Skip to content

Commit b494d9b

Browse files
committed
sstable: only support MinLZ for v6+ tables
We fall back to Snappy for older formats. Fixes #4633
1 parent 7ce22d1 commit b494d9b

File tree

8 files changed

+80
-6
lines changed

8 files changed

+80
-6
lines changed

options.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ const (
4949
NoCompression = block.NoCompression
5050
SnappyCompression = block.SnappyCompression
5151
ZstdCompression = block.ZstdCompression
52-
MinLZCompression = block.MinLZCompression
52+
// MinLZCompression is only supported with table formats v6+. Older formats
53+
// fall back to snappy.
54+
MinLZCompression = block.MinLZCompression
5355
)
5456

5557
// FilterType exports the base.FilterType type.

sstable/block/compression.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const (
2525
NoCompression
2626
SnappyCompression
2727
ZstdCompression
28+
// MinLZCompression is only supported with table formats v6+. Older formats
29+
// fall back to snappy.
2830
MinLZCompression
2931
NCompression
3032
)

sstable/format.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const (
2929
TableFormatPebblev3 // Value blocks.
3030
TableFormatPebblev4 // DELSIZED tombstones.
3131
TableFormatPebblev5 // Columnar blocks.
32-
TableFormatPebblev6 // Checksum footer + blob value handles + columnar metaindex/properties.
32+
TableFormatPebblev6 // Checksum footer + blob value handles + columnar metaindex/properties + MinLZ compression support.
3333
NumTableFormats
3434

3535
TableFormatMax = NumTableFormats - 1

sstable/options.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,6 @@ func (o WriterOptions) ensureDefaults() WriterOptions {
330330
if o.Comparer == nil {
331331
o.Comparer = base.DefaultComparer
332332
}
333-
if o.Compression <= block.DefaultCompression || o.Compression >= block.NCompression {
334-
o.Compression = block.SnappyCompression
335-
}
336333
if o.IndexBlockSize <= 0 {
337334
o.IndexBlockSize = o.BlockSize
338335
}
@@ -357,5 +354,9 @@ func (o WriterOptions) ensureDefaults() WriterOptions {
357354
s := colblk.DefaultKeySchema(o.Comparer, 16 /* bundle size */)
358355
o.KeySchema = &s
359356
}
357+
if o.Compression <= block.DefaultCompression || o.Compression >= block.NCompression ||
358+
(o.Compression == block.MinLZCompression && o.TableFormat < TableFormatPebblev6) {
359+
o.Compression = block.SnappyCompression
360+
}
360361
return o
361362
}

sstable/test_utils.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/cockroachdb/pebble/internal/testkeys"
2222
"github.com/cockroachdb/pebble/objstorage"
2323
"github.com/cockroachdb/pebble/sstable/blob"
24+
"github.com/cockroachdb/pebble/sstable/block"
2425
)
2526

2627
// ReadAll returns all point keys, range del spans, and range key spans from an
@@ -274,6 +275,16 @@ func ParseWriterOptions[StringOrStringer any](o *WriterOptions, args ...StringOr
274275
case "format", "leveldb":
275276
return errors.Errorf("%q is deprecated", key)
276277

278+
case "compression":
279+
o.Compression, err = func() (block.Compression, error) {
280+
for c := block.DefaultCompression; c < block.NCompression; c++ {
281+
if strings.EqualFold(c.String(), value) {
282+
return c, nil
283+
}
284+
}
285+
return 0, errors.Errorf("unknown compression %q", value)
286+
}()
287+
277288
default:
278289
// TODO(radu): ignoring unknown keys is error-prone; we need to find an
279290
// easy way for the upper layer to extract its own arguments.

sstable/testdata/writer_v5

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,24 @@ close
342342
----
343343
point: [a@2#1,SET-b@2#1,SET]
344344
seqnums: [1-1]
345+
346+
build compression=zstd
347+
a.SET.1:thequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydog
348+
----
349+
point: [a#1,SET-a#1,SET]
350+
seqnums: [1-1]
351+
352+
props rocksdb.compression
353+
----
354+
rocksdb.compression: ZSTD
355+
356+
# MinLZ is not supported in v5; we should fall back to Snappy.
357+
build compression=minlz
358+
a.SET.1:thequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydog
359+
----
360+
point: [a#1,SET-a#1,SET]
361+
seqnums: [1-1]
362+
363+
props rocksdb.compression
364+
----
365+
rocksdb.compression: Snappy

sstable/testdata/writer_v6

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,24 @@ close
365365
----
366366
point: [a@2#1,SET-b@2#1,SET]
367367
seqnums: [1-1]
368+
369+
build compression=zstd
370+
a.SET.1:thequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydog
371+
----
372+
point: [a#1,SET-a#1,SET]
373+
seqnums: [1-1]
374+
375+
props rocksdb.compression
376+
----
377+
rocksdb.compression: ZSTD
378+
379+
# MinLZ is supported in v6.
380+
build compression=minlz
381+
a.SET.1:thequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydogthequickbrownfoxjumpsoverthelazydog
382+
----
383+
point: [a#1,SET-a#1,SET]
384+
seqnums: [1-1]
385+
386+
props rocksdb.compression
387+
----
388+
rocksdb.compression: MinLZ

sstable/writer_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"testing"
1818
"unsafe"
1919

20+
"github.com/cockroachdb/crlib/crstrings"
2021
"github.com/cockroachdb/crlib/testutils/leaktest"
2122
"github.com/cockroachdb/datadriven"
2223
"github.com/cockroachdb/errors"
@@ -306,7 +307,22 @@ func runDataDriven(t *testing.T, file string, tableFormat TableFormat) {
306307
return formatWriterMetadata(td, meta)
307308

308309
case "props":
309-
return r.Properties.String()
310+
var buf strings.Builder
311+
for _, p := range crstrings.Lines(r.Properties.String()) {
312+
if len(td.CmdArgs) > 0 {
313+
ok := false
314+
for i := range td.CmdArgs {
315+
if strings.HasPrefix(p, td.CmdArgs[i].String()+":") {
316+
ok = true
317+
}
318+
}
319+
if !ok {
320+
continue
321+
}
322+
}
323+
fmt.Fprintf(&buf, "%s\n", p)
324+
}
325+
return buf.String()
310326

311327
default:
312328
return fmt.Sprintf("unknown command: %s", td.Cmd)

0 commit comments

Comments
 (0)