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

Fix StreamWriter usage in bulk loader #3635

Merged
merged 2 commits into from
Jul 5, 2019
Merged
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
38 changes: 23 additions & 15 deletions dgraph/cmd/bulk/reduce.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,34 +139,42 @@ func (r *reducer) encodeAndWrite(
writer *badger.StreamWriter, entryCh chan []*pb.MapEntry, closer *y.Closer) {
defer closer.Done()

preds := make(map[string]uint32)

var listSize int
list := &bpb.KVList{}

preds := make(map[string]uint32)
setStreamId := func(kv *bpb.KV) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var setStreamId should be setStreamID (from golint)

pk := x.Parse(kv.Key)
x.AssertTrue(len(pk.Attr) > 0)

// We don't need to consider the data prefix, count prefix, etc. because each predicate
// contains sorted keys, the way they are produced.
streamId := preds[pk.Attr]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var streamId should be streamID (from golint)

if streamId == 0 {
streamId = atomic.AddUint32(&r.streamId, 1)
preds[pk.Attr] = streamId
}
// TODO: Having many stream ids can cause memory issues with StreamWriter. So, we
// should build a way in StreamWriter to indicate that the stream is over, so the
// table for that stream can be flushed and memory released.
kv.StreamId = streamId
}

for batch := range entryCh {
listSize += r.toList(batch, list)
if listSize > 4<<20 {
for _, kv := range list.Kv {
pk := x.Parse(kv.Key)
if len(pk.Attr) == 0 {
continue
}
streamId := preds[pk.Attr]
if streamId == 0 {
streamId = atomic.AddUint32(&r.streamId, 1)
preds[pk.Attr] = streamId
}
// TODO: Having many stream ids can cause memory issues with StreamWriter. So, we
// should build a way in StreamWriter to indicate that the stream is over, so the
// table for that stream can be flushed and memory released.
kv.StreamId = streamId
setStreamId(kv)
}
x.Check(writer.Write(list))
list = &bpb.KVList{}
listSize = 0
}
}
if len(list.Kv) > 0 {
for _, kv := range list.Kv {
setStreamId(kv)
}
x.Check(writer.Write(list))
}
}
Expand Down