Skip to content

Commit 3e4eb3e

Browse files
committed
db: add configurable LatencyTolerantSpanPolicy option
We will add a configurable option, `LatencyTolerantSpanPolicy`, that specifies the minimum value size required for latency tolerant spans and likely MVCC garbage to be separated into a blob file. Fixes: #5377
1 parent 3795809 commit 3e4eb3e

File tree

17 files changed

+140
-44
lines changed

17 files changed

+140
-44
lines changed

checkpoint_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/cockroachdb/datadriven"
2020
"github.com/cockroachdb/pebble/internal/base"
21+
"github.com/cockroachdb/pebble/internal/compact"
2122
"github.com/cockroachdb/pebble/internal/testutils"
2223
"github.com/cockroachdb/pebble/objstorage/remote"
2324
"github.com/cockroachdb/pebble/sstable"
@@ -52,6 +53,11 @@ func testCheckpointImpl(t *testing.T, ddFile string, createOnShared bool) {
5253
if createOnShared {
5354
opts.Experimental.CreateOnShared = remote.CreateOnSharedAll
5455
}
56+
opts.Experimental.LatencyTolerantSpanPolicy = func() compact.ValueSeparationOutputConfig {
57+
return compact.ValueSeparationOutputConfig{
58+
MinimumSize: 10,
59+
}
60+
}
5561
opts.DisableTableStats = true
5662
opts.private.testingAlwaysWaitForCleanup = true
5763
return opts

compaction.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,9 +3477,7 @@ func (d *DB) compactAndWrite(
34773477
case ValueStorageLatencyTolerant:
34783478
// This span of keyspace is more tolerant of latency, so set a more
34793479
// aggressive value separation policy for this output.
3480-
vSep.SetNextOutputConfig(compact.ValueSeparationOutputConfig{
3481-
MinimumSize: latencyTolerantMinimumSize,
3482-
})
3480+
vSep.SetNextOutputConfig(d.opts.Experimental.LatencyTolerantSpanPolicy())
34833481
}
34843482
objMeta, tw, err := d.newCompactionOutputTable(jobID, c, writerOpts)
34853483
if err != nil {

compaction_picker_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/cockroachdb/datadriven"
2424
"github.com/cockroachdb/errors"
2525
"github.com/cockroachdb/pebble/internal/base"
26+
"github.com/cockroachdb/pebble/internal/compact"
2627
"github.com/cockroachdb/pebble/internal/humanize"
2728
"github.com/cockroachdb/pebble/internal/manifest"
2829
"github.com/cockroachdb/pebble/internal/problemspans"
@@ -1513,6 +1514,11 @@ func TestCompactionPickerScores(t *testing.T) {
15131514
opts.Experimental.CompactionScheduler = func() CompactionScheduler {
15141515
return NewConcurrencyLimitSchedulerWithNoPeriodicGrantingForTest()
15151516
}
1517+
opts.Experimental.LatencyTolerantSpanPolicy = func() compact.ValueSeparationOutputConfig {
1518+
return compact.ValueSeparationOutputConfig{
1519+
MinimumSize: 10,
1520+
}
1521+
}
15161522
var err error
15171523
d, err = runDBDefineCmd(td, opts)
15181524
if err != nil {

compaction_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,11 @@ func runCompactionTest(
949949
opts.Experimental.CompactionScheduler = func() CompactionScheduler {
950950
return NewConcurrencyLimitSchedulerWithNoPeriodicGrantingForTest()
951951
}
952+
opts.Experimental.LatencyTolerantSpanPolicy = func() compact.ValueSeparationOutputConfig {
953+
return compact.ValueSeparationOutputConfig{
954+
MinimumSize: 10,
955+
}
956+
}
952957
return opts
953958
}
954959
reset := func() {
@@ -2474,6 +2479,11 @@ func TestCompactionErrorCleanup(t *testing.T) {
24742479
},
24752480
Logger: testutils.Logger{T: t},
24762481
}
2482+
opts.Experimental.LatencyTolerantSpanPolicy = func() compact.ValueSeparationOutputConfig {
2483+
return compact.ValueSeparationOutputConfig{
2484+
MinimumSize: 10,
2485+
}
2486+
}
24772487
opts.WithFSDefaults()
24782488
for i := range opts.TargetFileSizes {
24792489
opts.TargetFileSizes[i] = 1
@@ -2722,6 +2732,11 @@ func TestCompactFlushQueuedLargeBatch(t *testing.T) {
27222732
FS: mem,
27232733
Logger: testutils.Logger{T: t},
27242734
}
2735+
opts.Experimental.LatencyTolerantSpanPolicy = func() compact.ValueSeparationOutputConfig {
2736+
return compact.ValueSeparationOutputConfig{
2737+
MinimumSize: 10,
2738+
}
2739+
}
27252740
opts.WithFSDefaults()
27262741
d, err := Open("", testingRandomized(t, opts))
27272742
require.NoError(t, err)

db_test.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/cockroachdb/pebble/internal/base"
2828
"github.com/cockroachdb/pebble/internal/buildtags"
2929
"github.com/cockroachdb/pebble/internal/cache"
30+
"github.com/cockroachdb/pebble/internal/compact"
3031
"github.com/cockroachdb/pebble/internal/testkeys"
3132
"github.com/cockroachdb/pebble/internal/testutils"
3233
"github.com/cockroachdb/pebble/objstorage/objstorageprovider"
@@ -306,10 +307,16 @@ func TestBasicWrites(t *testing.T) {
306307
}
307308

308309
func TestRandomWrites(t *testing.T) {
309-
d, err := Open("", testingRandomized(t, &Options{
310+
opts := &Options{
310311
FS: vfs.NewMem(),
311312
MemTableSize: 8 * 1024,
312-
}))
313+
}
314+
opts.Experimental.LatencyTolerantSpanPolicy = func() compact.ValueSeparationOutputConfig {
315+
return compact.ValueSeparationOutputConfig{
316+
MinimumSize: 10,
317+
}
318+
}
319+
d, err := Open("", testingRandomized(t, opts))
313320
require.NoError(t, err)
314321

315322
keys := [64][]byte{}
@@ -697,10 +704,16 @@ func TestIterLeak(t *testing.T) {
697704
for _, flush := range []bool{true, false} {
698705
t.Run(fmt.Sprintf("flush=%t", flush), func(t *testing.T) {
699706
fc := NewFileCache(10, 100)
700-
d, err := Open("", testingRandomized(t, &Options{
707+
opts := &Options{
701708
FS: vfs.NewMem(),
702709
FileCache: fc,
703-
}))
710+
}
711+
opts.Experimental.LatencyTolerantSpanPolicy = func() compact.ValueSeparationOutputConfig {
712+
return compact.ValueSeparationOutputConfig{
713+
MinimumSize: 10,
714+
}
715+
}
716+
d, err := Open("", testingRandomized(t, opts))
704717
require.NoError(t, err)
705718

706719
require.NoError(t, d.Set([]byte("a"), []byte("a"), nil))
@@ -1194,6 +1207,11 @@ func TestDBConcurrentCompactClose(t *testing.T) {
11941207
return 1, 2
11951208
},
11961209
}
1210+
opts.Experimental.LatencyTolerantSpanPolicy = func() compact.ValueSeparationOutputConfig {
1211+
return compact.ValueSeparationOutputConfig{
1212+
MinimumSize: 10,
1213+
}
1214+
}
11971215
d, err := Open("", testingRandomized(t, opts))
11981216
require.NoError(t, err)
11991217

@@ -1265,7 +1283,13 @@ func TestDBApplyBatchMismatch(t *testing.T) {
12651283
func TestCloseCleanerRace(t *testing.T) {
12661284
mem := vfs.NewMem()
12671285
for i := 0; i < 20; i++ {
1268-
db, err := Open("", testingRandomized(t, &Options{FS: mem}))
1286+
opts := &Options{FS: mem}
1287+
opts.Experimental.LatencyTolerantSpanPolicy = func() compact.ValueSeparationOutputConfig {
1288+
return compact.ValueSeparationOutputConfig{
1289+
MinimumSize: 10,
1290+
}
1291+
}
1292+
db, err := Open("", testingRandomized(t, opts))
12691293
require.NoError(t, err)
12701294
require.NoError(t, db.Set([]byte("a"), []byte("something"), Sync))
12711295
require.NoError(t, db.Flush())

event_listener_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/cockroachdb/datadriven"
2222
"github.com/cockroachdb/errors"
2323
"github.com/cockroachdb/pebble/internal/base"
24+
"github.com/cockroachdb/pebble/internal/compact"
2425
"github.com/cockroachdb/pebble/internal/testutils"
2526
"github.com/cockroachdb/pebble/objstorage/objstorageprovider"
2627
"github.com/cockroachdb/pebble/sstable"
@@ -638,6 +639,11 @@ func TestBlobCorruptionEvent(t *testing.T) {
638639
MaxBlobReferenceDepth: 10,
639640
}
640641
}
642+
opts.Experimental.LatencyTolerantSpanPolicy = func() compact.ValueSeparationOutputConfig {
643+
return compact.ValueSeparationOutputConfig{
644+
MinimumSize: 10,
645+
}
646+
}
641647
d, err := Open("", opts)
642648
require.NoError(t, err)
643649

internal/compact/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ func (r *Runner) writeKeysToTable(
344344
}
345345

346346
valueLen := kv.V.Len()
347-
isLikelyMVCCGarbage := sstable.IsLikelyMVCCGarbage(kv.K.UserKey, prevKeyKind, kv.K.Kind(), valueLen, prefixEqual)
347+
isLikelyMVCCGarbage := sstable.IsLikelyMVCCGarbage(kv.K.UserKey, prevKeyKind, kv.K.Kind(),
348+
valueLen, prefixEqual)
348349
// Add the value to the sstable, possibly separating its value into a
349350
// blob file. The ValueSeparation implementation is responsible for
350351
// writing the KV to the sstable.

metamorphic/options.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/cockroachdb/pebble"
2323
"github.com/cockroachdb/pebble/bloom"
2424
"github.com/cockroachdb/pebble/internal/base"
25+
"github.com/cockroachdb/pebble/internal/compact"
2526
"github.com/cockroachdb/pebble/objstorage/remote"
2627
"github.com/cockroachdb/pebble/sstable"
2728
"github.com/cockroachdb/pebble/sstable/block"
@@ -347,6 +348,11 @@ func defaultOptions(kf KeyFormat) *pebble.Options {
347348
GarbageRatioHighPriority: 0.30, // 30% garbage
348349
}
349350
}
351+
opts.Experimental.LatencyTolerantSpanPolicy = func() compact.ValueSeparationOutputConfig {
352+
return compact.ValueSeparationOutputConfig{
353+
MinimumSize: 10,
354+
}
355+
}
350356

351357
// The level checker runs every time a new read state is installed: every
352358
// compaction, flush, ingest completion, etc. It runs while the database
@@ -932,6 +938,11 @@ func RandomOptions(rng *rand.Rand, kf KeyFormat, cfg RandomOptionsCfg) *TestOpti
932938
opts.Experimental.ValueSeparationPolicy = func() pebble.ValueSeparationPolicy {
933939
return policy
934940
}
941+
opts.Experimental.LatencyTolerantSpanPolicy = func() compact.ValueSeparationOutputConfig {
942+
return compact.ValueSeparationOutputConfig{
943+
MinimumSize: 1 + rng.IntN(14),
944+
}
945+
}
935946
}
936947

937948
if rand.IntN(2) == 0 {

metamorphic/options_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ func TestOptionsRoundtrip(t *testing.T) {
8585
"Experimental.SingleDeleteInvariantViolationCallback:",
8686
"Experimental.EnableDeleteOnlyCompactionExcises:",
8787
"Experimental.ValueSeparationPolicy:",
88+
"Experimental.LatencyTolerantSpanPolicy:",
8889
"Levels[0].Compression:",
8990
"Levels[1].Compression:",
9091
"Levels[2].Compression:",

metrics_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/cockroachdb/datadriven"
2222
"github.com/cockroachdb/pebble/internal/base"
2323
"github.com/cockroachdb/pebble/internal/cache"
24+
"github.com/cockroachdb/pebble/internal/compact"
2425
"github.com/cockroachdb/pebble/internal/humanize"
2526
"github.com/cockroachdb/pebble/internal/manifest"
2627
"github.com/cockroachdb/pebble/internal/testkeys"
@@ -259,6 +260,11 @@ func TestMetrics(t *testing.T) {
259260
MaxBlobReferenceDepth: 5,
260261
}
261262
}
263+
opts.Experimental.LatencyTolerantSpanPolicy = func() compact.ValueSeparationOutputConfig {
264+
return compact.ValueSeparationOutputConfig{
265+
MinimumSize: 10,
266+
}
267+
}
262268
opts.TargetFileSizes[0] = 50
263269

264270
// Prevent foreground flushes and compactions from triggering asynchronous

0 commit comments

Comments
 (0)