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

Added support for xidmap in bulkloader #5090

Merged
merged 6 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
12 changes: 11 additions & 1 deletion dgraph/cmd/bulk/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type options struct {
IgnoreErrors bool
CustomTokenizers string
NewUids bool
ClientDir string

MapShards int
ReduceShards int
Expand Down Expand Up @@ -161,7 +162,15 @@ func readSchema(filename string) *schema.ParsedSchema {

func (ld *loader) mapStage() {
ld.prog.setPhase(mapPhase)
ld.xids = xidmap.New(ld.zero, nil)
var db *badger.DB
if len(ld.opt.ClientDir) > 0 {
x.Check(os.MkdirAll(ld.opt.ClientDir, 0700))

var err error
db, err = badger.Open(badger.DefaultOptions(ld.opt.ClientDir))
x.Checkf(err, "Error while creating badger KV posting store")
}
ld.xids = xidmap.New(ld.zero, db)

files := x.FindDataFiles(ld.opt.DataFiles, []string{".rdf", ".rdf.gz", ".json", ".json.gz"})
if len(files) == 0 {
Expand Down Expand Up @@ -224,6 +233,7 @@ func (ld *loader) mapStage() {
ld.mappers[i] = nil
}
x.Check(ld.xids.Flush())
x.Check(db.Close())
ld.xids = nil
}

Expand Down
2 changes: 2 additions & 0 deletions dgraph/cmd/bulk/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func init() {
flag.Bool("version", false, "Prints the version of Dgraph Bulk Loader.")
flag.BoolP("store_xids", "x", false, "Generate an xid edge for each node.")
flag.StringP("zero", "z", "localhost:5080", "gRPC address for Dgraph zero")
flag.String("xidmap", "", "Directory to store xid to uid mapping")
// TODO: Potentially move http server to main.
flag.String("http", "localhost:8080",
"Address to serve http (pprof).")
Expand Down Expand Up @@ -129,6 +130,7 @@ func run() {
ReduceShards: Bulk.Conf.GetInt("reduce_shards"),
CustomTokenizers: Bulk.Conf.GetString("custom_tokenizers"),
NewUids: Bulk.Conf.GetBool("new_uids"),
ClientDir: Bulk.Conf.GetString("xidmap"),

BadgerKeyFile: Bulk.Conf.GetString("encryption_key_file"),
BadgerCompressionLevel: Bulk.Conf.GetInt("badger.compression_level"),
Expand Down