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

BREAKING(flags) feat(bulk): Allow encrypted input with unencrypted output in bulk. #6541

Merged
merged 6 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions dgraph/cmd/bulk/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type options struct {
NewUids bool
ClientDir string
Encrypted bool
EncryptedOut bool

MapShards int
ReduceShards int
Expand Down
7 changes: 6 additions & 1 deletion dgraph/cmd/bulk/reduce.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,17 @@ func (r *reducer) createBadgerInternal(dir string, compression bool) *badger.DB
}
}

key := r.opt.EncryptionKey
if !r.opt.EncryptedOut {
key = nil
}

opt := badger.DefaultOptions(dir).
WithSyncWrites(false).
WithTableLoadingMode(bo.MemoryMap).
WithValueThreshold(1 << 10 /* 1 KB */).
WithLogger(nil).
WithEncryptionKey(r.opt.EncryptionKey).
WithEncryptionKey(key).
WithBlockCacheSize(r.opt.BlockCacheSize).
WithIndexCacheSize(r.opt.IndexCacheSize)

Expand Down
11 changes: 11 additions & 0 deletions dgraph/cmd/bulk/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func init() {
"Specify file format (rdf or json) instead of getting it from filename.")
flag.Bool("encrypted", false,
"Flag to indicate whether schema and data files are encrypted.")
flag.Bool("encrypted_out", false,
"Flag to indicate whether to encrypt the output.")
flag.String("out", defaultOutDir,
"Location to write the final dgraph data directories.")
flag.Bool("replace_out", false,
Expand Down Expand Up @@ -122,6 +124,7 @@ func run() {
SchemaFile: Bulk.Conf.GetString("schema"),
GqlSchemaFile: Bulk.Conf.GetString("graphql_schema"),
Encrypted: Bulk.Conf.GetBool("encrypted"),
EncryptedOut: Bulk.Conf.GetBool("encrypted_out"),
OutDir: Bulk.Conf.GetString("out"),
ReplaceOutDir: Bulk.Conf.GetBool("replace_out"),
TmpDir: Bulk.Conf.GetString("tmp"),
Expand Down Expand Up @@ -166,10 +169,18 @@ func run() {
fmt.Printf("unable to read key %v", err)
return
}
if len(opt.EncryptionKey) > 0 && !opt.Encrypted && !opt.EncryptedOut {
opt.Encrypted = true
opt.EncryptedOut = true
}
if opt.Encrypted && len(opt.EncryptionKey) == 0 {
fmt.Printf("Must use --encryption_key_file or vault option(s) with --encrypted option.\n")
os.Exit(1)
}
if opt.EncryptedOut && len(opt.EncryptionKey) == 0 {
fmt.Printf("Must use --encryption_key_file or vault option(s) with --encrypted_out option.\n")
os.Exit(1)
}
if opt.SchemaFile == "" {
fmt.Fprint(os.Stderr, "Schema file must be specified.\n")
os.Exit(1)
Expand Down