compact: add cli flags to enable NoSync option

Signed-off-by: missinglink <insomnia@rcpt.at>
pull/403/head
missinglink 2023-02-01 14:26:24 +01:00 committed by Benjamin Wang
parent 8f4a7e1f92
commit 287049ea83
1 changed files with 7 additions and 1 deletions

View File

@ -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")
}