Skip to content

Commit

Permalink
db: turn testingAlwaysWaitForCleanup into an option
Browse files Browse the repository at this point in the history
There are some potential racy problems by making it a variable
which is written to after the db is opened. All of the existing
use cases can just use this variable as an option.
  • Loading branch information
bananabrick committed Oct 3, 2023
1 parent a05b019 commit c7c47d6
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ func TestCleaner(t *testing.T) {
}
// Asynchronous table stats retrieval makes the output flaky.
opts.private.disableTableStats = true
opts.private.testingAlwaysWaitForCleanup = true
d, err := Open(dir, opts)
if err != nil {
return err.Error()
}
d.TestOnlyWaitForCleaning()
d.testingAlwaysWaitForCleanup = true
dbs[dir] = d
return memLog.String()

Expand Down
2 changes: 1 addition & 1 deletion compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -3778,7 +3778,7 @@ func (d *DB) deleteObsoleteFiles(jobID int) {
if len(filesToDelete) > 0 {
d.cleanupManager.EnqueueJob(jobID, filesToDelete)
}
if d.testingAlwaysWaitForCleanup {
if d.opts.private.testingAlwaysWaitForCleanup {
d.cleanupManager.Wait()
}
}
Expand Down
3 changes: 0 additions & 3 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,6 @@ type DB struct {
closedCh chan struct{}

cleanupManager *cleanupManager
// testingAlwaysWaitForCleanup is set by some tests to force waiting for
// obsolete file deletion (to make events deterministic).
testingAlwaysWaitForCleanup bool

// During an iterator close, we may asynchronously schedule read compactions.
// We want to wait for those goroutines to finish, before closing the DB.
Expand Down
2 changes: 1 addition & 1 deletion event_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestEventListener(t *testing.T) {
t = t.Add(time.Second)
return t
}
d.testingAlwaysWaitForCleanup = true
d.opts.private.testingAlwaysWaitForCleanup = true
return memLog.String()

case "close":
Expand Down
4 changes: 4 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,10 @@ type Options struct {
// A private option to disable stats collection.
disableTableStats bool

// testingAlwaysWaitForCleanup is set by some tests to force waiting for
// obsolete file deletion (to make events deterministic).
testingAlwaysWaitForCleanup bool

// fsCloser holds a closer that should be invoked after a DB using these
// Options is closed. This is used to automatically stop the
// long-running goroutine associated with the disk-health-checking FS.
Expand Down

0 comments on commit c7c47d6

Please sign in to comment.