From 7accddd0a6764b44e190b13fffccfe18799eb8b5 Mon Sep 17 00:00:00 2001 From: Javier Alvarado Date: Mon, 11 Feb 2019 11:48:00 -0800 Subject: [PATCH 1/4] Export with the actual UIDs instead of blanks. --- worker/export.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/worker/export.go b/worker/export.go index 9d9c7c76896..d5c8d1a2dba 100644 --- a/worker/export.go +++ b/worker/export.go @@ -75,7 +75,7 @@ func toRDF(pl *posting.List, prefix string, readTs uint64) (*bpb.KVList, error) err := pl.Iterate(readTs, 0, func(p *pb.Posting) error { buf.WriteString(prefix) if p.PostingType == pb.Posting_REF { - buf.WriteString(fmt.Sprintf("<_:uid%x>", p.Uid)) + buf.WriteString(fmt.Sprintf("<0x%04x>", p.Uid)) } else { // Value posting @@ -313,7 +313,7 @@ func export(ctx context.Context, in *pb.ExportRequest) error { return toSchema(pk.Attr, update) case pk.IsData(): - prefix := fmt.Sprintf("<_:uid%x> <%s> ", pk.Uid, pk.Attr) + prefix := fmt.Sprintf("<0x%04x> <%s> ", pk.Uid, pk.Attr) pl, err := posting.ReadPostingList(key, itr) if err != nil { return nil, err From 9dde2a6cfd487a84aed53a4606b3b1cfa2a7df0c Mon Sep 17 00:00:00 2001 From: Javier Alvarado Date: Mon, 11 Feb 2019 11:48:41 -0800 Subject: [PATCH 2/4] Fix awkwardly punctuated error message. --- dgraph/cmd/live/batch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dgraph/cmd/live/batch.go b/dgraph/cmd/live/batch.go index 5ef92ba9209..44735c76c65 100644 --- a/dgraph/cmd/live/batch.go +++ b/dgraph/cmd/live/batch.go @@ -137,7 +137,7 @@ func handleError(err error) { fmt.Printf("Server is overloaded. Will retry after %s.", dur.Round(time.Minute)) time.Sleep(dur) case err != y.ErrAborted && err != y.ErrConflict: - fmt.Printf("Error while mutating %v\n", s.Message()) + fmt.Printf("Error while mutating. %v\n", s.Message()) } } From 567af713f85ef4940e59e143c4bd89bba98d7a18 Mon Sep 17 00:00:00 2001 From: Javier Alvarado Date: Mon, 11 Feb 2019 14:09:14 -0800 Subject: [PATCH 3/4] Fix tests assuming _:uid in export. --- systest/loader_test.go | 10 +++++----- worker/export.go | 7 +++++-- worker/export_test.go | 20 ++++++++++---------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/systest/loader_test.go b/systest/loader_test.go index 28341a69e6d..2ba8d363469 100644 --- a/systest/loader_test.go +++ b/systest/loader_test.go @@ -103,11 +103,11 @@ func TestLoaderXidmap(t *testing.T) { t.Fatalf("While trying to sort exported file: %v", err) } - expected = `<_:uid1> "13" . -<_:uid1> <_:uid2711> . -<_:uid1> "Wonderland" . -<_:uid1> "Alice" . -<_:uid2711> "Bob" . + expected = `<0x1> "13" . +<0x1> <0x2711> . +<0x1> "Wonderland" . +<0x1> "Alice" . +<0x2711> "Bob" . ` if string(out) != expected { diff --git a/worker/export.go b/worker/export.go index d5c8d1a2dba..5468b7b095e 100644 --- a/worker/export.go +++ b/worker/export.go @@ -69,13 +69,16 @@ var predNonSpecialChars = unicode.RangeTable{ }, } +// UIDs like 0x1 look weird but 64-bit ones like 0x0000000000000001 are too long. +var uidFmtStr = "<0x%x>" + func toRDF(pl *posting.List, prefix string, readTs uint64) (*bpb.KVList, error) { var buf bytes.Buffer err := pl.Iterate(readTs, 0, func(p *pb.Posting) error { buf.WriteString(prefix) if p.PostingType == pb.Posting_REF { - buf.WriteString(fmt.Sprintf("<0x%04x>", p.Uid)) + buf.WriteString(fmt.Sprintf(uidFmtStr, p.Uid)) } else { // Value posting @@ -313,7 +316,7 @@ func export(ctx context.Context, in *pb.ExportRequest) error { return toSchema(pk.Attr, update) case pk.IsData(): - prefix := fmt.Sprintf("<0x%04x> <%s> ", pk.Uid, pk.Attr) + prefix := fmt.Sprintf(uidFmtStr+" <%s> ", pk.Uid, pk.Attr) pl, err := posting.ReadPostingList(key, itr) if err != nil { return nil, err diff --git a/worker/export_test.go b/worker/export_test.go index 016361c0046..60fbaf74fdd 100644 --- a/worker/export_test.go +++ b/worker/export_test.go @@ -149,22 +149,22 @@ func TestExport(t *testing.T) { for scanner.Scan() { nq, err := rdf.Parse(scanner.Text()) require.NoError(t, err) - require.Contains(t, []string{"_:uid1", "_:uid2", "_:uid3", "_:uid4", "_:uid5"}, nq.Subject) + require.Contains(t, []string{"0x1", "0x2", "0x3", "0x4", "0x5"}, nq.Subject) if nq.ObjectValue != nil { switch nq.Subject { - case "_:uid1", "_:uid2": + case "0x1", "0x2": require.Equal(t, &api.Value{Val: &api.Value_DefaultVal{DefaultVal: "pho\ton"}}, nq.ObjectValue) - case "_:uid3": + case "0x3": require.Equal(t, &api.Value{Val: &api.Value_DefaultVal{DefaultVal: "First Line\nSecondLine"}}, nq.ObjectValue) - case "_:uid4": - case "_:uid5": - require.Equal(t, `<_:uid5> "" .`, scanner.Text()) + case "0x4": + case "0x5": + require.Equal(t, `<0x5> "" .`, scanner.Text()) default: t.Errorf("Unexpected subject: %v", nq.Subject) } - if nq.Subject == "_:uid1" || nq.Subject == "_:uid2" { + if nq.Subject == "_:uid1" || nq.Subject == "0x2" { require.Equal(t, &api.Value{Val: &api.Value_DefaultVal{DefaultVal: "pho\ton"}}, nq.ObjectValue) } @@ -172,14 +172,14 @@ func TestExport(t *testing.T) { // The only objectId we set was uid 5. if nq.ObjectId != "" { - require.Equal(t, "_:uid5", nq.ObjectId) + require.Equal(t, "0x5", nq.ObjectId) } // Test lang. - if nq.Subject == "_:uid2" && nq.Predicate == "name" { + if nq.Subject == "0x2" && nq.Predicate == "name" { require.Equal(t, "en", nq.Lang) } // Test facets. - if nq.Subject == "_:uid4" { + if nq.Subject == "0x4" { require.Equal(t, "age", nq.Facets[0].Key) require.Equal(t, "close", nq.Facets[1].Key) require.Equal(t, "game", nq.Facets[2].Key) From cda6e5a01051457baa9ac1c507d499daf2ec5860 Mon Sep 17 00:00:00 2001 From: Javier Alvarado Date: Mon, 11 Feb 2019 16:13:42 -0800 Subject: [PATCH 4/4] Change period to color in error message. --- dgraph/cmd/live/batch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dgraph/cmd/live/batch.go b/dgraph/cmd/live/batch.go index 44735c76c65..7bbe40a4b6d 100644 --- a/dgraph/cmd/live/batch.go +++ b/dgraph/cmd/live/batch.go @@ -137,7 +137,7 @@ func handleError(err error) { fmt.Printf("Server is overloaded. Will retry after %s.", dur.Round(time.Minute)) time.Sleep(dur) case err != y.ErrAborted && err != y.ErrConflict: - fmt.Printf("Error while mutating. %v\n", s.Message()) + fmt.Printf("Error while mutating: %v\n", s.Message()) } }