-
Notifications
You must be signed in to change notification settings - Fork 20.4k
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: Enforce readonly in freezer instantiation #24119
Conversation
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.
I think you also should take care of the case where someone tries to actually write to the freezer. This can be done in several ways -- all write happens via the batch, afaik, so you could centralize the check there. Perhaps make the singular f.writeBatch
be nil if readonly, or set the batch to non-nil but "refusing to write".
Hm, my comment was a bit misplaced. So the |
This is not implemented, and I added a test to check how it would behave. What happens is that the I think that's an ok scenario, The caller can write to a batch, but it will eventually fail, and there should be no side-effects, afaict. So I'm good. |
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
5175e9f
to
208c7a9
Compare
core/rawdb/freezer.go
Outdated
var length uint64 | ||
var name string | ||
// Hack to get length of any table | ||
for k, table := range f.tables { |
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.
I think we can merge these two loops into single one, to have less code.
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.
Other nit, please rename k
to something a bit better, lest go with kind
without a better idea.
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.
I think we can merge these two loops into single one, to have less code.
I understand that would be shorted in terms of lines, but I find it more readable to have them logically separate. If you don't have a strong feeling about it I'd like to keep it as is.
So I found out |
After fixing that issue the logs for ❯ ./build/bin/geth --dev --datadir dev-datadir-legacy db inspect
INFO [01-11|19:57:55.086] Maximum peer count ETH=50 LES=0 total=50
INFO [01-11|19:57:55.087] Set global gas cap cap=50,000,000
INFO [01-11|19:57:55.151] Using developer account address=0xe0AD84EE1bC06DCb400235A3006997e262A3106F
INFO [01-11|19:57:55.151] Allocated cache and file handles database=~/data/geth/chaindata cache=512.00MiB handles=5120 readonly=true
WARN [01-11|19:57:55.158] Truncating dangling indexes database=~/data/geth/chaindata/ancient table=receipts indexed=1.19MiB stored=1.19MiB
Fatal: Could not open database: truncate ~/data/geth/chaindata/ancient/receipts.cidx: invalid argument Not super clean IMHO. I'm tilting slightly towards adding back the extra checks. |
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.
SGTM
* freezer: add readonly flag to table * freezer: enforce readonly in table repair * freezer: enforce readonly in newFreezer * minor fix * minor * core/rawdb: test that writing during readonly fails * rm unused log * check readonly on batch append * minor * Revert "check readonly on batch append" This reverts commit 2ddb5ec. * review fixes * minor test refactor * attempt at fixing windows issue * add comment re windows sync issue * k->kind * open readonly db for genesis check Co-authored-by: Martin Holst Swende <martin@swende.se>
* freezer: add readonly flag to table * freezer: enforce readonly in table repair * freezer: enforce readonly in newFreezer * minor fix * minor * core/rawdb: test that writing during readonly fails * rm unused log * check readonly on batch append * minor * Revert "check readonly on batch append" This reverts commit 2ddb5ec. * review fixes * minor test refactor * attempt at fixing windows issue * add comment re windows sync issue * k->kind * open readonly db for genesis check Co-authored-by: Martin Holst Swende <martin@swende.se>
When opening the freezer in readonly mode (e.g.
db inspect
command) we still perform repair, possibly modifying the underlying files. This PR changes that and only raises an error instead when freezer is in an invalid state.