-
Notifications
You must be signed in to change notification settings - Fork 117
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
fix(state): Write database format version to disk atomically to avoid a rare panic #8795
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… directories with `default_cache_dir()`
…spawn_atomic_write_to_tmp_file` for use in async environments.
…s callsite to avoid adding tokio as a dependency of zebra-chain.
upbqdn
previously approved these changes
Aug 26, 2024
arya2
commented
Aug 28, 2024
Co-authored-by: Marek <[email protected]>
upbqdn
approved these changes
Aug 29, 2024
dmidem
pushed a commit
to QED-it/zebra
that referenced
this pull request
Oct 29, 2024
… a rare panic (ZcashFoundation#8795) * Splits `atomic_write_to_tmp_file` out of `zebra_network::Config::update_peer_cache` * Uses the new `atomic_write_to_tmp_file` fn in `update_peer_cache()` * Replaces repetitive code for getting the default peer and state cache directories with `default_cache_dir()` * Converts `atomic_write_to_tmp_file` to a blocking function and adds `spawn_atomic_write_to_tmp_file` for use in async environments. * Uses `atomic_write_to_tmp_file` to write database versions to disk * Removes `spawn_atomic_write_to_tmp_file()` and inlines its body at its callsite to avoid adding tokio as a dependency of zebra-chain. * Apply suggestions from code review Co-authored-by: Marek <[email protected]> --------- Co-authored-by: Marek <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
We want to avoid potentially corrupting the database format version file when updating it.
Closes #8793.
Solution
atomic_write_to_tmp_file()
fn.fs::write()
inwrite_database_format_version_to_disk()
with a call toatomic_write_to_tmp_file()
.Tests
Parts of this change are covered by existing tests for
update_peer_cache()
.We could also add a test for the atomic file write that interrupts a very expensive file system operation and checks that nothing has been written to the target file path, though I would prefer to leave that as follow-up work.
Follow-up Work
atomic_write_to_tmp_file()
doesn't write anything to the target file path when interrupted.PR Author's Checklist
PR Reviewer's Checklist