From 79c9cbfc8d621d17b955e7b6cb7e6a1bf49edd73 Mon Sep 17 00:00:00 2001 From: Jackson Owens Date: Fri, 11 Oct 2024 13:09:52 -0400 Subject: [PATCH] db: use EncodeSpan in TestCheckLevelsCornerCases --- level_checker_test.go | 40 ++++++++++++++++++++++++---------------- testdata/level_checker | 34 +++++++++++++++++----------------- 2 files changed, 41 insertions(+), 33 deletions(-) diff --git a/level_checker_test.go b/level_checker_test.go index da26e4b935..03c97ee5b9 100644 --- a/level_checker_test.go +++ b/level_checker_test.go @@ -20,11 +20,11 @@ import ( "github.com/cockroachdb/pebble/internal/invariants" "github.com/cockroachdb/pebble/internal/keyspan" "github.com/cockroachdb/pebble/internal/manifest" - "github.com/cockroachdb/pebble/internal/rangedel" "github.com/cockroachdb/pebble/internal/sstableinternal" "github.com/cockroachdb/pebble/internal/testkeys" "github.com/cockroachdb/pebble/objstorage/objstorageprovider" "github.com/cockroachdb/pebble/sstable" + "github.com/cockroachdb/pebble/sstable/colblk" "github.com/cockroachdb/pebble/vfs" "github.com/stretchr/testify/require" ) @@ -177,8 +177,9 @@ func TestCheckLevelsCornerCases(t *testing.T) { } } writerOpts := sstable.WriterOptions{ - TableFormat: FormatNewest.MaxTableFormat(), Comparer: testkeys.Comparer, + KeySchema: colblk.DefaultKeySchema(testkeys.Comparer, 16), + TableFormat: FormatNewest.MaxTableFormat(), } writerOpts.SetInternal(sstableinternal.WriterOptions{ DisableKeyOrderChecks: disableKeyOrderChecks, @@ -192,22 +193,26 @@ func TestCheckLevelsCornerCases(t *testing.T) { tombstones = append(tombstones, fragmented) }, } - keyvalues := strings.Fields(line) - for _, kv := range keyvalues { - j := strings.Index(kv, ":") - ikey := base.ParseInternalKey(kv[:j]) - value := []byte(kv[j+1:]) - var err error - switch ikey.Kind() { - case InternalKeyKindRangeDelete: + keyValues := strings.Fields(line) + for _, kv := range keyValues { + if strings.HasPrefix(kv, "EncodeSpan:") { + kv = kv[len("EncodeSpan:"):] + s := keyspan.ParseSpan(kv) if writeUnfragmented { - err = w.AddWithForceObsolete(ikey, value, false /* forceObsolete */) - break + if err = w.EncodeSpan(s); err != nil { + return err.Error() + } + } else if s.Keys[0].Kind() == base.InternalKeyKindRangeDelete { + frag.Add(s) + } else { + t.Fatalf("unexpected span: %s", s.Pretty(testkeys.Comparer.FormatKey)) } - frag.Add(rangedel.Decode(ikey, value, nil)) - default: - err = w.AddWithForceObsolete(ikey, value, false /* forceObsolete */) + continue } + j := strings.Index(kv, ":") + ikey := base.ParseInternalKey(kv[:j]) + value := []byte(kv[j+1:]) + err = w.AddWithForceObsolete(ikey, value, false /* forceObsolete */) if err != nil { return err.Error() } @@ -230,7 +235,10 @@ func TestCheckLevelsCornerCases(t *testing.T) { return err.Error() } // Set FileNum for logging purposes. - readerOpts := sstable.ReaderOptions{Comparer: testkeys.Comparer} + readerOpts := sstable.ReaderOptions{ + Comparer: testkeys.Comparer, + KeySchema: writerOpts.KeySchema, + } readerOpts.SetInternalCacheOpts(sstableinternal.CacheOptions{FileNum: base.DiskFileNum(fileNum - 1)}) r, err := sstable.NewReader(context.Background(), readable, readerOpts) if err != nil { diff --git a/testdata/level_checker b/testdata/level_checker index f2c661ac57..45b3a8abf1 100644 --- a/testdata/level_checker +++ b/testdata/level_checker @@ -16,10 +16,10 @@ define L a.SET.30 e.RANGEDEL.inf -a.SET.30:30 c.SET.27:27 a.RANGEDEL.8:f +a.SET.30:30 c.SET.27:27 EncodeSpan:a-f:{(#8,RANGEDEL)} L e.SET.10 g.SET.20 -e.SET.10:10 g.SET.20:20 e.RANGEDEL.8:f +e.SET.10:10 g.SET.20:20 EncodeSpan:e-f:{(#8,RANGEDEL)} ---- Level 1 file 0: [a#30,SET-e#inf,RANGEDEL] @@ -34,7 +34,7 @@ check define L a.SET.15 f.SET.16 -a.SET.15:15 c.SET.13:13 f.SET.16:16 a.RANGEDEL.12:h +a.SET.15:15 c.SET.13:13 f.SET.16:16 EncodeSpan:a-h:{(#12,RANGEDEL)} L e.SET.10 g.SET.15 e.SET.10:10 g.SET.15:15 @@ -52,10 +52,10 @@ check define L c.SET.30 f.RANGEDEL.0 -c.SET.30:30 d.SET.27:27 a.RANGEDEL.8:f +c.SET.30:30 d.SET.27:27 EncodeSpan:a-f:{(#8,RANGEDEL)} L a.SET.10 c.RANGEDEL.inf -a.SET.10:10 b.SET.12:12 a.RANGEDEL.8:f +a.SET.10:10 b.SET.12:12 EncodeSpan:a-f:{(#8,RANGEDEL)} ---- Level 1 file 0: [c#30,SET-f#0,RANGEDEL] @@ -70,7 +70,7 @@ check define L c.SET.15 g.SET.16 -c.SET.15:15 f.SET.13:13 g.SET.16:16 a.RANGEDEL.12:h +c.SET.15:15 f.SET.13:13 g.SET.16:16 EncodeSpan:a-h:{(#12,RANGEDEL)} L b.SET.14 d.SET.10 b.SET.14:14 d.SET.10:10 @@ -87,10 +87,10 @@ check define L a.SET.30 e.RANGEDEL.inf -a.SET.30:30 c.SET.27:27 a.RANGEDEL.8:g +a.SET.30:30 c.SET.27:27 EncodeSpan:a-g:{(#8,RANGEDEL)} L e.SET.10 g.SET.20 -e.SET.10:10 g.SET.20:20 e.RANGEDEL.8:g +e.SET.10:10 g.SET.20:20 EncodeSpan:e-g:{(#8,RANGEDEL)} ---- Level 1 file 0: [a#30,SET-e#inf,RANGEDEL] @@ -103,7 +103,7 @@ check define L a.SET.30 e.RANGEDEL.inf -a.SET.30:30 c.SET.27:27 a.RANGEDEL.8:g +a.SET.30:30 c.SET.27:27 EncodeSpan:a-g:{(#8,RANGEDEL)} L a.SET.10 g.SET.20 a.SET.10:10 c.SET.28:28 g.SET.20:20 @@ -122,7 +122,7 @@ found InternalKey c#27,SET in L1: fileNum=000010 and InternalKey c#28,SET in L2: define L a.SET.30 g.RANGEDEL.inf -a.SET.30:30 c.SET.27:27 a.RANGEDEL.8:g +a.SET.30:30 c.SET.27:27 EncodeSpan:a-g:{(#8,RANGEDEL)} L g.SET.10 j.SET.20 g.SET.10:10 j.SET.20:20 @@ -138,7 +138,7 @@ check define L a.SET.30 g.SET.8 -a.SET.30:30 c.SET.27:27 a.RANGEDEL.8:g g.SET.8:8 +a.SET.30:30 c.SET.27:27 EncodeSpan:a-g:{(#8,RANGEDEL)} g.SET.8:8 L g.SET.10 j.SET.20 g.SET.10:10 j.SET.20:20 @@ -158,7 +158,7 @@ a.SET.30 g.SET.30 a.SET.30:30 c.SET.8:8 g.SET.30:30 L a.SET.10 j.SET.20 -a.SET.10:10 j.SET.20:20 b.RANGEDEL.10:g +a.SET.10:10 j.SET.20:20 EncodeSpan:b-g:{(#10,RANGEDEL)} ---- Level 1 file 0: [a#30,SET-g#30,SET] @@ -172,10 +172,10 @@ tombstone b-g:{(#10,RANGEDEL)} in L2: fileNum=000017 deletes key c#8,SET in L1: define L a.RANGEDEL.8 c.RANGEDEL.inf -a.RANGEDEL.8:c +EncodeSpan:a-c:{(#8,RANGEDEL)} L a.RANGEDEL.6 d.RANGEDEL.inf -a.RANGEDEL.6:d b.RANGEDEL.10:c +EncodeSpan:a-d:{(#6,RANGEDEL)} EncodeSpan:b-c:{(#10,RANGEDEL)} ---- Level 1 file 0: [a#8,RANGEDEL-c#inf,RANGEDEL] @@ -227,7 +227,7 @@ out of order keys b#2,SET >= b#3,SET in L1: fileNum=000023 define write-unfragmented disable-key-order-checks L a.RANGEDEL.1 g.RANGEDEL.inf -d.RANGEDEL.2:e d.RANGEDEL.1:e f.RANGEDEL.3:g a.RANGEDEL.4:b +EncodeSpan:d-e:{(#2,RANGEDEL)} EncodeSpan:d-e:{(#1,RANGEDEL)} EncodeSpan:f-g:{(#3,RANGEDEL)} EncodeSpan:a-b:{(#4,RANGEDEL)} ---- Level 1 file 0: [a#1,RANGEDEL-g#inf,RANGEDEL] @@ -240,7 +240,7 @@ unordered or unfragmented range delete tombstones f-g:{(#3,RANGEDEL)}, a-b:{(#4, define write-unfragmented disable-key-order-checks L a.RANGEDEL.1 d.RANGEDEL.inf -a.RANGEDEL.1:d b.RANGEDEL.2:c +EncodeSpan:a-d:{(#1,RANGEDEL)} EncodeSpan:b-c:{(#2,RANGEDEL)} ---- Level 1 file 0: [a#1,RANGEDEL-d#inf,RANGEDEL] @@ -364,7 +364,7 @@ merge processing error on key a#9,SINGLEDEL in L1: fileNum=000033: finish failed define L a@9.SET.9 f.RANGEDEL.inf -a@9.SET.9:a9 a@6.SET.6:a6 a.RANGEDEL.5:f +a@9.SET.9:a9 a@6.SET.6:a6 EncodeSpan:a-f:{(#5,RANGEDEL)} f@6.SET.6 f@6.SET.6 f@6.SET.6:f6 ----