From 381c069505152f8b5a6cf2ccf66b5be6c35e9d34 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Fri, 24 Jan 2025 20:10:01 +0700 Subject: [PATCH] nodedb: use SafeNoSync (#13545) port of https://github.com/erigontech/erigon/issues/13457 --- erigon-lib/kv/mdbx/kv_mdbx.go | 7 ++++--- p2p/enode/nodedb.go | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/erigon-lib/kv/mdbx/kv_mdbx.go b/erigon-lib/kv/mdbx/kv_mdbx.go index 9bc205c8326..f42c9479049 100644 --- a/erigon-lib/kv/mdbx/kv_mdbx.go +++ b/erigon-lib/kv/mdbx/kv_mdbx.go @@ -116,9 +116,10 @@ func (opts MdbxOpts) WriteMergeThreshold(v uint64) MdbxOpts { opts.mergeTh func (opts MdbxOpts) WithTableCfg(f TableCfgFunc) MdbxOpts { opts.bucketsCfg = f; return opts } // Flags -func (opts MdbxOpts) HasFlag(flag uint) bool { return opts.flags&flag != 0 } -func (opts MdbxOpts) AddFlags(flags uint) MdbxOpts { opts.flags = opts.flags | flags; return opts } -func (opts MdbxOpts) RemoveFlags(flags uint) MdbxOpts { opts.flags = opts.flags &^ flags; return opts } +func (opts MdbxOpts) HasFlag(flag uint) bool { return opts.flags&flag != 0 } +func (opts MdbxOpts) Flags(f func(uint) uint) MdbxOpts { opts.flags = f(opts.flags); return opts } +func (opts MdbxOpts) AddFlags(flags uint) MdbxOpts { opts.flags = opts.flags | flags; return opts } +func (opts MdbxOpts) RemoveFlags(flags uint) MdbxOpts { opts.flags = opts.flags &^ flags; return opts } func (opts MdbxOpts) boolToFlag(enabled bool, flag uint) MdbxOpts { if enabled { return opts.AddFlags(flag) diff --git a/p2p/enode/nodedb.go b/p2p/enode/nodedb.go index 857d2f0b48a..d6590851b14 100644 --- a/p2p/enode/nodedb.go +++ b/p2p/enode/nodedb.go @@ -32,11 +32,11 @@ import ( "time" "github.com/c2h5oh/datasize" - - "github.com/erigontech/erigon-lib/log/v3" + mdbx1 "github.com/erigontech/mdbx-go/mdbx" "github.com/erigontech/erigon-lib/kv" "github.com/erigontech/erigon-lib/kv/mdbx" + "github.com/erigontech/erigon-lib/log/v3" "github.com/erigontech/erigon-lib/rlp" ) @@ -124,6 +124,8 @@ func newPersistentDB(ctx context.Context, logger log.Logger, path string) (*DB, WithTableCfg(bucketsConfig). MapSize(8 * datasize.GB). GrowthStep(16 * datasize.MB). + Flags(func(f uint) uint { return f ^ mdbx1.Durable | mdbx1.SafeNoSync }). + SyncPeriod(2 * time.Second). DirtySpace(uint64(64 * datasize.MB)). Open(ctx) if err != nil {