From 287049ea83a2bfee3f3a83e1368b2f3719996fe1 Mon Sep 17 00:00:00 2001 From: missinglink Date: Wed, 1 Feb 2023 14:26:24 +0100 Subject: [PATCH] compact: add cli flags to enable NoSync option Signed-off-by: missinglink --- cmd/bbolt/main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/bbolt/main.go b/cmd/bbolt/main.go index f76cd82c4..38be33de3 100644 --- a/cmd/bbolt/main.go +++ b/cmd/bbolt/main.go @@ -1572,6 +1572,7 @@ type compactCommand struct { SrcPath string DstPath string TxMaxSize int64 + DstNoSync bool } // newCompactCommand returns a CompactCommand. @@ -1588,6 +1589,7 @@ func (cmd *compactCommand) Run(args ...string) (err error) { fs.SetOutput(io.Discard) fs.StringVar(&cmd.DstPath, "o", "", "") fs.Int64Var(&cmd.TxMaxSize, "tx-max-size", 65536, "") + fs.BoolVar(&cmd.DstNoSync, "no-sync", false, "") if err := fs.Parse(args); err == flag.ErrHelp { fmt.Fprintln(cmd.Stderr, cmd.Usage()) return ErrUsage @@ -1620,7 +1622,7 @@ func (cmd *compactCommand) Run(args ...string) (err error) { defer src.Close() // Open destination database. - dst, err := bolt.Open(cmd.DstPath, fi.Mode(), nil) + dst, err := bolt.Open(cmd.DstPath, fi.Mode(), &bolt.Options{NoSync: cmd.DstNoSync}) if err != nil { return err } @@ -1658,6 +1660,10 @@ Additional options include: -tx-max-size NUM Specifies the maximum size of individual transactions. Defaults to 64KB. + + -no-sync BOOL + Skip fsync() calls after each commit (fast but unsafe) + Defaults to false `, "\n") }