dataTriesHolder with eviction cache#7191
dataTriesHolder with eviction cache#7191BeniaminDrasovean merged 13 commits intofeat/collapse-trie-based-on-sizefrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR implements a dataTriesHolder as a linked list with memory management and eviction capabilities. The changes introduce proper memory limits for tries, replace the simple tries holder with a more sophisticated implementation, and update the trie creation API to include memory size parameters.
- Implements a new linked-list-based dataTriesHolder with memory-aware eviction
- Adds memory size parameters to trie creation throughout the codebase
- Replaces the original simple tries holder with a more advanced memory-managed implementation
Reviewed Changes
Copilot reviewed 58 out of 58 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| state/triesHolder/dataTriesHolder.go | Implements new linked-list-based data tries holder with memory management and LRU eviction |
| state/triesHolder/triesHolder.go | Refactors original tries holder to be simpler without Replace method |
| trie/patriciaMerkleTrie.go | Adds maxSizeInMemory parameter to trie constructor and validation |
| state/accountsDB.go | Updates to use new data tries holder with memory limits |
| config/config.go | Adds configuration options for trie memory limits |
| Multiple test files | Updates test files to use new trie creation API with memory parameters |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…sed-on-size # Conflicts: # dataRetriever/factory/resolverscontainer/metaResolversContainerFactory_test.go # dataRetriever/factory/resolverscontainer/shardResolversContainerFactory_test.go # epochStart/bootstrap/process.go # epochStart/metachain/systemSCs_test.go # factory/api/apiResolverFactory.go # factory/processing/blockProcessorCreator_test.go # factory/state/stateComponents.go # genesis/process/memoryComponents.go # integrationTests/state/stateTrie/stateTrie_test.go # integrationTests/testInitializer.go # integrationTests/testProcessorNode.go # integrationTests/vm/staking/componentsHolderCreator.go # state/accountsDB.go # state/accountsDB_test.go # state/factory/accountsAdapterAPICreator_test.go # state/storagePruningManager/storagePruningManager_test.go # testscommon/integrationtests/factory.go # trie/snapshotTrieStorageManager_test.go # trie/trieStorageManagerInEpoch_test.go # update/factory/dataTrieFactory.go # update/genesis/import.go
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 59 out of 59 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
state/triesHolder/triesHolder.go:43
GetandGetAllacquire the write lock (Lock) even though they only read from the map. Since this uses anRWMutex, switching these toRLock/RUnlockwould allow concurrent readers and improve contention under read-heavy access patterns.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## feat/collapse-trie-based-on-size #7191 +/- ##
====================================================================
+ Coverage 76.64% 77.53% +0.89%
====================================================================
Files 823 884 +61
Lines 110227 123727 +13500
====================================================================
+ Hits 84484 95934 +11450
- Misses 20019 21441 +1422
- Partials 5724 6352 +628 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| storageFactory "github.com/multiversx/mx-chain-go/storage/factory" | ||
| "github.com/multiversx/mx-chain-go/storage/storageunit" | ||
| "github.com/multiversx/mx-chain-go/testscommon" | ||
| common2 "github.com/multiversx/mx-chain-go/testscommon/common" |
There was a problem hiding this comment.
maybe rename "common2" in something else
| "github.com/multiversx/mx-chain-go/trie" | ||
| ) | ||
|
|
||
| const tenMbSize = uint64(10485760) |
There was a problem hiding this comment.
maybe move this in the common package and use it everywhere
| "github.com/multiversx/mx-chain-core-go/hashing/blake2b" | ||
| "github.com/multiversx/mx-chain-core-go/marshal" | ||
| "github.com/multiversx/mx-chain-go/integrationTests" | ||
| trie2 "github.com/multiversx/mx-chain-go/testscommon/common" |
There was a problem hiding this comment.
maybe rename "trie2" in something else
| "github.com/multiversx/mx-chain-core-go/hashing/sha256" | ||
| crypto "github.com/multiversx/mx-chain-crypto-go" | ||
| "github.com/multiversx/mx-chain-go/epochStart/notifier" | ||
| common2 "github.com/multiversx/mx-chain-go/testscommon/common" |
| "github.com/multiversx/mx-chain-go/common/errChan" | ||
| "github.com/multiversx/mx-chain-go/integrationTests" | ||
| "github.com/multiversx/mx-chain-go/state/parsers" | ||
| trie2 "github.com/multiversx/mx-chain-go/testscommon/common" |
| return tries | ||
| } | ||
|
|
||
| func (dth *dataTriesHolder) getDirtyTrie(key string) common.Trie { |
There was a problem hiding this comment.
maybe rename in getDirtyTrieNoLock ( similar with putNoLock )
| "github.com/multiversx/mx-chain-go/state/storagePruningManager/disabled" | ||
| "github.com/multiversx/mx-chain-go/state/storagePruningManager/evictionWaitingList" | ||
| "github.com/multiversx/mx-chain-go/testscommon" | ||
| common2 "github.com/multiversx/mx-chain-go/testscommon/common" |
| "github.com/multiversx/mx-chain-go/storage/factory" | ||
| "github.com/multiversx/mx-chain-go/storage/storageunit" | ||
| "github.com/multiversx/mx-chain-go/testscommon" | ||
| common2 "github.com/multiversx/mx-chain-go/testscommon/common" |
|
|
||
| var emptyTrieHash = make([]byte, 32) | ||
|
|
||
| const tenMBSize = uint64(10485760) |
There was a problem hiding this comment.
this const is defined in a lot of places
There was a problem hiding this comment.
It is refactored in the next PR.
|
|
||
| "github.com/multiversx/mx-chain-go/storage" | ||
| "github.com/multiversx/mx-chain-go/testscommon" | ||
| storage2 "github.com/multiversx/mx-chain-go/testscommon/storage" |
| tenMBSize := uint64(10485760) | ||
| dataTrie, err := trie.NewTrie(b.trieStorageManager, b.marshalizer, b.hasher, b.enableEpochsHandler, tenMBSize) |
There was a problem hiding this comment.
is this func still used? is it ok to set static size limit?
There was a problem hiding this comment.
It is not used anywhere.
| for i := 0; i < numTries; i++ { | ||
| go func(key int) { | ||
| dth.Put([]byte(strconv.Itoa(key)), &trieMock.TrieStub{}) | ||
| wg.Done() | ||
| }(i) | ||
| } |
| Identifier: dataRetriever.UserAccountsUnit.String(), | ||
| EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, | ||
| StatsCollector: disabled.NewStateStatistics(), | ||
| MaxSizeInMemory: 10 * 1024 * 1024, // 10 MB |
There was a problem hiding this comment.
use tenMBSize const here also
| oldRoot []byte | ||
| chanClose chan struct{} | ||
| sizeInMemory int | ||
| maxSizeInMem uint64 |
There was a problem hiding this comment.
max size in mem will be used later on in another PR?
There was a problem hiding this comment.
Yes. It will be moved to another component and used there.
| if len(dth.evictedBuffer) > 0 { | ||
| // this means that this trie was evicted while being dirty | ||
| delete(dth.evictedBuffer, keyString) | ||
| } |
There was a problem hiding this comment.
why try to delete current key if there are entries on evictedBuffer? just to make sure it's removed from evicted in case it might be there?
There was a problem hiding this comment.
If a dirty trie is evicted from the cache (this is an edgecase, if the cache is large enough it should never happen), we still need to commit it, so we keep it in dth.evictedBuffer until the commit is triggered. But if that trie is accessed again after it was evicted from the cache but before it was committed, we re-add it to the cache, so we can remove it from the dth.evictedBuffer.
a1758e0
into
feat/collapse-trie-based-on-size
Reasoning behind the pull request
Proposed changes
Testing procedure
Pre-requisites
Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:
featbranch created?featbranch merging, do all satellite projects have a proper tag insidego.mod?