Skip to content

Commit ea932a8

Browse files
authored
feat(cmd/flatten): Add encryption-key-file flag. (dgraph-io#1560)
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.
1 parent 2b9b6e9 commit ea932a8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

badger/cmd/flatten.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ This command would compact all the LSM tables into one level.
3333
RunE: flatten,
3434
}
3535

36+
var keyPath string
3637
var numWorkers int
3738

3839
func init() {
@@ -43,17 +44,26 @@ func init() {
4344
flattenCmd.Flags().IntVarP(&numVersions, "num_versions", "", 1,
4445
"Option to configure the maximum number of versions per key. "+
4546
"Values <= 0 will be considered to have the max number of versions.")
47+
flattenCmd.Flags().StringVar(&keyPath, "encryption-key-file", "",
48+
"Path of the encryption key file.")
4649
}
4750

4851
func flatten(cmd *cobra.Command, args []string) error {
4952
if numVersions <= 0 {
5053
// Keep all versions.
5154
numVersions = math.MaxInt32
5255
}
56+
encKey, err := getKey(keyPath)
57+
if err != nil {
58+
return err
59+
}
5360
opt := badger.DefaultOptions(sstDir).
5461
WithValueDir(vlogDir).
5562
WithNumVersionsToKeep(numVersions).
56-
WithNumCompactors(0)
63+
WithNumCompactors(0).
64+
WithBlockCacheSize(100 << 20).
65+
WithIndexCacheSize(200 << 20).
66+
WithEncryptionKey(encKey)
5767
fmt.Printf("Opening badger with options = %+v\n", opt)
5868
db, err := badger.Open(opt)
5969
if err != nil {

0 commit comments

Comments
 (0)