Skip to content

Commit 06c3d70

Browse files
committed
db: deflake TestCompactionCorruption
This test can still be flaky in CI. Tweaking it to generate many non-overlapping L0 files instead of many L0 sublevels; this way there are no intra-L0 compactions that compete with the compactions we care about. I ran it under stress locally for a few hours (700k runs) with the 2 minute internal timeout reduced to 15s. Fixes #4634
1 parent 14bdcd5 commit 06c3d70

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

compaction_test.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,15 +2902,13 @@ func TestCompactionCorruption(t *testing.T) {
29022902
},
29032903
},
29042904
L0CompactionThreshold: 1,
2905-
L0CompactionFileThreshold: 10,
2905+
L0CompactionFileThreshold: 5,
29062906
}
29072907
opts.WithFSDefaults()
29082908
remoteStorage := remote.NewInMem()
29092909
opts.Experimental.RemoteStorage = remote.MakeSimpleFactory(map[remote.Locator]remote.Storage{
29102910
"external-locator": remoteStorage,
29112911
})
2912-
opts.EnsureDefaults()
2913-
opts.Levels[0].TargetFileSize = 8192
29142912
d, err := Open("", opts)
29152913
require.NoError(t, err)
29162914

@@ -2928,16 +2926,17 @@ func TestCompactionCorruption(t *testing.T) {
29282926
defer workloadWG.Done()
29292927
for !stopWorkload.Load() {
29302928
b := d.NewBatch()
2931-
// Write some random keys of the form a012345.
2932-
for i := 0; i < 100; i++ {
2933-
v := make([]byte, 100+rand.IntN(100))
2934-
for i := range v {
2935-
v[i] = byte(rand.Uint32())
2936-
}
2937-
key := fmt.Sprintf("%c%06d", 'a'+byte(rand.IntN(int('z'-'a'+1))), rand.IntN(1000000))
2938-
if err := b.Set([]byte(key), v, nil); err != nil {
2939-
panic(err)
2940-
}
2929+
// Write a random key of the form a012345 and flush it. This will result
2930+
// in (mostly) non-overlapping tables in L0.
2931+
var valSeed [32]byte
2932+
for i := range valSeed {
2933+
valSeed[i] = byte(rand.Uint32())
2934+
}
2935+
v := make([]byte, 1024+rand.IntN(10240))
2936+
_, _ = rand.NewChaCha8(valSeed).Read(v)
2937+
key := fmt.Sprintf("%c%06d", 'a'+byte(rand.IntN(int('z'-'a'+1))), rand.IntN(1000000))
2938+
if err := b.Set([]byte(key), v, nil); err != nil {
2939+
panic(err)
29412940
}
29422941
if err := b.Commit(nil); err != nil {
29432942
panic(err)

0 commit comments

Comments
 (0)