-
Notifications
You must be signed in to change notification settings - Fork 107
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
feat(state): delete old database directories #4586
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4586 +/- ##
==========================================
- Coverage 79.07% 79.01% -0.06%
==========================================
Files 304 304
Lines 37418 37499 +81
==========================================
+ Hits 29589 29631 +42
- Misses 7829 7868 +39 |
This looks good, and it looks like it should work. If we wanted to test it, we'd need to pass the current state version as a function argument. And I'm not sure it's worth it. Our ephemeral database code is very similar, and it works fine. I have some suggestions about edge cases, simplifications, and module structure. Did you want to catch up to talk through them, or I could make a PR, or I could write some comments? |
Comments or PR are welcome (whatever is easier for you). Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filesystem error and path handling is a bit tricky in Rust, I made some suggestions to avoid panics.
I have some other suggestions about performance and module structure, but they are optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The premature returns and panics are all fixed, so we can merge this if you want.
(The other changes can be made in other PRs, but they are all optional.)
…ectory (#4631) * Add function comments, tweak log * Simplify version parsing * Use spawn_blocking to launch the task on a separate thread, do the cleanup last * Abort the cleanup task when Zebra exits * Split directory deletion into its own function, handle ownership * Rename cache_dir to state_dir * If an outdated state directory is outside the cache directory, don't delete it * Minimise diffs
I'm going to merge |
@Mergifyio update |
✅ Branch has been successfully updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, we just need to fix a non-canonical path on macOS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks great, and thanks for the tests!
* ZIPs were updated to remove ambiguity, this was tracked in #1267. * #2105 was fixed by #3039 and #2379 was closed by #3069 * #2230 was a duplicate of #2231 which was closed by #2511 * #3235 was obsoleted by #2156 which was fixed by #3505 * #1850 was fixed by #2944, #1851 was fixed by #2961 and #2902 was fixed by #2969 * We migrated to Rust 2021 edition in Jan 2022 with #3332 * #1631 was closed as not needed * #338 was fixed by #3040 and #1162 was fixed by #3067 * #2079 was fixed by #2445 * #4794 was fixed by #6122 * #1678 stopped being an issue * #3151 was fixed by #3934 * #3204 was closed as not needed * #1213 was fixed by #4586 * #1774 was closed as not needed * #4633 was closed as not needed * Clarify behaviour of difficulty spacing Co-authored-by: teor <teor@riseup.net> * Update comment to reflect implemented behaviour Co-authored-by: teor <teor@riseup.net> * Update comment to reflect implemented behaviour when retrying block downloads Co-authored-by: teor <teor@riseup.net> * Update `TODO` to remove closed issue and clarify when we might want to fix Co-authored-by: teor <teor@riseup.net> * Update `TODO` to remove closed issue and clarify what we might want to change in future Co-authored-by: teor <teor@riseup.net> * Clarify benefits of how we do block verification Co-authored-by: teor <teor@riseup.net> * Fix rustfmt errors --------- Co-authored-by: teor <teor@riseup.net>
Motivation
When the database format change, a new full blockchain will be downloaded when zebra starts. The old blockchain will remain in the file system occupying a lot of hard drive space.
We want to delete this old versions of the blockchain by default when zebra starts, but we also want a config option to not do it if the user want to keep the different versions for whatever reason.
This PR will close #1213 if it gets merged.
Solution
When zebra start and if the
delete_old_database
config option is set totrue
, the code added here will check the database directories and delete the ones that are considered all. Directory will be deleted will all the content inside them.Review
I think anyone can review, open for improvements, probably some code in the
check_and_delete_old_databases
can be simplified a bit.No tests were made, i do tested manually.
check_and_delete_old_databases
function could be tested with different scenarios but i am unsure if it will worth to do it.