-
Notifications
You must be signed in to change notification settings - Fork 671
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
P-chain state prune + height index #1719
Conversation
numIndexed = 0 | ||
) | ||
|
||
for blockIterator.Next() { |
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.
Where is the early exit if the node shuts down?
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 VM takes care of shutting down here: https://github.com/ava-labs/avalanchego/blob/master/vms/platformvm/vm.go#L315-L352
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 don't think we've really added any of these for any of our indexing - it'll exit when the DB errors due to being closed.. (or when the process exits 🤷)
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.
And to ask a question I think I know the answer to, partial pruning will be handled gracefully (and the pruned value will only be written once we've iterated over all elements)?
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.
Hmmmm this should be the case. But I think we should probably check for blockIterator.Error()
before trying to write the pruned value. Specifically, because it doesn't seem like the corruptabledb has any handling for iterators.
// Since we only store accepted blocks on disk, we only need to store a map of | ||
// ids.ID to Block. | ||
if isStateBlk { | ||
if err := s.blockDB.Put(blkID[:], blkBytes); err != nil { |
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 should have been:
if err := s.blockDB.Put(blkID[:], blk.Bytes()); err != nil {
Why this should be merged
Closes #1623.
This PR is a remake (with significant changes) of the original P-chain height index PR: #1447. We reverted the original PR as it was stalling nodes by populating the height index synchronously.
At the end of the process kicked off in this PR:
blockDB
will be purged from disk.blockDB
will be a map ofblockID
s toBlock
s.blockDB
by removingstateBlk
which takes up unnecessary space.How this works
Kicks off a background process that goes through each block in
blockDB
. Per block, it does this logic:height
toblockID
index (blockIDDb
)stateBlk
inblockDB
, replace it with block bytesTo prevent OOMing nodes and to minimize disruption, we commit periodically (currently set to every
1024
blocks) and sleep after each commit to prevent burning the DB too much.How this was tested