Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compact: add cli flag to control NoSync option #290

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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