mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
eth, trie/triedb/pathdb: address comments
This commit is contained in:
parent
dd9770c19a
commit
7a3f807b54
4 changed files with 17 additions and 16 deletions
|
|
@ -131,9 +131,10 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
|||
}
|
||||
// Optimize memory distribution by reallocating surplus allowance from the
|
||||
// dirty cache to the clean cache.
|
||||
if config.StateScheme == rawdb.PathScheme && config.TrieDirtyCache > pathdb.MaxBufferSize/1024/1024 {
|
||||
config.TrieCleanCache += config.TrieDirtyCache - pathdb.MaxBufferSize/1024/1024
|
||||
config.TrieDirtyCache = pathdb.MaxBufferSize / 1024 / 1024
|
||||
if config.StateScheme == rawdb.PathScheme && config.TrieDirtyCache > pathdb.MaxDirtyBufferSize/1024/1024 {
|
||||
log.Info("Capped dirty cache size", "provided", common.StorageSize(config.TrieDirtyCache)*1024*1024, "adjusted", common.StorageSize(pathdb.MaxDirtyBufferSize))
|
||||
config.TrieCleanCache += config.TrieDirtyCache - pathdb.MaxDirtyBufferSize/1024/1024
|
||||
config.TrieDirtyCache = pathdb.MaxDirtyBufferSize / 1024 / 1024
|
||||
}
|
||||
log.Info("Allocated trie memory caches", "clean", common.StorageSize(config.TrieCleanCache)*1024*1024, "dirty", common.StorageSize(config.TrieDirtyCache)*1024*1024)
|
||||
|
||||
|
|
|
|||
|
|
@ -683,6 +683,6 @@ func (h *handler) enableSyncedFeatures() {
|
|||
h.snapSync.Store(false)
|
||||
}
|
||||
if h.chain.TrieDB().Scheme() == rawdb.PathScheme {
|
||||
h.chain.TrieDB().SetBufferSize(pathdb.DefaultBufferSize)
|
||||
h.chain.TrieDB().SetBufferSize(pathdb.DefaultDirtyBufferSize)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,18 +40,18 @@ const (
|
|||
// defaultCleanSize is the default memory allowance of clean cache.
|
||||
defaultCleanSize = 16 * 1024 * 1024
|
||||
|
||||
// MaxBufferSize is the maximum memory allowance of node buffer.
|
||||
// MaxDirtyBufferSize is the maximum memory allowance of node buffer.
|
||||
// Too large nodebuffer will cause the system to pause for a long
|
||||
// time when write happens. Also, the largest batch that pebble can
|
||||
// support is 4GB, node will panic if batch size exceeds this limit.
|
||||
MaxBufferSize = 256 * 1024 * 1024
|
||||
MaxDirtyBufferSize = 256 * 1024 * 1024
|
||||
|
||||
// DefaultBufferSize is the default memory allowance of node buffer
|
||||
// DefaultDirtyBufferSize is the default memory allowance of node buffer
|
||||
// that aggregates the writes from above until it's flushed into the
|
||||
// disk. It's meant to be used once the initial sync is finished.
|
||||
// Do not increase the buffer size arbitrarily, otherwise the system
|
||||
// pause time will increase when the database writes happen.
|
||||
DefaultBufferSize = 64 * 1024 * 1024
|
||||
DefaultDirtyBufferSize = 64 * 1024 * 1024
|
||||
)
|
||||
|
||||
// layer is the interface implemented by all state layers which includes some
|
||||
|
|
@ -96,9 +96,9 @@ type Config struct {
|
|||
// unreasonable or unworkable.
|
||||
func (c *Config) sanitize() *Config {
|
||||
conf := *c
|
||||
if conf.DirtyCacheSize > MaxBufferSize {
|
||||
log.Warn("Sanitizing invalid node buffer size", "provided", common.StorageSize(conf.DirtyCacheSize), "updated", common.StorageSize(MaxBufferSize))
|
||||
conf.DirtyCacheSize = MaxBufferSize
|
||||
if conf.DirtyCacheSize > MaxDirtyBufferSize {
|
||||
log.Warn("Sanitizing invalid node buffer size", "provided", common.StorageSize(conf.DirtyCacheSize), "updated", common.StorageSize(MaxDirtyBufferSize))
|
||||
conf.DirtyCacheSize = MaxDirtyBufferSize
|
||||
}
|
||||
return &conf
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ func (c *Config) sanitize() *Config {
|
|||
var Defaults = &Config{
|
||||
StateHistory: params.FullImmutabilityThreshold,
|
||||
CleanCacheSize: defaultCleanSize,
|
||||
DirtyCacheSize: DefaultBufferSize,
|
||||
DirtyCacheSize: DefaultDirtyBufferSize,
|
||||
}
|
||||
|
||||
// ReadOnly is the config in order to open database in read only mode.
|
||||
|
|
@ -439,9 +439,9 @@ func (db *Database) SetBufferSize(size int) error {
|
|||
db.lock.Lock()
|
||||
defer db.lock.Unlock()
|
||||
|
||||
if size > MaxBufferSize {
|
||||
log.Info("Capped node buffer size", "provided", common.StorageSize(size), "adjusted", common.StorageSize(MaxBufferSize))
|
||||
size = MaxBufferSize
|
||||
if size > MaxDirtyBufferSize {
|
||||
log.Info("Capped node buffer size", "provided", common.StorageSize(size), "adjusted", common.StorageSize(MaxDirtyBufferSize))
|
||||
size = MaxDirtyBufferSize
|
||||
}
|
||||
db.bufferSize = size
|
||||
return db.tree.bottom().setBufferSize(db.bufferSize)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ import (
|
|||
func emptyLayer() *diskLayer {
|
||||
return &diskLayer{
|
||||
db: New(rawdb.NewMemoryDatabase(), nil),
|
||||
buffer: newNodeBuffer(DefaultBufferSize, nil, 0),
|
||||
buffer: newNodeBuffer(DefaultDirtyBufferSize, nil, 0),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue