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

chore: Replace panic in live loader with errors #7798

Merged
merged 1 commit into from
May 10, 2021
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
18 changes: 11 additions & 7 deletions dgraph/cmd/live/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func generateQuery(node, predicate, xid string) string {
return sb.String()
}

func (l *loader) upsertUids(nqs []*api.NQuad) {
func (l *loader) upsertUids(nqs []*api.NQuad) error {
// We form upsertPredicate query for each of the ids we saw in the request, along with
// adding the corresponding xid to that uid. The mutation we added is only useful if the
// uid doesn't exists.
Expand Down Expand Up @@ -375,7 +375,7 @@ func (l *loader) upsertUids(nqs []*api.NQuad) {
}

if len(mutations) == 0 {
return
return nil
}

query.WriteRune('}')
Expand All @@ -388,7 +388,7 @@ func (l *loader) upsertUids(nqs []*api.NQuad) {
})

if err != nil {
panic(err)
return err
}

type dResult struct {
Expand All @@ -398,15 +398,15 @@ func (l *loader) upsertUids(nqs []*api.NQuad) {
var result map[string][]dResult
err = json.Unmarshal(resp.GetJson(), &result)
if err != nil {
panic(err)
return err
}

for xid, idx := range ids {
// xid already exist in dgraph
if val, ok := result[idx]; ok && len(val) > 0 {
uid, err := strconv.ParseUint(val[0].Uid, 0, 64)
if err != nil {
panic(err)
return err
}

l.alloc.SetUid(xid, uid)
Expand All @@ -417,13 +417,15 @@ func (l *loader) upsertUids(nqs []*api.NQuad) {
if val, ok := resp.GetUids()[generateUidFunc(idx)]; ok {
uid, err := strconv.ParseUint(val, 0, 64)
if err != nil {
panic(err)
return err
}

l.alloc.SetUid(xid, uid)
continue
}
}

return nil
}

// allocateUids looks for the maximum uid value in the given NQuads and bumps the
Expand Down Expand Up @@ -546,7 +548,9 @@ func (l *loader) processLoadFile(ctx context.Context, rd *bufio.Reader, ck chunk
// figure out its processsing.
// Currently, this option works with data loading in the logged-in namespace.
// TODO(Naman): Add a test for a case when it works and when it doesn't.
l.upsertUids(nqs)
if err = l.upsertUids(nqs); err != nil {
return
}
}

for _, nq := range nqs {
Expand Down