kv: expose mdbx SafeNoSync and OptSyncPeriod options (#356)

This commit is contained in:
battlmonstr 2022-03-10 04:25:11 +01:00 committed by GitHub
parent 75b52ac25e
commit 009358ab2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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())