-
Notifications
You must be signed in to change notification settings - Fork 203
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
Trie storage statistics component #5401
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## rc/v1.7.0 #5401 +/- ##
===========================================
Coverage 80.34% 80.34%
===========================================
Files 708 709 +1
Lines 93768 93922 +154
===========================================
+ Hits 75335 75459 +124
- Misses 13149 13173 +24
- Partials 5284 5290 +6
☔ View full report in Codecov by Sentry. |
trie/patriciaMerkleTrie.go
Outdated
func (tr *patriciaMerkleTrie) GetStats() string { | ||
dbWithStats, ok := tr.trieStorage.(storageManagerWithStats) | ||
if !ok { | ||
log.Warn("invalid trie storage type %T", tr.trieStorage) |
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 will print invalid trie storage type %T
.
fmt.Sprintf("invalid trie storage type %T", tr.trieStorage)
will print the storage type
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.
done, thanks
trie/patriciaMerkleTrie.go
Outdated
@@ -269,6 +269,17 @@ func (tr *patriciaMerkleTrie) Commit() error { | |||
return nil | |||
} | |||
|
|||
// GetStats will returns trie storage operations statistics as string | |||
func (tr *patriciaMerkleTrie) GetStats() string { |
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.
Add tests for this func
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.
done
common/interface.go
Outdated
@@ -116,10 +117,17 @@ type StorageManager interface { | |||
IsInterfaceNil() bool | |||
} | |||
|
|||
// StorageManagerWithStats defines the behaviour of a storage manager component with stats collector | |||
type StorageManagerWithStats interface { |
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 this can be removed.
common/interface.go
Outdated
@@ -56,6 +56,7 @@ type Trie interface { | |||
VerifyProof(rootHash []byte, key []byte, proof [][]byte) (bool, error) | |||
GetStorageManager() StorageManager | |||
IsMigratedToLatestVersion() (bool, error) | |||
GetStats() string |
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.
GetStorageStats() ?
storage/interface.go
Outdated
@@ -91,6 +91,12 @@ type StorerWithPutInEpoch interface { | |||
SetEpochForPutOperation(epoch uint32) | |||
} | |||
|
|||
// StorerWithPutInEpoch is an extended storer with the ability to set the epoch which will be used for put operations |
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.
StorerWithStats ....
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.
updated comment
storage/pruning/pruningStorer.go
Outdated
v, ok := ps.cacher.Get(key) | ||
if ok { | ||
return v.([]byte), nil | ||
return v.([]byte), true, 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.
On L447 replace with if errors.Is(err, storage.ErrDBIsClosed)
please
state/accountsDB.go
Outdated
@@ -877,6 +877,7 @@ func (adb *AccountsDB) CommitInEpoch(currentEpoch uint32, epochToCommit uint32) | |||
adb.mutOp.Lock() | |||
defer func() { | |||
adb.mainTrie.GetStorageManager().SetEpochForPutOperation(currentEpoch) | |||
adb.printTrieStorageStatistics() |
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 needs to also be called on Commit()
.
The stats need to be reset after each commit if we want to know the stats for each block without adding extra operations.
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.
added
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.
Maybe move it inside func (adb *AccountsDB) commit() ([]byte, error)
. This will remove duplicated code.
state/accountsDB.go
Outdated
if stats != "" { | ||
log.Debug("trie storage statistics", | ||
"storage manager", adb.mainTrie.GetStorageManager().GetIdentifier(), | ||
"stats", adb.mainTrie.GetStats(), |
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.
use stats
instead of adb.mainTrie.GetStats()
@@ -41,3 +50,8 @@ func (tsm *trieStorageManagerWithoutCheckpoints) SetCheckpoint( | |||
func (tsm *trieStorageManagerWithoutCheckpoints) AddDirtyCheckpointHashes(_ []byte, _ common.ModifiedHashes) bool { | |||
return false | |||
} | |||
|
|||
// GetStatsCollector will return the stats collector component | |||
func (tsm *trieStorageManagerWithoutCheckpoints) GetStatsCollector() common.StateStatisticsHandler { |
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 this can be removed, as this func is exported on common.StorageManager
interface. By removing this, there is no need to have storerWithStats
.
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.
right 👍
@@ -59,7 +60,7 @@ func (c *chainStorer) GetStorer(unitType dataRetriever.UnitType) (storage.Storer | |||
_, ok := c.mapStorages[unitType] | |||
if !ok { | |||
log.Debug("created new mem storer", "key", unitType) | |||
c.mapStorages[unitType] = CreateMemUnit() | |||
c.mapStorages[unitType] = testscommon.CreateMemStorerWithStats(CreateMemUnit()) |
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 we have the MemStorerWithStats somewhere else, not in the testscommon? please create it somewhere else, so that we do not import testscommon in the production code.
@@ -97,59 +97,59 @@ func TestNewSystemSCProcessor(t *testing.T) { | |||
cfg := config.EnableEpochs{ | |||
StakingV2EnableEpoch: 100, | |||
} | |||
args, _ := createFullArgumentsForSystemSCProcessing(cfg, createMemUnit()) | |||
args, _ := createFullArgumentsForSystemSCProcessing(cfg, testscommon.CreateStorerWithStats()) |
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 creates a memory
-StorerWithStats and from the name it is not obvious any more. Could it be renamed to something like: CreateDefaultMemStorerWithStats
?
trie/patriciaMerkleTrie.go
Outdated
@@ -269,6 +269,17 @@ func (tr *patriciaMerkleTrie) Commit() error { | |||
return nil | |||
} | |||
|
|||
// GetStorageStats will returns trie storage operations statistics as string |
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 return, not will returnS
trie/patriciaMerkleTrie.go
Outdated
@@ -269,6 +269,17 @@ func (tr *patriciaMerkleTrie) Commit() error { | |||
return nil | |||
} | |||
|
|||
// GetStorageStats will returns trie storage operations statistics as string | |||
func (tr *patriciaMerkleTrie) GetStorageStats() string { | |||
dbWithStats, ok := tr.trieStorage.(storageManagerWithStats) |
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 this be called many times and fail? there will be a lot of warns in the log.
could all StorageManagers have a GetStatsCollector() that returns "" on ToString()?
if not, could you also add a unit test for the branch !ok?
trie/trieStorageManager.go
Outdated
return nil, storage.ErrNilStatsCollector | ||
} | ||
|
||
storerWithStats, ok := args.MainStorer.(common.StorerWithStats) |
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 the args.MainStorer be of type common.StorerWithStats? This way this check is not needed anymore, if the MainStorer has to be always StorerWithStats
trie/trieStorageManager.go
Outdated
@@ -184,17 +197,28 @@ func (tsm *trieStorageManager) Get(key []byte) ([]byte, error) { | |||
return nil, core.ErrContextClosing | |||
} | |||
|
|||
val, err := tsm.mainStorer.Get(key) | |||
val, foundInCache, err := tsm.mainStorer.GetWithStats(key) |
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 the trieStorageManager should know about the caches... could the statsCollector be injected one level lower in a PruningStorerWithStats for example?
} | ||
|
||
return nil | ||
return n.resolveCollapsed(pos, db) |
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 number of resolveCollapsed can be computed from the trieOps and cacheOps?
dataRetriever/factory/storageRequestersContainer/shardRequestersContainerFactory.go
Show resolved
Hide resolved
return v, false, err | ||
} | ||
|
||
// CreateMemStorerWithStats - |
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.
Add proper comments, this is productive code
trie/patriciaMerkleTrie.go
Outdated
@@ -40,6 +40,7 @@ type patriciaMerkleTrie struct { | |||
hasher hashing.Hasher | |||
enableEpochsHandler common.EnableEpochsHandler | |||
trieNodeVersionVerifier core.TrieNodeVersionVerifier | |||
stateStatsHandler common.StateStatisticsHandler |
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 is not used anywhere
The base branch was changed.
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.
Normal allin test: v1.5.13-dev-config-8c685c8e00 -> trie-storage-statistics-co-4c31571a2d
--- Specific errors ---
block hash does not match 6173
wrong nonce in block 2582
miniblocks does not match 0
num miniblocks does not match 0
miniblock hash does not match 0
block bodies does not match 0
receipts hash missmatch 1
/------/
--- Statistics ---
Nr. of all ERRORS: 1
Nr. of all WARNS: 1442
Nr. of new ERRORS: 1
Nr. of new WARNS: 8
Nr. of PANICS: 0
/------/
--- ERRORS ---
/------/
6a4be57
Reasoning behind the pull request
Testing procedure
StateStatisticsEnabled = true
in[StateTriesConfig]
section fromconfig.toml
Pre-requisites
Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:
feat
branch created?feat
branch merging, do all satellite projects have a proper tag insidego.mod
?