Skip to content

Commit

Permalink
db: use EncodeSpan in TestCheckLevelsCornerCases
Browse files Browse the repository at this point in the history
  • Loading branch information
jbowens committed Oct 11, 2024
1 parent 4b62ea0 commit 79c9cbf
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
40 changes: 24 additions & 16 deletions level_checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
Expand All @@ -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()
}
Expand All @@ -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 {
Expand Down
34 changes: 17 additions & 17 deletions testdata/level_checker
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down Expand Up @@ -364,7 +364,7 @@ merge processing error on key a#9,SINGLEDEL in L1: fileNum=000033: finish failed
define
L
[email protected] f.RANGEDEL.inf
[email protected]:a9 [email protected]:a6 a.RANGEDEL.5:f
[email protected]:a9 [email protected]:a6 EncodeSpan:a-f:{(#5,RANGEDEL)}
[email protected] [email protected]
[email protected]:f6
----
Expand Down

0 comments on commit 79c9cbf

Please sign in to comment.