Skip to content

Commit 9ec96e0

Browse files
committed
db: fix TestCheckpointManyFiles
It was incorrectly using the same compaction scheduler across two DB open calls. The fix doesn't change the test, but instead sets a non-nil CompactionScheduler in Open, after the Options are cloned. Fixes #4421
1 parent 3eb304d commit 9ec96e0

File tree

4 files changed

+5
-6
lines changed

4 files changed

+5
-6
lines changed

compaction_scheduler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ func (c *pickedCompactionCache) add(pc *pickedCompaction) {
237237
// ConcurrencyLimitScheduler is the default scheduler used by Pebble. It
238238
// simply uses the concurrency limit retrieved from
239239
// DBForCompaction.GetAllowedWithoutPermission to decide the number of
240-
// compactions to schedule.
240+
// compactions to schedule. ConcurrencyLimitScheduler must have its Register
241+
// method called at most once -- i.e., it cannot be reused across DBs.
241242
//
242243
// Since the GetAllowedWithoutPermission value changes over time, the
243244
// scheduler needs to be quite current in its sampling, especially if the

open.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ func Open(dirname string, opts *Options) (db *DB, err error) {
8181
// Make a copy of the options so that we don't mutate the passed in options.
8282
opts = opts.Clone()
8383
opts.EnsureDefaults()
84+
if opts.Experimental.CompactionScheduler == nil {
85+
opts.Experimental.CompactionScheduler = newConcurrencyLimitScheduler(defaultTimeSource{})
86+
}
8487
if err := opts.Validate(); err != nil {
8588
return nil, err
8689
}

open_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ func TestErrorIfNotPristine(t *testing.T) {
133133
ErrorIfNotPristine: true,
134134
})
135135
defer ensureFilesClosed(t, opts)()
136-
// Ensures each DB will create its own CompactionScheduler in Open.
137-
opts.Experimental.CompactionScheduler = nil
138136

139137
d0, err := Open("", opts)
140138
require.NoError(t, err)

options.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,9 +1272,6 @@ func (o *Options) EnsureDefaults() {
12721272
if o.Experimental.MultiLevelCompactionHeuristic == nil {
12731273
o.Experimental.MultiLevelCompactionHeuristic = WriteAmpHeuristic{}
12741274
}
1275-
if o.Experimental.CompactionScheduler == nil {
1276-
o.Experimental.CompactionScheduler = newConcurrencyLimitScheduler(defaultTimeSource{})
1277-
}
12781275

12791276
o.initMaps()
12801277
}

0 commit comments

Comments
 (0)