Skip to content

Commit

Permalink
Add support for xidmap in bulkloader (#5090)
Browse files Browse the repository at this point in the history
Add support for xidmap in bulkloader
  • Loading branch information
all-seeing-code authored Apr 8, 2020
1 parent 98769a6 commit 73825c4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 13 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,9 @@ func (ld *loader) mapStage() {
ld.mappers[i] = nil
}
x.Check(ld.xids.Flush())
if db != nil {
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

0 comments on commit 73825c4

Please sign in to comment.