mdbx mergeThreshold option #665

This commit is contained in:
Alex Sharov 2022-10-03 16:53:23 +07:00 committed by GitHub
parent ca2ebac0f9
commit 9860f845fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}
}