Skip to content

Commit

Permalink
sstable: bump TableFormatMax to TableFormatPebblev5
Browse files Browse the repository at this point in the history
Fix a few remaining tests to work with TableFormatPebblev5 and bump the
TableFormatMax constant to point at TableFormatPebblev5.
  • Loading branch information
jbowens committed Oct 7, 2024
1 parent 997b6bc commit a29c275
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 20 deletions.
14 changes: 12 additions & 2 deletions internal/compact/spans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (
"github.com/cockroachdb/datadriven"
"github.com/cockroachdb/pebble/internal/base"
"github.com/cockroachdb/pebble/internal/keyspan"
"github.com/cockroachdb/pebble/internal/testkeys"
"github.com/cockroachdb/pebble/objstorage"
"github.com/cockroachdb/pebble/sstable"
"github.com/cockroachdb/pebble/sstable/colblk"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -121,10 +123,18 @@ func TestSplitAndEncodeSpan(t *testing.T) {
}

obj := &objstorage.MemObj{}
tw := sstable.NewRawWriter(obj, sstable.WriterOptions{TableFormat: sstable.TableFormatMax})
wo := sstable.WriterOptions{
Comparer: testkeys.Comparer,
KeySchema: colblk.DefaultKeySchema(testkeys.Comparer, 16),
TableFormat: sstable.TableFormatMax,
}
tw := sstable.NewRawWriter(obj, wo)
require.NoError(t, SplitAndEncodeSpan(base.DefaultComparer.Compare, &span, upToKey, tw))
require.NoError(t, tw.Close())
_, rangeDels, rangeKeys := sstable.ReadAll(obj)
_, rangeDels, rangeKeys := sstable.ReadAll(obj, sstable.ReaderOptions{
Comparer: wo.Comparer,
KeySchema: wo.KeySchema,
})
require.LessOrEqual(t, len(rangeDels)+len(rangeKeys), 1)
s := "."
if all := append(rangeDels, rangeKeys...); len(all) == 1 {
Expand Down
4 changes: 1 addition & 3 deletions sstable/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ const (
TableFormatPebblev5 // Columnar blocks.
NumTableFormats

// TODO(jackson): Update TableFormatMax to `NumTableFormats-1` once
// TableFormatPebblev5 is stable.
TableFormatMax = TableFormatPebblev4
TableFormatMax = NumTableFormats - 1

// TableFormatMinSupported is the minimum format supported by Pebble. This
// package still supports older formats for uses outside of Pebble
Expand Down
12 changes: 10 additions & 2 deletions sstable/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/cockroachdb/pebble/objstorage"
"github.com/cockroachdb/pebble/objstorage/objstorageprovider"
"github.com/cockroachdb/pebble/sstable/block"
"github.com/cockroachdb/pebble/sstable/colblk"
"github.com/cockroachdb/pebble/vfs"
"github.com/cockroachdb/pebble/vfs/errorfs"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -1674,14 +1675,21 @@ func TestReader_TableFormat(t *testing.T) {
f, err := fs.Create("test", vfs.WriteCategoryUnspecified)
require.NoError(t, err)

opts := WriterOptions{TableFormat: want}
opts := WriterOptions{
Comparer: testkeys.Comparer,
KeySchema: colblk.DefaultKeySchema(testkeys.Comparer, 16),
TableFormat: want,
}
w := NewRawWriter(objstorageprovider.NewFileWritable(f), opts)
err = w.Close()
require.NoError(t, err)

f, err = fs.Open("test")
require.NoError(t, err)
r, err := newReader(f, ReaderOptions{})
r, err := newReader(f, ReaderOptions{
Comparer: opts.Comparer,
KeySchema: opts.KeySchema,
})
require.NoError(t, err)
defer r.Close()

Expand Down
4 changes: 2 additions & 2 deletions sstable/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
// ReadAll returns all point keys, range del spans, and range key spans from an
// sstable. Closes the Readable. Panics on errors.
func ReadAll(
r objstorage.Readable,
r objstorage.Readable, ro ReaderOptions,
) (points []base.InternalKV, rangeDels, rangeKeys []keyspan.Span) {
reader := testutils.CheckErr(NewReader(context.Background(), r, ReaderOptions{}))
reader := testutils.CheckErr(NewReader(context.Background(), r, ro))
defer reader.Close()
pointIter := testutils.CheckErr(reader.NewIter(NoTransforms, nil /* lower */, nil /* upper */))
defer pointIter.Close()
Expand Down
4 changes: 2 additions & 2 deletions sstable/testdata/reader/iter
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ bbx.SET.2:X
bby.SET.2:Y
bbz.SET.2:Z
c.SET.3:C
cc.RANGEDEL.3:ccc
EncodeSpan: cc-ccc:{(#3,RANGEDEL)}
cce.SET.3:E
ccf.SET.3:F
ccg.SET.3:G
Expand All @@ -384,7 +384,7 @@ ccx.SET.3:X
ccy.SET.3:Y
ccz.SET.3:Z
d.SET.4:D
dd.RANGEDEL.4:ddd
EncodeSpan: dd-ddd:{(#4,RANGEDEL)}
dde.SET.4:E
ddf.SET.4:F
ddg.SET.4:G
Expand Down
12 changes: 6 additions & 6 deletions sstable/testdata/virtual_reader_iter
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ build block-size=1 index-block-size=1
a.SET.1:a
d.SET.2:d
f.SET.3:f
d.RANGEDEL.4:e
EncodeSpan: d-e:{(#4,RANGEDEL)}
EncodeSpan: a-d:{(#11,RANGEKEYSET,@10,foo)}
g.RANGEDEL.5:l
EncodeSpan: g-l:{(#5,RANGEDEL)}
EncodeSpan: y-z:{(#12,RANGEKEYSET,@11,foo)}
----
point: [a#1,SET-f#3,SET]
Expand Down Expand Up @@ -493,7 +493,7 @@ build
a.SET.1:a
d.SET.2:d
e.SET.3:e
d.RANGEDEL.4:e
EncodeSpan: d-e:{(#4,RANGEDEL)}
f.SET.5:f
----
point: [a#1,SET-f#5,SET]
Expand Down Expand Up @@ -530,7 +530,7 @@ build block-size=1 index-block-size=1
a.SET.1:a
d.SET.2:d
e.SET.3:e
d.RANGEDEL.4:e
EncodeSpan: d-e:{(#4,RANGEDEL)}
f.SET.5:f
----
point: [a#1,SET-f#5,SET]
Expand Down Expand Up @@ -568,9 +568,9 @@ a.SET.1:a
b.SET.5:b
d.SET.2:d
f.SET.3:f
d.RANGEDEL.4:e
EncodeSpan: d-e:{(#4,RANGEDEL)}
EncodeSpan: a-d:{(#11,RANGEKEYSET,@10,foo)}
g.RANGEDEL.5:l
EncodeSpan: g-l:{(#5,RANGEDEL)}
EncodeSpan: y-z:{(#12,RANGEKEYSET,@11,foo)}
----
point: [a#1,SET-f#3,SET]
Expand Down
11 changes: 8 additions & 3 deletions table_stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"testing"

"github.com/cockroachdb/datadriven"
"github.com/cockroachdb/pebble/internal/base"
"github.com/cockroachdb/pebble/internal/keyspan"
"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 @@ -192,7 +192,7 @@ func TestTableStats(t *testing.T) {

func TestTableRangeDeletionIter(t *testing.T) {
var m *fileMetadata
cmp := base.DefaultComparer
cmp := testkeys.Comparer
fs := vfs.NewMem()
datadriven.RunTest(t, "testdata/table_stats_deletion_iter", func(t *testing.T, td *datadriven.TestData) string {
switch cmd := td.Cmd; cmd {
Expand All @@ -202,6 +202,8 @@ func TestTableRangeDeletionIter(t *testing.T) {
return err.Error()
}
w := sstable.NewRawWriter(objstorageprovider.NewFileWritable(f), sstable.WriterOptions{
Comparer: cmp,
KeySchema: colblk.DefaultKeySchema(cmp, 16),
TableFormat: sstable.TableFormatMax,
})
m = &fileMetadata{}
Expand Down Expand Up @@ -238,7 +240,10 @@ func TestTableRangeDeletionIter(t *testing.T) {
if err != nil {
return err.Error()
}
r, err = sstable.NewReader(context.Background(), readable, sstable.ReaderOptions{})
r, err = sstable.NewReader(context.Background(), readable, sstable.ReaderOptions{
Comparer: cmp,
KeySchema: colblk.DefaultKeySchema(cmp, 16),
})
if err != nil {
return err.Error()
}
Expand Down

0 comments on commit a29c275

Please sign in to comment.