diff --git a/internal/base/internal.go b/internal/base/internal.go index e364508ba0..baf47a6395 100644 --- a/internal/base/internal.go +++ b/internal/base/internal.go @@ -292,23 +292,6 @@ var kindsMap = map[string]InternalKeyKind{ "DELSIZED": InternalKeyKindDeleteSized, } -// ParseInternalKey parses the string representation of an internal key. The -// format is ... If the seq-num starts with a "b" it -// is marked as a batch-seq-num (i.e. the SeqNumBatchBit bit is set). -func ParseInternalKey(s string) InternalKey { - x := strings.Split(s, ".") - if len(x) != 3 { - panic(fmt.Sprintf("invalid internal key %q", s)) - } - ukey := x[0] - kind, ok := kindsMap[x[1]] - if !ok { - panic(fmt.Sprintf("unknown kind: %q", x[1])) - } - seqNum := ParseSeqNum(x[2]) - return MakeInternalKey([]byte(ukey), seqNum, kind) -} - // ParseSeqNum parses the string representation of a sequence number. // "inf" is supported as the maximum sequence number (mainly used for exclusive // end keys). @@ -541,11 +524,32 @@ func (k prettyInternalKey) Format(s fmt.State, c rune) { fmt.Fprintf(s, "%s#%s,%s", k.formatKey(k.UserKey), k.SeqNum(), k.Kind()) } -// ParsePrettyInternalKey parses the pretty string representation of an -// internal key. The format is #,. -// TODO(radu): do we need both ParseInternalKey and ParsePrettyInternalKey? -func ParsePrettyInternalKey(s string) InternalKey { +// ParseInternalKey parses the string representation of an internal key. The +// format is #,. The older format +// .. is also supported (for now). +// +// If the seq-num starts with a "b" it is marked as a batch-seq-num (i.e. the +// SeqNumBatchBit bit is set). +func ParseInternalKey(s string) InternalKey { + if !strings.Contains(s, "#") { + // Parse the old format: .. + // TODO(radu): get rid of this. + x := strings.Split(s, ".") + if len(x) != 3 { + panic(fmt.Sprintf("invalid internal key %q", s)) + } + ukey := x[0] + kind, ok := kindsMap[x[1]] + if !ok { + panic(fmt.Sprintf("unknown kind: %q", x[1])) + } + seqNum := ParseSeqNum(x[2]) + return MakeInternalKey([]byte(ukey), seqNum, kind) + } x := strings.FieldsFunc(s, func(c rune) bool { return c == '#' || c == ',' }) + if len(x) != 3 { + panic(fmt.Sprintf("invalid key internal %q", s)) + } userKey := []byte(x[0]) seqNum := ParseSeqNum(x[1]) kind, ok := kindsMap[x[2]] @@ -565,7 +569,7 @@ func ParseInternalKeyRange(s string) (start, end InternalKey) { if !ok1 || !ok2 || len(x) != 2 { panic(fmt.Sprintf("invalid key range %q", s)) } - return ParsePrettyInternalKey(x[0]), ParsePrettyInternalKey(x[1]) + return ParseInternalKey(x[0]), ParseInternalKey(x[1]) } // MakeInternalKV constructs an InternalKV with the provided internal key and diff --git a/internal/manifest/testutils.go b/internal/manifest/testutils.go index 6a608d7ddf..c2c3be32c0 100644 --- a/internal/manifest/testutils.go +++ b/internal/manifest/testutils.go @@ -150,7 +150,7 @@ func (p *debugParser) DiskFileNum() base.DiskFileNum { // InternalKey parses the next token as an internal key. func (p *debugParser) InternalKey() base.InternalKey { - return base.ParsePrettyInternalKey(p.Next()) + return base.ParseInternalKey(p.Next()) } // Errf panics with an error which includes the original string and the last diff --git a/sstable/colblk/data_block_test.go b/sstable/colblk/data_block_test.go index 38eefb54d9..112dfb6916 100644 --- a/sstable/colblk/data_block_test.go +++ b/sstable/colblk/data_block_test.go @@ -46,7 +46,7 @@ func TestDataBlock(t *testing.T) { case "write": for _, line := range strings.Split(td.Input, "\n") { j := strings.IndexRune(line, ':') - ik := base.ParsePrettyInternalKey(line[:j]) + ik := base.ParseInternalKey(line[:j]) kcmp := w.KeyWriter.ComparePrev(ik.UserKey) valueString := line[j+1:]