From 9860f845fe5c2d879634cccc2cada2091664636f Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Mon, 3 Oct 2022 16:53:23 +0700 Subject: [PATCH] mdbx mergeThreshold option #665 --- kv/mdbx/kv_mdbx.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/kv/mdbx/kv_mdbx.go b/kv/mdbx/kv_mdbx.go index 6c09615bc..06512ecfc 100644 --- a/kv/mdbx/kv_mdbx.go +++ b/kv/mdbx/kv_mdbx.go @@ -59,7 +59,12 @@ type MdbxOpts struct { syncPeriod time.Duration augumentLimit uint64 pageSize uint64 - roTxsLimiter *semaphore.Weighted + + // must be in the range from 12.5% (almost empty) to 50% (half empty) + // which corresponds to the range from 8192 and to 32768 in units respectively + mergeThreshold uint64 + + roTxsLimiter *semaphore.Weighted } func testKVPath() string { @@ -72,11 +77,12 @@ func testKVPath() string { func NewMDBX(log log.Logger) MdbxOpts { return MdbxOpts{ - bucketsCfg: WithChaindataTables, - flags: mdbx.NoReadahead | mdbx.Coalesce | mdbx.Durable, - log: log, - pageSize: kv.DefaultPageSize(), - growthStep: 2 * datasize.GB, + bucketsCfg: WithChaindataTables, + flags: mdbx.NoReadahead | mdbx.Coalesce | mdbx.Durable, + log: log, + pageSize: kv.DefaultPageSize(), + growthStep: 2 * datasize.GB, + mergeThreshold: 32768, } } @@ -160,6 +166,11 @@ func (opts MdbxOpts) WriteMap() MdbxOpts { return opts } +func (opts MdbxOpts) WriteMergeThreshold(v uint64) MdbxOpts { + opts.mergeThreshold = v + return opts +} + func (opts MdbxOpts) WithTableCfg(f TableCfgFunc) MdbxOpts { opts.bucketsCfg = f return opts @@ -263,7 +274,7 @@ func (opts MdbxOpts) Open() (kv.RwDB, error) { } // must be in the range from 12.5% (almost empty) to 50% (half empty) // which corresponds to the range from 8192 and to 32768 in units respectively - if err = env.SetOption(mdbx.OptMergeThreshold16dot16Percent, 32768); err != nil { + if err = env.SetOption(mdbx.OptMergeThreshold16dot16Percent, opts.mergeThreshold); err != nil { return nil, err } }