MCPcopy Create free account
hub / github.com/dgraph-io/dgraph / mapStage

Method mapStage

dgraph/cmd/bulk/loader.go:354–445  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

352}
353
354func (ld *loader) mapStage() {
355 ld.prog.setPhase(mapPhase)
356 var db *badger.DB
357 if len(ld.opt.ClientDir) > 0 {
358 x.Check(os.MkdirAll(ld.opt.ClientDir, 0700))
359
360 var err error
361 db, err = badger.Open(badger.DefaultOptions(ld.opt.ClientDir))
362 x.Checkf(err, "Error while creating badger KV posting store")
363 }
364 ld.xids = xidmap.New(xidmap.XidMapOptions{
365 UidAssigner: ld.zero,
366 DB: db,
367 DgClient: ld.dg,
368 Dir: filepath.Join(ld.opt.TmpDir, bufferDir),
369 })
370
371 fs := filestore.NewFileStore(ld.opt.DataFiles)
372
373 files := fs.FindDataFiles(ld.opt.DataFiles, []string{".rdf", ".rdf.gz", ".json", ".json.gz"})
374 if len(files) == 0 {
375 fmt.Printf("No data files found in %s.\n", ld.opt.DataFiles)
376 os.Exit(1)
377 }
378
379 // Because mappers must handle chunks that may be from different input files, they must all
380 // assume the same data format, either RDF or JSON. Use the one specified by the user or by
381 // the first load file.
382 loadType := chunker.DataFormat(files[0], ld.opt.DataFormat)
383 if loadType == chunker.UnknownFormat {
384 // Dont't try to detect JSON input in bulk loader.
385 fmt.Printf("Need --format=rdf or --format=json to load %s", files[0])
386 os.Exit(1)
387 }
388
389 var mapperWg sync.WaitGroup
390 mapperWg.Add(len(ld.mappers))
391 for _, m := range ld.mappers {
392 go func(m *mapper) {
393 m.run(loadType)
394 mapperWg.Done()
395 }(m)
396 }
397
398 // This is the main map loop.
399 thr := y.NewThrottle(ld.opt.NumGoroutines)
400 for i, file := range files {
401 x.Check(thr.Do())
402 fmt.Printf("Processing file (%d out of %d): %s\n", i+1, len(files), file)
403
404 go func(file string) {
405 defer thr.Done(nil)
406
407 key := ld.opt.EncryptionKey
408 if !ld.opt.Encrypted {
409 key = nil
410 }
411 r, cleanup := fs.ChunkReader(file, key)

Callers 1

RunBulkLoaderFunction · 0.80

Calls 15

FindDataFilesMethod · 0.95
ChunkReaderMethod · 0.95
ChunkMethod · 0.95
processGqlSchemaMethod · 0.95
CheckFunction · 0.92
CheckfFunction · 0.92
NewFunction · 0.92
NewFileStoreFunction · 0.92
DataFormatFunction · 0.92
NewChunkerFunction · 0.92
cleanupFunction · 0.85
setPhaseMethod · 0.80

Tested by

no test coverage detected