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

Change the mapper output directory from $TMP/shards to $TMP/map_output #3960

Merged
merged 2 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion dgraph/cmd/bulk/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (m *mapper) openOutputFile(shardIdx int) (*os.File, error) {
fileNum := atomic.AddUint32(&m.mapFileId, 1)
filename := filepath.Join(
m.opt.TmpDir,
"shards",
mapShardDir,
fmt.Sprintf("%03d", shardIdx),
fmt.Sprintf("%06d.map.gz", fileNum),
)
Expand Down
15 changes: 10 additions & 5 deletions dgraph/cmd/bulk/merge_shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ import (
"github.com/dgraph-io/dgraph/x"
)

const (
mapShardDir = "map_output"
reduceShardDir = "shards"
)

func mergeMapShardsIntoReduceShards(opt options) {
mapShards := shardDirs(opt.TmpDir)
mapShards := shardDirs(filepath.Join(opt.TmpDir, mapShardDir))

var reduceShards []string
for i := 0; i < opt.ReduceShards; i++ {
shardDir := filepath.Join(opt.TmpDir, "shards", fmt.Sprintf("shard_%d", i))
shardDir := filepath.Join(opt.TmpDir, reduceShardDir, fmt.Sprintf("shard_%d", i))
x.Check(os.MkdirAll(shardDir, 0755))
reduceShards = append(reduceShards, shardDir)
}
Expand All @@ -47,14 +52,14 @@ func mergeMapShardsIntoReduceShards(opt options) {
}
}

func shardDirs(tmpDir string) []string {
dir, err := os.Open(filepath.Join(tmpDir, "shards"))
func shardDirs(d string) []string {
dir, err := os.Open(d)
x.Check(err)
shards, err := dir.Readdirnames(0)
x.Check(err)
dir.Close()
for i, shard := range shards {
shards[i] = filepath.Join(tmpDir, "shards", shard)
shards[i] = filepath.Join(d, shard)
}

// Allow largest shards to be shuffled first.
Expand Down
3 changes: 2 additions & 1 deletion dgraph/cmd/bulk/reduce.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"io"
"log"
"os"
"path/filepath"
"sync/atomic"

"github.com/dgraph-io/badger"
Expand All @@ -45,7 +46,7 @@ type reducer struct {
}

func (r *reducer) run() error {
dirs := shardDirs(r.opt.TmpDir)
dirs := shardDirs(filepath.Join(r.opt.TmpDir, reduceShardDir))
x.AssertTrue(len(dirs) == r.opt.ReduceShards)
x.AssertTrue(len(r.opt.shardOutputDirs) == r.opt.ReduceShards)

Expand Down