From bf912d4eaa945187332b35a897345fd4bfc264dc Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 7 Dec 2022 10:31:14 +0700 Subject: [PATCH] save --- common/dbg/experiments.go | 16 ++++++++++++++++ kv/mdbx/kv_mdbx.go | 3 +++ 2 files changed, 19 insertions(+) diff --git a/common/dbg/experiments.go b/common/dbg/experiments.go index 4bbd97b13..c911115a8 100644 --- a/common/dbg/experiments.go +++ b/common/dbg/experiments.go @@ -58,6 +58,22 @@ func WriteMap() bool { return writeMap } +var ( + noSync bool + noSyncOnce sync.Once +) + +func NoSync() bool { + noSyncOnce.Do(func() { + v, _ := os.LookupEnv("NO_SYNC") + if v == "true" { + noSync = true + log.Info("[Experiment]", "NO_SYNC", noSync) + } + }) + return noSync +} + var ( mergeTr int mergeTrOnce sync.Once diff --git a/kv/mdbx/kv_mdbx.go b/kv/mdbx/kv_mdbx.go index a093437c3..9aa368314 100644 --- a/kv/mdbx/kv_mdbx.go +++ b/kv/mdbx/kv_mdbx.go @@ -177,6 +177,9 @@ func (opts MdbxOpts) Open() (kv.RwDB, error) { if dbg.WriteMap() { opts = opts.WriteMap() //nolint } + if dbg.NoSync() { + opts = opts.Flags(func(u uint) uint { return u | mdbx.SafeNoSync }) //nolint + } if dbg.MergeTr() > 0 { opts = opts.WriteMergeThreshold(uint64(dbg.MergeTr() * 8192)) //nolint }