Skip to content

Commit

Permalink
sstable: fix use of incorrect iterator in CopySpan()
Browse files Browse the repository at this point in the history
Previously we were using the wrong index iterator's Separator
when iterating over the entries of a two-level index sstable.
  • Loading branch information
itsbilal committed Oct 19, 2024
1 parent dff8179 commit f159870
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sstable/copier.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func intersectingIndexEntries(
if err != nil {
return nil, err
}
entry := indexEntry{bh: bh, sep: top.Separator()}
entry := indexEntry{bh: bh, sep: sub.Separator()}
alloc, entry.bh.Props = alloc.Copy(entry.bh.Props)
alloc, entry.sep = alloc.Copy(entry.sep)
res = append(res, entry)
Expand Down
24 changes: 20 additions & 4 deletions sstable/copier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package sstable
import (
"context"
"fmt"
"strconv"
"strings"
"testing"

Expand Down Expand Up @@ -35,6 +36,8 @@ func TestCopySpan(t *testing.T) {
return err.Error()
}
tableFormat := TableFormatMax
blockSize := 1
var indexBlockSize int
for i := range d.CmdArgs[1:] {
switch d.CmdArgs[i+1].Key {
case "format":
Expand All @@ -44,13 +47,26 @@ func TestCopySpan(t *testing.T) {
case "pebblev5":
tableFormat = TableFormatPebblev5
}
case "block_size":
var err error
blockSize, err = strconv.Atoi(d.CmdArgs[i+1].FirstVal(t))
if err != nil {
return err.Error()
}
case "index_block_size":
var err error
indexBlockSize, err = strconv.Atoi(d.CmdArgs[i+1].FirstVal(t))
if err != nil {
return err.Error()
}
}
}
w := NewWriter(objstorageprovider.NewFileWritable(f), WriterOptions{
BlockSize: 1,
TableFormat: tableFormat,
Comparer: testkeys.Comparer,
KeySchema: keySchema,
BlockSize: blockSize,
IndexBlockSize: indexBlockSize,
TableFormat: tableFormat,
Comparer: testkeys.Comparer,
KeySchema: keySchema,
})
for _, key := range strings.Split(d.Input, "\n") {
j := strings.Index(key, ":")
Expand Down
96 changes: 96 additions & 0 deletions sstable/testdata/copy_span
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,54 @@ a#0,SET: foo
b#0,SET: bar
c#0,SET: baz


# Try the above with small blocks.
build test22 format=pebblev4 block_size=1 index_block_size=1
a.SET.5:foo
b.SET.3:bar
c.SET.4:baz
d.SET.5:foobar
e.SET.5:foo
f.SET.5:foo
g.SET.5:foo
h.SET.5:foo
i.SET.5:foo
j.SET.5:foo
----

iter test22
----
a#0,SET: foo
b#0,SET: bar
c#0,SET: baz
d#0,SET: foobar
e#0,SET: foo
f#0,SET: foo
g#0,SET: foo
h#0,SET: foo
i#0,SET: foo
j#0,SET: foo

copy-span test22 test23 b.SET.10 cc.SET.0
----
copied 661 bytes

iter test23
----
b#0,SET: bar
c#0,SET: baz
d#0,SET: foobar

copy-span test22 test24 a.SET.10 bb.SET.0
----
copied 658 bytes

iter test24
----
a#0,SET: foo
b#0,SET: bar
c#0,SET: baz

# Try the above with columnar blocks.

build test3 format=pebblev5
Expand Down Expand Up @@ -70,3 +118,51 @@ iter test5
a#0,SET: foo
b#0,SET: bar
c#0,SET: baz


# Try the above with small blocks.
build test32 format=pebblev5 block_size=1 index_block_size=1
a.SET.5:foo
b.SET.3:bar
c.SET.4:baz
d.SET.5:foobar
e.SET.5:foo
f.SET.5:foo
g.SET.5:foo
h.SET.5:foo
i.SET.5:foo
j.SET.5:foo
----

iter test32
----
a#0,SET: foo
b#0,SET: bar
c#0,SET: baz
d#0,SET: foobar
e#0,SET: foo
f#0,SET: foo
g#0,SET: foo
h#0,SET: foo
i#0,SET: foo
j#0,SET: foo

copy-span test32 test33 b.SET.10 cc.SET.0
----
copied 889 bytes

iter test33
----
b#0,SET: bar
c#0,SET: baz
d#0,SET: foobar

copy-span test32 test34 a.SET.10 bb.SET.0
----
copied 897 bytes

iter test34
----
a#0,SET: foo
b#0,SET: bar
c#0,SET: baz

0 comments on commit f159870

Please sign in to comment.