Skip to content

Commit

Permalink
Only reduce the consensus db size based on flags values (#8321) (#8327)
Browse files Browse the repository at this point in the history
This is to fix an issue with resource usage if the db.size.limit is
increased from its default setting of 2TB. This is applied to the chain
DB, but should not be used on the consensus DB which has smaller data
requirements. Expanding both DBs results in excessive RAM being reserved
by the underlying OS.

---------

Co-authored-by: Mark Holt <135143369+mh0lt@users.noreply.github.com>
  • Loading branch information
yperbasis and mh0lt committed Sep 29, 2023
1 parent b8744d9 commit c91efdc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 5 additions & 2 deletions erigon-lib/kv/mdbx/kv_mdbx.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ type MdbxOpts struct {
inMem bool
}

const DefaultMapSize = 2 * datasize.TB
const DefaultGrowthStep = 2 * datasize.GB

func NewMDBX(log log.Logger) MdbxOpts {
opts := MdbxOpts{
bucketsCfg: WithChaindataTables,
Expand All @@ -81,8 +84,8 @@ func NewMDBX(log log.Logger) MdbxOpts {
// but for reproducibility of benchmarks - please don't rely on Available RAM
dirtySpace: 2 * (memory.TotalMemory() / 42),

mapSize: 2 * datasize.TB,
growthStep: 2 * datasize.GB,
mapSize: DefaultMapSize,
growthStep: DefaultGrowthStep,
mergeThreshold: 3 * 8192,
shrinkThreshold: -1, // default
label: kv.InMem,
Expand Down
14 changes: 13 additions & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func OpenDatabase(config *nodecfg.Config, label kv.Label, name string, readonly
}

switch label {
case kv.ChainDB, kv.ConsensusDB:
case kv.ChainDB:
if config.MdbxPageSize.Bytes() > 0 {
opts = opts.PageSize(config.MdbxPageSize.Bytes())
}
Expand All @@ -335,6 +335,18 @@ func OpenDatabase(config *nodecfg.Config, label kv.Label, name string, readonly
if config.MdbxGrowthStep > 0 {
opts = opts.GrowthStep(config.MdbxGrowthStep)
}
case kv.ConsensusDB:
if config.MdbxPageSize.Bytes() > 0 {
opts = opts.PageSize(config.MdbxPageSize.Bytes())
}
// Don't adjust up the consensus DB - this will lead to resource exhaustion lor large map sizes
if config.MdbxDBSizeLimit > 0 && config.MdbxDBSizeLimit < mdbx.DefaultMapSize {
opts = opts.MapSize(config.MdbxDBSizeLimit)
}
// Don't adjust up the consensus DB - to align with db size limit above
if config.MdbxGrowthStep > 0 && config.MdbxGrowthStep < mdbx.DefaultGrowthStep {
opts = opts.GrowthStep(config.MdbxGrowthStep)
}
default:
opts = opts.GrowthStep(16 * datasize.MB)
}
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
const (
VersionMajor = 2 // Major version component of the current release
VersionMinor = 50 // Minor version component of the current release
VersionMicro = 0 // Patch version component of the current release
VersionMicro = 1 // Patch version component of the current release
VersionModifier = "" // Modifier component of the current release
VersionKeyCreated = "ErigonVersionCreated"
VersionKeyFinished = "ErigonVersionFinished"
Expand Down

0 comments on commit c91efdc

Please sign in to comment.