@@ -25,6 +25,7 @@ import (
25
25
26
26
"github.com/cockroachdb/crlib/crstrings"
27
27
"github.com/cockroachdb/crlib/crtime"
28
+ "github.com/cockroachdb/crlib/testutils/leaktest"
28
29
"github.com/cockroachdb/datadriven"
29
30
"github.com/cockroachdb/errors"
30
31
"github.com/cockroachdb/errors/oserror"
@@ -123,6 +124,8 @@ func (p *compactionPickerForTesting) pickAutoNonScore(env compactionEnv) (pc pic
123
124
}
124
125
125
126
func TestPickCompaction (t * testing.T ) {
127
+ defer leaktest .AfterTest (t )()
128
+
126
129
fileNums := func (files manifest.LevelSlice ) string {
127
130
var ss []string
128
131
for meta := range files .All () {
@@ -559,6 +562,8 @@ func TestPickCompaction(t *testing.T) {
559
562
}
560
563
561
564
func TestAutomaticFlush (t * testing.T ) {
565
+ defer leaktest .AfterTest (t )()
566
+
562
567
const memTableSize = 10000
563
568
// Tuned so that 2 values can reside in the memtable before a flush, but a
564
569
// 3rd value will cause a flush. Needs to account for the max skiplist node
@@ -701,6 +706,8 @@ func TestAutomaticFlush(t *testing.T) {
701
706
}
702
707
703
708
func TestValidateVersionEdit (t * testing.T ) {
709
+ defer leaktest .AfterTest (t )()
710
+
704
711
const badKey = "malformed-key"
705
712
706
713
errValidationFailed := errors .New ("validation failed" )
@@ -871,6 +878,8 @@ func TestValidateVersionEdit(t *testing.T) {
871
878
// TestCompaction tests compaction mechanics. It is a datadriven test, with
872
879
// multiple datadriven test files in the testdata/compaction directory.
873
880
func TestCompaction (t * testing.T ) {
881
+ defer leaktest .AfterTest (t )()
882
+
874
883
var mem vfs.FS
875
884
var d * DB
876
885
defer func () {
@@ -1508,6 +1517,8 @@ func TestCompaction(t *testing.T) {
1508
1517
}
1509
1518
1510
1519
func TestCompactionOutputLevel (t * testing.T ) {
1520
+ defer leaktest .AfterTest (t )()
1521
+
1511
1522
opts := DefaultOptions ()
1512
1523
version := manifest .NewInitialVersion (opts .Comparer )
1513
1524
l0Organizer := manifest .NewL0Organizer (opts .Comparer , 0 /* flushSplitBytes */ )
@@ -1537,6 +1548,8 @@ func TestCompactionOutputLevel(t *testing.T) {
1537
1548
}
1538
1549
1539
1550
func TestCompactionDeleteOnlyHints (t * testing.T ) {
1551
+ defer leaktest .AfterTest (t )()
1552
+
1540
1553
parseUint64 := func (s string ) uint64 {
1541
1554
v , err := strconv .ParseUint (s , 10 , 64 )
1542
1555
require .NoError (t , err )
@@ -1815,6 +1828,8 @@ func TestCompactionDeleteOnlyHints(t *testing.T) {
1815
1828
}
1816
1829
1817
1830
func TestCompactionTombstones (t * testing.T ) {
1831
+ defer leaktest .AfterTest (t )()
1832
+
1818
1833
var d * DB
1819
1834
defer func () {
1820
1835
if d != nil {
@@ -1969,6 +1984,7 @@ func closeAllSnapshots(d *DB) error {
1969
1984
}
1970
1985
1971
1986
func TestCompactionReadTriggeredQueue (t * testing.T ) {
1987
+ defer leaktest .AfterTest (t )()
1972
1988
1973
1989
// Convert a read compaction to a string which this test
1974
1990
// understands.
@@ -2045,6 +2061,8 @@ func (qu *readCompactionQueue) at(i int) *readCompaction {
2045
2061
}
2046
2062
2047
2063
func TestCompactionReadTriggered (t * testing.T ) {
2064
+ defer leaktest .AfterTest (t )()
2065
+
2048
2066
var d * DB
2049
2067
defer func () {
2050
2068
if d != nil {
@@ -2159,6 +2177,8 @@ func TestCompactionReadTriggered(t *testing.T) {
2159
2177
}
2160
2178
2161
2179
func TestCompactionAllowZeroSeqNum (t * testing.T ) {
2180
+ defer leaktest .AfterTest (t )()
2181
+
2162
2182
var d * DB
2163
2183
defer func () {
2164
2184
if d != nil {
@@ -2272,6 +2292,8 @@ func TestCompactionAllowZeroSeqNum(t *testing.T) {
2272
2292
}
2273
2293
2274
2294
func TestCompactionErrorOnUserKeyOverlap (t * testing.T ) {
2295
+ defer leaktest .AfterTest (t )()
2296
+
2275
2297
cmp := DefaultComparer .Compare
2276
2298
parseMeta := func (s string ) * manifest.TableMetadata {
2277
2299
parts := strings .Split (s , "-" )
@@ -2324,6 +2346,8 @@ func TestCompactionErrorOnUserKeyOverlap(t *testing.T) {
2324
2346
// after some output tables have been created. It ensures that the pending
2325
2347
// output tables are removed from the filesystem.
2326
2348
func TestCompactionErrorCleanup (t * testing.T ) {
2349
+ defer leaktest .AfterTest (t )()
2350
+
2327
2351
// protected by d.mu
2328
2352
var (
2329
2353
initialSetupDone bool
@@ -2399,6 +2423,8 @@ func TestCompactionErrorCleanup(t *testing.T) {
2399
2423
}
2400
2424
2401
2425
func TestCompactionCheckOrdering (t * testing.T ) {
2426
+ defer leaktest .AfterTest (t )()
2427
+
2402
2428
cmp := DefaultComparer .Compare
2403
2429
parseMeta := func (s string ) * manifest.TableMetadata {
2404
2430
parts := strings .Split (s , "-" )
@@ -2522,6 +2548,8 @@ func TestCompactionCheckOrdering(t *testing.T) {
2522
2548
}
2523
2549
2524
2550
func TestCompactFlushQueuedMemTableAndFlushMetrics (t * testing.T ) {
2551
+ defer leaktest .AfterTest (t )()
2552
+
2525
2553
t .Run ("" , func (t * testing.T ) {
2526
2554
// Verify that manual compaction forces a flush of a queued memtable.
2527
2555
@@ -2584,6 +2612,8 @@ func TestCompactFlushQueuedMemTableAndFlushMetrics(t *testing.T) {
2584
2612
}
2585
2613
2586
2614
func TestCompactFlushQueuedLargeBatch (t * testing.T ) {
2615
+ defer leaktest .AfterTest (t )()
2616
+
2587
2617
// Verify that compaction forces a flush of a queued large batch.
2588
2618
2589
2619
mem := vfs .NewMem ()
@@ -2620,6 +2650,8 @@ func TestCompactFlushQueuedLargeBatch(t *testing.T) {
2620
2650
}
2621
2651
2622
2652
func TestFlushError (t * testing.T ) {
2653
+ defer leaktest .AfterTest (t )()
2654
+
2623
2655
// Error the first five times we try to write a sstable.
2624
2656
var errorOps atomic.Int32
2625
2657
errorOps .Store (3 )
@@ -2646,6 +2678,8 @@ func TestFlushError(t *testing.T) {
2646
2678
}
2647
2679
2648
2680
func TestAdjustGrandparentOverlapBytesForFlush (t * testing.T ) {
2681
+ defer leaktest .AfterTest (t )()
2682
+
2649
2683
// 500MB in Lbase
2650
2684
var lbaseFiles []* manifest.TableMetadata
2651
2685
const lbaseSize = 5 << 20
@@ -2685,6 +2719,8 @@ func TestAdjustGrandparentOverlapBytesForFlush(t *testing.T) {
2685
2719
}
2686
2720
2687
2721
func TestCompactionInvalidBounds (t * testing.T ) {
2722
+ defer leaktest .AfterTest (t )()
2723
+
2688
2724
opts := & Options {
2689
2725
FS : vfs .NewMem (),
2690
2726
}
@@ -2698,6 +2734,8 @@ func TestCompactionInvalidBounds(t *testing.T) {
2698
2734
}
2699
2735
2700
2736
func TestMarkedForCompaction (t * testing.T ) {
2737
+ defer leaktest .AfterTest (t )()
2738
+
2701
2739
var mem vfs.FS = vfs .NewMem ()
2702
2740
var d * DB
2703
2741
defer func () {
@@ -2838,6 +2876,9 @@ var _ errorfs.Injector = &createManifestErrorInjector{}
2838
2876
//
2839
2877
// Regression test for #1669.
2840
2878
func TestCompaction_UpdateVersionFails (t * testing.T ) {
2879
+ // TODO(jackson): Fix the leak.
2880
+ // defer leaktest.AfterTest(t)()
2881
+
2841
2882
// flushKeys writes the given keys to the DB, flushing the resulting memtable.
2842
2883
var key = []byte ("foo" )
2843
2884
flushErrC := make (chan error )
@@ -2935,6 +2976,8 @@ func TestCompaction_UpdateVersionFails(t *testing.T) {
2935
2976
// TestSharedObjectDeletePacing tests that we don't throttle shared object
2936
2977
// deletes (see the TargetBytesDeletionRate option).
2937
2978
func TestSharedObjectDeletePacing (t * testing.T ) {
2979
+ defer leaktest .AfterTest (t )()
2980
+
2938
2981
var opts Options
2939
2982
opts .FS = vfs .NewMem ()
2940
2983
opts .Experimental .RemoteStorage = remote .MakeSimpleFactory (map [remote.Locator ]remote.Storage {
@@ -3027,6 +3070,8 @@ var _ errorfs.Injector = &WriteErrorInjector{}
3027
3070
3028
3071
// Cumulative compaction stats shouldn't be updated on compaction error.
3029
3072
func TestCompactionErrorStats (t * testing.T ) {
3073
+ defer leaktest .AfterTest (t )()
3074
+
3030
3075
// protected by d.mu
3031
3076
var (
3032
3077
useInjector bool
@@ -3111,6 +3156,8 @@ func TestCompactionErrorStats(t *testing.T) {
3111
3156
}
3112
3157
3113
3158
func TestCompactionCorruption (t * testing.T ) {
3159
+ defer leaktest .AfterTest (t )()
3160
+
3114
3161
if buildtags .SlowBuild {
3115
3162
t .Skip ("disabled in slow builds" )
3116
3163
}
@@ -3151,6 +3198,11 @@ func TestCompactionCorruption(t *testing.T) {
3151
3198
})
3152
3199
d , err := Open ("" , opts )
3153
3200
require .NoError (t , err )
3201
+ defer func () {
3202
+ if d != nil {
3203
+ require .NoError (t , d .Close ())
3204
+ }
3205
+ }()
3154
3206
3155
3207
var now crtime.AtomicMono
3156
3208
now .Store (1 )
@@ -3314,6 +3366,8 @@ func hasExternalFiles(d *DB) bool {
3314
3366
// - There are no overlapping files in the output level
3315
3367
// - The grandparent overlap is below the threshold
3316
3368
func TestTombstoneDensityCompactionMoveOptimization (t * testing.T ) {
3369
+ defer leaktest .AfterTest (t )()
3370
+
3317
3371
const (
3318
3372
inputLevel = 4
3319
3373
outputLevel = 5
@@ -3412,6 +3466,8 @@ func TestTombstoneDensityCompactionMoveOptimization(t *testing.T) {
3412
3466
// TestTombstoneDensityCompactionMoveOptimization_NoMoveWithOverlap verifies that
3413
3467
// the move optimization does NOT apply when there is an overlapping file in the output level.
3414
3468
func TestTombstoneDensityCompactionMoveOptimization_NoMoveWithOverlap (t * testing.T ) {
3469
+ defer leaktest .AfterTest (t )()
3470
+
3415
3471
const (
3416
3472
inputLevel = 4
3417
3473
outputLevel = 5
@@ -3490,6 +3546,8 @@ func TestTombstoneDensityCompactionMoveOptimization_NoMoveWithOverlap(t *testing
3490
3546
// TestTombstoneDensityCompactionMoveOptimization_GrandparentOverlapTooLarge
3491
3547
// verifies that the move optimization does NOT apply if the grandparent overlap exceeds the threshold.
3492
3548
func TestTombstoneDensityCompactionMoveOptimization_GrandparentOverlapTooLarge (t * testing.T ) {
3549
+ defer leaktest .AfterTest (t )()
3550
+
3493
3551
const (
3494
3552
inputLevel = 4
3495
3553
outputLevel = 5
@@ -3553,6 +3611,8 @@ func TestTombstoneDensityCompactionMoveOptimization_GrandparentOverlapTooLarge(t
3553
3611
// TestTombstoneDensityCompactionMoveOptimization_BelowDensityThreshold
3554
3612
// verifies that the move optimization does NOT apply if the file's tombstone density is below the threshold.
3555
3613
func TestTombstoneDensityCompactionMoveOptimization_BelowDensityThreshold (t * testing.T ) {
3614
+ defer leaktest .AfterTest (t )()
3615
+
3556
3616
const (
3557
3617
inputLevel = 4
3558
3618
outputLevel = 5
@@ -3600,6 +3660,8 @@ func TestTombstoneDensityCompactionMoveOptimization_BelowDensityThreshold(t *tes
3600
3660
// TestTombstoneDensityCompactionMoveOptimization_InvalidStats
3601
3661
// verifies that the move optimization does NOT apply if the file's stats are missing or invalid.
3602
3662
func TestTombstoneDensityCompactionMoveOptimization_InvalidStats (t * testing.T ) {
3663
+ defer leaktest .AfterTest (t )()
3664
+
3603
3665
const (
3604
3666
inputLevel = 4
3605
3667
outputLevel = 5
0 commit comments