Skip to content

Commit

Permalink
compact: add cli flags to enable NoSync option
Browse files Browse the repository at this point in the history
Signed-off-by: missinglink <insomnia@rcpt.at>
  • Loading branch information
missinglink authored and ahrtr committed Feb 2, 2023
1 parent 8f4a7e1 commit 287049e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/bbolt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,7 @@ type compactCommand struct {
SrcPath string
DstPath string
TxMaxSize int64
DstNoSync bool
}

// newCompactCommand returns a CompactCommand.
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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")
}

Expand Down

0 comments on commit 287049e

Please sign in to comment.