Skip to content

Commit 6b27dae

Browse files
committed
db: add leaktest to compaction unit tests
One test, TestCompaction_UpdateVersionFails, has a leak that I haven't dug into yet.
1 parent 83f68e0 commit 6b27dae

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

compaction_test.go

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

2626
"github.com/cockroachdb/crlib/crstrings"
2727
"github.com/cockroachdb/crlib/crtime"
28+
"github.com/cockroachdb/crlib/testutils/leaktest"
2829
"github.com/cockroachdb/datadriven"
2930
"github.com/cockroachdb/errors"
3031
"github.com/cockroachdb/errors/oserror"
@@ -123,6 +124,8 @@ func (p *compactionPickerForTesting) pickAutoNonScore(env compactionEnv) (pc pic
123124
}
124125

125126
func TestPickCompaction(t *testing.T) {
127+
defer leaktest.AfterTest(t)()
128+
126129
fileNums := func(files manifest.LevelSlice) string {
127130
var ss []string
128131
for meta := range files.All() {
@@ -559,6 +562,8 @@ func TestPickCompaction(t *testing.T) {
559562
}
560563

561564
func TestAutomaticFlush(t *testing.T) {
565+
defer leaktest.AfterTest(t)()
566+
562567
const memTableSize = 10000
563568
// Tuned so that 2 values can reside in the memtable before a flush, but a
564569
// 3rd value will cause a flush. Needs to account for the max skiplist node
@@ -701,6 +706,8 @@ func TestAutomaticFlush(t *testing.T) {
701706
}
702707

703708
func TestValidateVersionEdit(t *testing.T) {
709+
defer leaktest.AfterTest(t)()
710+
704711
const badKey = "malformed-key"
705712

706713
errValidationFailed := errors.New("validation failed")
@@ -871,6 +878,8 @@ func TestValidateVersionEdit(t *testing.T) {
871878
// TestCompaction tests compaction mechanics. It is a datadriven test, with
872879
// multiple datadriven test files in the testdata/compaction directory.
873880
func TestCompaction(t *testing.T) {
881+
defer leaktest.AfterTest(t)()
882+
874883
var mem vfs.FS
875884
var d *DB
876885
defer func() {
@@ -1508,6 +1517,8 @@ func TestCompaction(t *testing.T) {
15081517
}
15091518

15101519
func TestCompactionOutputLevel(t *testing.T) {
1520+
defer leaktest.AfterTest(t)()
1521+
15111522
opts := DefaultOptions()
15121523
version := manifest.NewInitialVersion(opts.Comparer)
15131524
l0Organizer := manifest.NewL0Organizer(opts.Comparer, 0 /* flushSplitBytes */)
@@ -1537,6 +1548,8 @@ func TestCompactionOutputLevel(t *testing.T) {
15371548
}
15381549

15391550
func TestCompactionDeleteOnlyHints(t *testing.T) {
1551+
defer leaktest.AfterTest(t)()
1552+
15401553
parseUint64 := func(s string) uint64 {
15411554
v, err := strconv.ParseUint(s, 10, 64)
15421555
require.NoError(t, err)
@@ -1815,6 +1828,8 @@ func TestCompactionDeleteOnlyHints(t *testing.T) {
18151828
}
18161829

18171830
func TestCompactionTombstones(t *testing.T) {
1831+
defer leaktest.AfterTest(t)()
1832+
18181833
var d *DB
18191834
defer func() {
18201835
if d != nil {
@@ -1969,6 +1984,7 @@ func closeAllSnapshots(d *DB) error {
19691984
}
19701985

19711986
func TestCompactionReadTriggeredQueue(t *testing.T) {
1987+
defer leaktest.AfterTest(t)()
19721988

19731989
// Convert a read compaction to a string which this test
19741990
// understands.
@@ -2045,6 +2061,8 @@ func (qu *readCompactionQueue) at(i int) *readCompaction {
20452061
}
20462062

20472063
func TestCompactionReadTriggered(t *testing.T) {
2064+
defer leaktest.AfterTest(t)()
2065+
20482066
var d *DB
20492067
defer func() {
20502068
if d != nil {
@@ -2159,6 +2177,8 @@ func TestCompactionReadTriggered(t *testing.T) {
21592177
}
21602178

21612179
func TestCompactionAllowZeroSeqNum(t *testing.T) {
2180+
defer leaktest.AfterTest(t)()
2181+
21622182
var d *DB
21632183
defer func() {
21642184
if d != nil {
@@ -2272,6 +2292,8 @@ func TestCompactionAllowZeroSeqNum(t *testing.T) {
22722292
}
22732293

22742294
func TestCompactionErrorOnUserKeyOverlap(t *testing.T) {
2295+
defer leaktest.AfterTest(t)()
2296+
22752297
cmp := DefaultComparer.Compare
22762298
parseMeta := func(s string) *manifest.TableMetadata {
22772299
parts := strings.Split(s, "-")
@@ -2324,6 +2346,8 @@ func TestCompactionErrorOnUserKeyOverlap(t *testing.T) {
23242346
// after some output tables have been created. It ensures that the pending
23252347
// output tables are removed from the filesystem.
23262348
func TestCompactionErrorCleanup(t *testing.T) {
2349+
defer leaktest.AfterTest(t)()
2350+
23272351
// protected by d.mu
23282352
var (
23292353
initialSetupDone bool
@@ -2399,6 +2423,8 @@ func TestCompactionErrorCleanup(t *testing.T) {
23992423
}
24002424

24012425
func TestCompactionCheckOrdering(t *testing.T) {
2426+
defer leaktest.AfterTest(t)()
2427+
24022428
cmp := DefaultComparer.Compare
24032429
parseMeta := func(s string) *manifest.TableMetadata {
24042430
parts := strings.Split(s, "-")
@@ -2522,6 +2548,8 @@ func TestCompactionCheckOrdering(t *testing.T) {
25222548
}
25232549

25242550
func TestCompactFlushQueuedMemTableAndFlushMetrics(t *testing.T) {
2551+
defer leaktest.AfterTest(t)()
2552+
25252553
t.Run("", func(t *testing.T) {
25262554
// Verify that manual compaction forces a flush of a queued memtable.
25272555

@@ -2584,6 +2612,8 @@ func TestCompactFlushQueuedMemTableAndFlushMetrics(t *testing.T) {
25842612
}
25852613

25862614
func TestCompactFlushQueuedLargeBatch(t *testing.T) {
2615+
defer leaktest.AfterTest(t)()
2616+
25872617
// Verify that compaction forces a flush of a queued large batch.
25882618

25892619
mem := vfs.NewMem()
@@ -2620,6 +2650,8 @@ func TestCompactFlushQueuedLargeBatch(t *testing.T) {
26202650
}
26212651

26222652
func TestFlushError(t *testing.T) {
2653+
defer leaktest.AfterTest(t)()
2654+
26232655
// Error the first five times we try to write a sstable.
26242656
var errorOps atomic.Int32
26252657
errorOps.Store(3)
@@ -2646,6 +2678,8 @@ func TestFlushError(t *testing.T) {
26462678
}
26472679

26482680
func TestAdjustGrandparentOverlapBytesForFlush(t *testing.T) {
2681+
defer leaktest.AfterTest(t)()
2682+
26492683
// 500MB in Lbase
26502684
var lbaseFiles []*manifest.TableMetadata
26512685
const lbaseSize = 5 << 20
@@ -2685,6 +2719,8 @@ func TestAdjustGrandparentOverlapBytesForFlush(t *testing.T) {
26852719
}
26862720

26872721
func TestCompactionInvalidBounds(t *testing.T) {
2722+
defer leaktest.AfterTest(t)()
2723+
26882724
opts := &Options{
26892725
FS: vfs.NewMem(),
26902726
}
@@ -2698,6 +2734,8 @@ func TestCompactionInvalidBounds(t *testing.T) {
26982734
}
26992735

27002736
func TestMarkedForCompaction(t *testing.T) {
2737+
defer leaktest.AfterTest(t)()
2738+
27012739
var mem vfs.FS = vfs.NewMem()
27022740
var d *DB
27032741
defer func() {
@@ -2838,6 +2876,9 @@ var _ errorfs.Injector = &createManifestErrorInjector{}
28382876
//
28392877
// Regression test for #1669.
28402878
func TestCompaction_UpdateVersionFails(t *testing.T) {
2879+
// TODO(jackson): Fix the leak.
2880+
// defer leaktest.AfterTest(t)()
2881+
28412882
// flushKeys writes the given keys to the DB, flushing the resulting memtable.
28422883
var key = []byte("foo")
28432884
flushErrC := make(chan error)
@@ -2935,6 +2976,8 @@ func TestCompaction_UpdateVersionFails(t *testing.T) {
29352976
// TestSharedObjectDeletePacing tests that we don't throttle shared object
29362977
// deletes (see the TargetBytesDeletionRate option).
29372978
func TestSharedObjectDeletePacing(t *testing.T) {
2979+
defer leaktest.AfterTest(t)()
2980+
29382981
var opts Options
29392982
opts.FS = vfs.NewMem()
29402983
opts.Experimental.RemoteStorage = remote.MakeSimpleFactory(map[remote.Locator]remote.Storage{
@@ -3027,6 +3070,8 @@ var _ errorfs.Injector = &WriteErrorInjector{}
30273070

30283071
// Cumulative compaction stats shouldn't be updated on compaction error.
30293072
func TestCompactionErrorStats(t *testing.T) {
3073+
defer leaktest.AfterTest(t)()
3074+
30303075
// protected by d.mu
30313076
var (
30323077
useInjector bool
@@ -3111,6 +3156,8 @@ func TestCompactionErrorStats(t *testing.T) {
31113156
}
31123157

31133158
func TestCompactionCorruption(t *testing.T) {
3159+
defer leaktest.AfterTest(t)()
3160+
31143161
if buildtags.SlowBuild {
31153162
t.Skip("disabled in slow builds")
31163163
}
@@ -3151,6 +3198,11 @@ func TestCompactionCorruption(t *testing.T) {
31513198
})
31523199
d, err := Open("", opts)
31533200
require.NoError(t, err)
3201+
defer func() {
3202+
if d != nil {
3203+
require.NoError(t, d.Close())
3204+
}
3205+
}()
31543206

31553207
var now crtime.AtomicMono
31563208
now.Store(1)
@@ -3314,6 +3366,8 @@ func hasExternalFiles(d *DB) bool {
33143366
// - There are no overlapping files in the output level
33153367
// - The grandparent overlap is below the threshold
33163368
func TestTombstoneDensityCompactionMoveOptimization(t *testing.T) {
3369+
defer leaktest.AfterTest(t)()
3370+
33173371
const (
33183372
inputLevel = 4
33193373
outputLevel = 5
@@ -3412,6 +3466,8 @@ func TestTombstoneDensityCompactionMoveOptimization(t *testing.T) {
34123466
// TestTombstoneDensityCompactionMoveOptimization_NoMoveWithOverlap verifies that
34133467
// the move optimization does NOT apply when there is an overlapping file in the output level.
34143468
func TestTombstoneDensityCompactionMoveOptimization_NoMoveWithOverlap(t *testing.T) {
3469+
defer leaktest.AfterTest(t)()
3470+
34153471
const (
34163472
inputLevel = 4
34173473
outputLevel = 5
@@ -3490,6 +3546,8 @@ func TestTombstoneDensityCompactionMoveOptimization_NoMoveWithOverlap(t *testing
34903546
// TestTombstoneDensityCompactionMoveOptimization_GrandparentOverlapTooLarge
34913547
// verifies that the move optimization does NOT apply if the grandparent overlap exceeds the threshold.
34923548
func TestTombstoneDensityCompactionMoveOptimization_GrandparentOverlapTooLarge(t *testing.T) {
3549+
defer leaktest.AfterTest(t)()
3550+
34933551
const (
34943552
inputLevel = 4
34953553
outputLevel = 5
@@ -3553,6 +3611,8 @@ func TestTombstoneDensityCompactionMoveOptimization_GrandparentOverlapTooLarge(t
35533611
// TestTombstoneDensityCompactionMoveOptimization_BelowDensityThreshold
35543612
// verifies that the move optimization does NOT apply if the file's tombstone density is below the threshold.
35553613
func TestTombstoneDensityCompactionMoveOptimization_BelowDensityThreshold(t *testing.T) {
3614+
defer leaktest.AfterTest(t)()
3615+
35563616
const (
35573617
inputLevel = 4
35583618
outputLevel = 5
@@ -3600,6 +3660,8 @@ func TestTombstoneDensityCompactionMoveOptimization_BelowDensityThreshold(t *tes
36003660
// TestTombstoneDensityCompactionMoveOptimization_InvalidStats
36013661
// verifies that the move optimization does NOT apply if the file's stats are missing or invalid.
36023662
func TestTombstoneDensityCompactionMoveOptimization_InvalidStats(t *testing.T) {
3663+
defer leaktest.AfterTest(t)()
3664+
36033665
const (
36043666
inputLevel = 4
36053667
outputLevel = 5

0 commit comments

Comments
 (0)