From 818b3b8dafc275ef90c9ce1d379f56a60cde7ded Mon Sep 17 00:00:00 2001 From: Peter Rabbitson Date: Wed, 1 Feb 2023 20:04:58 +0100 Subject: [PATCH] fix: extend LOTUS_CHAIN_BADGERSTORE_DISABLE_FSYNC to the markset Without doing this walking a badger markset on a non-nvme knocks the node hopelessly out of sync during a compaction. --- blockstore/splitstore/markset_badger.go | 4 +++- node/repo/fsrepo.go | 16 +++------------- system/io.go | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 system/io.go diff --git a/blockstore/splitstore/markset_badger.go b/blockstore/splitstore/markset_badger.go index e98046862..8808a6217 100644 --- a/blockstore/splitstore/markset_badger.go +++ b/blockstore/splitstore/markset_badger.go @@ -11,6 +11,8 @@ import ( "github.com/ipfs/go-cid" "go.uber.org/zap" "golang.org/x/xerrors" + + "github.com/filecoin-project/lotus/system" ) type BadgerMarkSetEnv struct { @@ -349,7 +351,7 @@ func (s *BadgerMarkSet) write(seqno int) (err error) { persist := s.persist s.mx.RUnlock() - if persist { + if persist && !system.BadgerFsyncDisable { return s.db.Sync() } diff --git a/node/repo/fsrepo.go b/node/repo/fsrepo.go index bd387babf..3012daaca 100644 --- a/node/repo/fsrepo.go +++ b/node/repo/fsrepo.go @@ -27,6 +27,7 @@ import ( "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/storage/sealer/fsutil" "github.com/filecoin-project/lotus/storage/sealer/storiface" + "github.com/filecoin-project/lotus/system" ) const ( @@ -479,19 +480,8 @@ func (fsr *fsLockedRepo) Blockstore(ctx context.Context, domain BlockstoreDomain return } - // - // Tri-state environment variable LOTUS_CHAIN_BADGERSTORE_DISABLE_FSYNC - // - unset == the default (currently fsync enabled) - // - set with a false-y value == fsync enabled no matter what a future default is - // - set with any other value == fsync is disabled ignored defaults (recommended for day-to-day use) - // - if nosyncBs, nosyncBsSet := os.LookupEnv("LOTUS_CHAIN_BADGERSTORE_DISABLE_FSYNC"); nosyncBsSet { - nosyncBs = strings.ToLower(nosyncBs) - if nosyncBs == "" || nosyncBs == "0" || nosyncBs == "false" || nosyncBs == "no" { - opts.SyncWrites = true - } else { - opts.SyncWrites = false - } + if system.BadgerFsyncDisable { + opts.SyncWrites = false } bs, err := badgerbs.Open(opts) diff --git a/system/io.go b/system/io.go new file mode 100644 index 000000000..5a8306df1 --- /dev/null +++ b/system/io.go @@ -0,0 +1,25 @@ +package system + +import ( + "os" + "strings" +) + +var BadgerFsyncDisable bool + +func init() { + // + // Tri-state environment variable LOTUS_CHAIN_BADGERSTORE_DISABLE_FSYNC + // - unset == the default (currently fsync enabled) + // - set with a false-y value == fsync enabled no matter what a future default is + // - set with any other value == fsync is disabled ignored defaults (recommended for day-to-day use) + // + if nosyncBs, nosyncBsSet := os.LookupEnv("LOTUS_CHAIN_BADGERSTORE_DISABLE_FSYNC"); nosyncBsSet { + nosyncBs = strings.ToLower(nosyncBs) + if nosyncBs == "" || nosyncBs == "0" || nosyncBs == "false" || nosyncBs == "no" { + BadgerFsyncDisable = false + } else { + BadgerFsyncDisable = true + } + } +}