Skip to content
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

Merged
merged 10 commits into from
Mar 10, 2022

Conversation

rjl493456442
Copy link
Member

@rjl493456442 rjl493456442 commented Nov 23, 2021

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.

ethdb/database.go Outdated Show resolved Hide resolved
@rjl493456442 rjl493456442 force-pushed the freezer-tail-deletion branch 3 times, most recently from 91e6c0e to 8619875 Compare November 25, 2021 06:10
@s1na s1na mentioned this pull request Nov 29, 2021
@rjl493456442 rjl493456442 force-pushed the freezer-tail-deletion branch 2 times, most recently from 2c29e6f to 63ca13f Compare January 10, 2022 08:36
core/rawdb/freezer.go Outdated Show resolved Hide resolved
core/rawdb/freezer_meta.go Outdated Show resolved Hide resolved
core/rawdb/freezer_meta.go Outdated Show resolved Hide resolved
Copy link
Contributor

@s1na s1na left a 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

core/rawdb/accessors_chain.go Outdated Show resolved Hide resolved
core/rawdb/freezer.go Outdated Show resolved Hide resolved
core/rawdb/freezer.go Outdated Show resolved Hide resolved
core/rawdb/freezer_meta.go Outdated Show resolved Hide resolved
core/rawdb/freezer_table.go Outdated Show resolved Hide resolved
@rjl493456442
Copy link
Member Author

We need to bump the database verison.

@rjl493456442
Copy link
Member Author

Now the freezer is fully compatible with the old version Geth. It's unnecessary to bump the database version.

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicks

core/rawdb/freezer_meta.go Show resolved Hide resolved
core/rawdb/freezer_table.go Outdated Show resolved Hide resolved
Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@holiman holiman merged commit 538a868 into ethereum:master Mar 10, 2022
@holiman holiman added this to the 1.10.17 milestone Mar 10, 2022
sidhujag pushed a commit to syscoin/go-ethereum that referenced this pull request Mar 11, 2022
…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
JacekGlen pushed a commit to JacekGlen/go-ethereum that referenced this pull request May 26, 2022
…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
cp-wjhan pushed a commit to cp-yoonjin/go-wemix that referenced this pull request Nov 16, 2022
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants