-
Notifications
You must be signed in to change notification settings - Fork 20.1k
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
core/rawdb, cmd, ethdb, eth: implement freezer tail deletion #23954
Conversation
e313ed9
to
9b08ce3
Compare
91e6c0e
to
8619875
Compare
8619875
to
09afc60
Compare
2c29e6f
to
63ca13f
Compare
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.
Did some comment editing
faed9c6
to
8c7bb69
Compare
8c7bb69
to
2a1d49f
Compare
2a1d49f
to
ea04113
Compare
ea04113
to
964ae61
Compare
We need to bump the database verison. |
Now the freezer is fully compatible with the old version Geth. It's unnecessary to bump the database version. |
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.
Nitpicks
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.
LGTM
…m#23954) * core/rawdb, cmd, ethdb, eth: implement freezer tail deletion * core/rawdb: address comments from martin and sina * core/rawdb: fixes cornercase in tail deletion * core/rawdb: separate metadata into a standalone file * core/rawdb: remove unused code * core/rawdb: add random test * core/rawdb: polish code * core/rawdb: fsync meta file before manipulating the index * core/rawdb: fix typo * core/rawdb: address comments
…m#23954) * core/rawdb, cmd, ethdb, eth: implement freezer tail deletion * core/rawdb: address comments from martin and sina * core/rawdb: fixes cornercase in tail deletion * core/rawdb: separate metadata into a standalone file * core/rawdb: remove unused code * core/rawdb: add random test * core/rawdb: polish code * core/rawdb: fsync meta file before manipulating the index * core/rawdb: fix typo * core/rawdb: address comments
…m#23954) * core/rawdb, cmd, ethdb, eth: implement freezer tail deletion * core/rawdb: address comments from martin and sina * core/rawdb: fixes cornercase in tail deletion * core/rawdb: separate metadata into a standalone file * core/rawdb: remove unused code * core/rawdb: add random test * core/rawdb: polish code * core/rawdb: fsync meta file before manipulating the index * core/rawdb: fix typo * core/rawdb: address comments
This PR introduces the tail deletion of freezer.
File level deletion
The tail deletion is at file level by design. It means whenever data items at tail are deleted, they will not be removed from the file immediately. Instead they will be hidden until items in the tail data file are all deleted then the entire data file will be dropped.
Reasons
Performance
The reason for designing this lazy deletion mechanism is mainly for saving cost of updating index file. The lookup in freezer is using item id to calculate the relative position in index file, read the data position info from the index file and finally read the data from data file.
However in order to delete the tail items from the data file, all the remaining items in this data file must be shifted forward and all of them need to be re-indexed by modifying the corresponding position information in the index file. This action is super expensive. So deletion by file is a good choice in terms of avoiding re-index.
Atomicity
Another big reason for lazy deletion is it's easier to gain atomicity guarantee. The deletion procedure contains the mutation to index file and data file. These two mutations should be applied at the same time, or apply none of them.
In this design we only need to update the index file atomically. The de-referenced data file can be dropped any time, even after the crash. For sake of simplification, it's a big win.