mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-28 14:47:16 +00:00
kv: expose mdbx SafeNoSync and OptSyncPeriod options (#356)
This commit is contained in:
parent
75b52ac25e
commit
009358ab2f
@ -27,6 +27,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/c2h5oh/datasize"
|
||||
stack2 "github.com/go-stack/stack"
|
||||
@ -52,6 +53,7 @@ type MdbxOpts struct {
|
||||
mapSize datasize.ByteSize
|
||||
flags uint
|
||||
log log.Logger
|
||||
syncPeriod time.Duration
|
||||
augumentLimit uint64
|
||||
pageSize uint64
|
||||
roTxsLimiter chan struct{}
|
||||
@ -124,6 +126,11 @@ func (opts MdbxOpts) Readonly() MdbxOpts {
|
||||
return opts
|
||||
}
|
||||
|
||||
func (opts MdbxOpts) SyncPeriod(period time.Duration) MdbxOpts {
|
||||
opts.syncPeriod = period
|
||||
return opts
|
||||
}
|
||||
|
||||
func (opts MdbxOpts) DBVerbosity(v kv.DBVerbosityLvl) MdbxOpts {
|
||||
opts.verbosity = v
|
||||
return opts
|
||||
@ -227,6 +234,15 @@ func (opts MdbxOpts) Open() (kv.RwDB, error) {
|
||||
return nil, fmt.Errorf("%w, label: %s, trace: %s", err, opts.label.String(), stack2.Trace().String())
|
||||
}
|
||||
|
||||
if opts.syncPeriod != 0 {
|
||||
// the option value is in 1/65536 of second units
|
||||
optValue := uint64(opts.syncPeriod / (time.Second / 65536))
|
||||
if err = env.SetOption(mdbx.OptSyncPeriod, optValue); err != nil {
|
||||
env.Close()
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if opts.roTxsLimiter == nil {
|
||||
|
||||
opts.roTxsLimiter = make(chan struct{}, runtime.NumCPU())
|
||||
|
Loading…
Reference in New Issue
Block a user