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

release/v2.2007 - fix(flatten): Add --num_versions flag (#1518) #1520

Merged
merged 1 commit into from
Sep 27, 2020
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
17 changes: 15 additions & 2 deletions badger/cmd/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package cmd

import (
"fmt"
"math"

"github.com/dgraph-io/badger/v2"
"github.com/spf13/cobra"
)
Expand All @@ -37,13 +40,23 @@ func init() {
flattenCmd.Flags().IntVarP(&numWorkers, "num-workers", "w", 1,
"Number of concurrent compactors to run. More compactors would use more"+
" server resources to potentially achieve faster compactions.")
flattenCmd.Flags().IntVarP(&numVersions, "num_versions", "", 1,
"Option to configure the maximum number of versions per key. "+
"Values <= 0 will be considered to have the max number of versions.")
}

func flatten(cmd *cobra.Command, args []string) error {
db, err := badger.Open(badger.DefaultOptions(sstDir).
if numVersions <= 0 {
// Keep all versions.
numVersions = math.MaxInt32
}
opt := badger.DefaultOptions(sstDir).
WithValueDir(vlogDir).
WithTruncate(truncate).
WithNumCompactors(0))
WithNumVersionsToKeep(numVersions).
WithNumCompactors(0)
fmt.Printf("Opening badger with options = %+v\n", opt)
db, err := badger.Open(opt)
if err != nil {
return err
}
Expand Down