-
Notifications
You must be signed in to change notification settings - Fork 17
Fix async flush logic and flaky unit test #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -152,34 +152,35 @@ | |
| } | ||
| database.lastRangeHashedCache = lastHashed | ||
|
|
||
| if config.DedicatedChangelog { | ||
| if config.KeepRecent < 0 { | ||
| return nil, errors.New("KeepRecent must be non-negative") | ||
| } | ||
| streamHandler, _ := changelog.NewStream( | ||
| logger.NewNopLogger(), | ||
| utils.GetChangelogPath(dataDir), | ||
| changelog.Config{ | ||
| DisableFsync: true, | ||
| ZeroCopy: true, | ||
| KeepRecent: uint64(config.KeepRecent), | ||
| PruneInterval: 300 * time.Second, | ||
| }, | ||
| ) | ||
| database.streamHandler = streamHandler | ||
| go database.writeAsyncInBackground() | ||
| } | ||
| if config.KeepRecent < 0 { | ||
| return nil, errors.New("KeepRecent must be non-negative") | ||
| } | ||
| streamHandler, _ := changelog.NewStream( | ||
| logger.NewNopLogger(), | ||
| utils.GetChangelogPath(dataDir), | ||
| changelog.Config{ | ||
| DisableFsync: true, | ||
| ZeroCopy: true, | ||
| KeepRecent: uint64(config.KeepRecent), | ||
| PruneInterval: time.Duration(config.PruneIntervalSeconds) * time.Second, | ||
| }, | ||
| ) | ||
| database.streamHandler = streamHandler | ||
| go database.writeAsyncInBackground() | ||
Check noticeCode scanning / CodeQL Spawning a Go routine Note
Spawning a Go routine may be a possible source of non-determinism
|
||
|
|
||
| return database, nil | ||
| } | ||
|
|
||
| func (db *Database) Close() error { | ||
| // First, stop accepting new pending changes and drain the worker | ||
| close(db.pendingChanges) | ||
|
||
| // Wait for the async writes to finish | ||
| db.asyncWriteWG.Wait() | ||
| // Now close the WAL stream | ||
| if db.streamHandler != nil { | ||
| _ = db.streamHandler.Close() | ||
| db.streamHandler = nil | ||
| close(db.pendingChanges) | ||
| } | ||
| // Wait for the async writes to finish | ||
| db.asyncWriteWG.Wait() | ||
| err := db.storage.Close() | ||
| db.storage = nil | ||
| return err | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.