-
Notifications
You must be signed in to change notification settings - Fork 179
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
[Storehouse] Implement Register store #4940
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4940 +/- ##
==========================================
+ Coverage 56.23% 61.15% +4.92%
==========================================
Files 969 20 -949
Lines 90431 1555 -88876
==========================================
- Hits 50854 951 -49903
+ Misses 35789 551 -35238
+ Partials 3788 53 -3735
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
2bdcffa
to
0424af0
Compare
|
||
type PrunedError struct { | ||
PrunedHeight uint64 | ||
Height uint64 |
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.
can you add a comment explaining what is the difference between height and pruned height
@zhangchiqing is this PR the same as the one I already reviewed? |
d66ec98
to
99bae7c
Compare
ae3aa51
to
ee8d328
Compare
ee8d328
to
039b226
Compare
// finalizationProcessingLoop notify the register store when a block is finalized | ||
// and handle the error if any |
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.
// finalizationProcessingLoop notify the register store when a block is finalized | |
// and handle the error if any | |
// finalizationProcessingLoop notifies the register store when a block is finalized. |
regs, err := r.memStore.GetUpdatedRegisters(next, blockID) | ||
if errors.Is(err, ErrNotExecuted) { | ||
// next block is not executed yet | ||
return 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.
could we join the GetUpdatedRegisters an Prune calls into one call.
something like PopUpdatedRegisters
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 can't prune before successfully storing it in diskstore, otherwise if there is a query getting register at the pruned height, it will fail, because the in-mem store has pruned its value, and disk store has not stored it yet.
I also can't store into disk store first, because I need to retrieve the updated registers from memStore first.
f1df248
to
e90aa0d
Compare
// if in memory store returns PrunedError, and register height is above the pruned height, | ||
// then it means the block is connected to the pruned block of in memory store, which is | ||
// a finalized block and executed block, so we can get its value from on disk store. | ||
if height > prunedError.PrunedHeight { |
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.
would this always be one bigger than pruned height? how could it be bigger than that?
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.
It could be a few blocks bigger, not just one. For instance:
X is 3 at height 10,
X is 6 at height 15.
block 12 is finalized, now (X: 3, height: 10) is stored in OnDiskRegisterStore, and (X: 6, height: 15) is stored in InMemoryRegisterStore.
Then GetRegister(14, X)
will first query memStore, which returns prunedError with prunedHeight as 12. So the height 14 is bigger than prunedHeight 12 by 2 (bigger than one), now we need to query diskStore with (X, 12), which returns 3. Meaning X at height 14 is the same as X at height 12, because X wasn't updated from height 11 to 14.
return fmt.Errorf("cannot save register to memStore: %w", err) | ||
} | ||
|
||
err = r.OnBlockFinalized() |
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.
will it be ok if the OnBlockFinalized
is not run since it's being used by another goroutine?
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.
It's ok, because:
- another goroutine will recursively call OnBlockFinalized for the next block, until there is no more finalized blocks.
- it's also ok to miss a call to onBlockFinalized, because the correct register value can still be returned regardless it's stored in in-memory store or on-disk store. We are also resistant from crash-failure, because during startup recovery, we will re-execute all blocks since on-disk store's latest executed height.
return fmt.Errorf("cannot save %v registers to disk store for height %v: %w", len(regs), next, err) | ||
} | ||
|
||
err = r.memStore.Prune(next, blockID) |
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.
is it ok to prune with every block finalized, would it be a valuable improvement if we only prune once we don't have more finalized blocks? not sure how expensive is to prune just an 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.
prune should be fast and cheap, since it's just acquire a lock and updating some index in memory.
I think the performance is quite similar comparing the following two approach:
- pruning once to prune 3 finalized blocks
- pruning 3 times each time to prune 1 finalized block
e90aa0d
to
f7d8ede
Compare
This PR implements the RegisterStore.
Closes: #4659