Skip to content

Commit

Permalink
feat(cmd/flatten): Add encryption-key-file flag. (#1560)
Browse files Browse the repository at this point in the history
Add an --encryption-key-file flag to the badger flatten tool to support encrypted databases.

Changes:

* Add --encryption-key-file flag
* Set block and index cache sizes to fix panic when running flatten.
  • Loading branch information
danielmai authored Oct 13, 2020
1 parent 2b9b6e9 commit ea932a8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion badger/cmd/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This command would compact all the LSM tables into one level.
RunE: flatten,
}

var keyPath string
var numWorkers int

func init() {
Expand All @@ -43,17 +44,26 @@ func init() {
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.")
flattenCmd.Flags().StringVar(&keyPath, "encryption-key-file", "",
"Path of the encryption key file.")
}

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

0 comments on commit ea932a8

Please sign in to comment.