-
Notifications
You must be signed in to change notification settings - Fork 198
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
Optimize db lookup extensions while sync & fast-reply-database #2269
Conversation
…nly on "receive notifications" goroutines.
…for both, shard and metachain nodes
@@ -50,6 +50,7 @@ type historyRepository struct { | |||
// that could mistakenly override the "patch()" operations performed when consuming notarization notifications. | |||
deduplicationCacheForInsertMiniblockMetadata storage.Cacher | |||
|
|||
// Question for review: this can be removed now, using the new approach (without the block tracker), right? |
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 only situation when the notifications will be redundant will be when a node will do a rollback. In this situation the same final block/blocks will be notified again, after another new block will be constructed upon it. But this case should not be a regular pattern and could be considered as an exception. If this redundant notifications will not break something in the implementation logic and the below method was used just as an optimization for this case, I would say that you can remove it now, considering the new approach.
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 implementation of OnNotarizedBlocks()
is all right with being called twice with some redundant data in case of rollbacks. Removed the extra optimization, thanks!
@@ -246,12 +247,14 @@ func (hr *historyRepository) OnNotarizedBlocks(shardID uint32, headers []data.He | |||
for i, headerHandler := range headers { | |||
headerHash := headersHashes[i] | |||
|
|||
log.Debug("onNotarizedBlocks():", "shardID", shardID, "nonce", headerHandler.GetNonce(), "headerHash", headerHash, "type", fmt.Sprintf("%T", headerHandler)) | |||
|
|||
// Question for review: this optimization is not required anymore, right? |
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 same response as above
cmd/node/config/config.toml
Outdated
@@ -645,7 +645,7 @@ | |||
PollingIntervalInMinutes = 65 | |||
|
|||
[DbLookupExtensions] | |||
Enabled = false | |||
Enabled = true # TODO DISABLE AFTER TESTS |
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.
don't forget to revert
@@ -158,6 +176,14 @@ func (hr *historyRepository) computeMiniblockHash(miniblock *block.MiniBlock) ([ | |||
return core.CalculateHash(hr.marshalizer, hr.hasher, miniblock) | |||
} | |||
|
|||
func (hr *historyRepository) hasRecentlyInsertedMiniblockMetadata(miniblockHash []byte) bool { | |||
return hr.deduplicationCacheForInsertMiniblockMetadata.Has(miniblockHash) |
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.
In case of a miniblock added in epoch x on a fork, but added again in epoch x+1 on canonical chain, the "miniblock hash to epoch" will not be updated with the correct epoch.
maybe add also the epoch in this cache as value, and only deduplicate if the epoch value is the same, otherwise update.
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.
Very very nice catch 🥳
Fixed by using a composite key for the deduplication cache. Is it all right?
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.
looks 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.
System tests passed.
RecordBlock
synchronously withCommit()
. Consume notifications only on "receive notifications" goroutines.Hold LRU caches for recently handled records so that performance at sync is improvednot needed anymoreshardBlock
/metaBlock
processor.Handle repeated commits of same block (protect against overriding the
miniblockMetadata
) / EN-7520. Edge case was:Foo
, start processing notifications (in progress), notification is seen, still in mapFoo
Foo
from map