From 0d3600c5b1c45eb95001311de9fe84356b3e9e23 Mon Sep 17 00:00:00 2001 From: 3pCode Date: Thu, 18 Oct 2018 22:27:16 -0400 Subject: [PATCH 1/3] Fix bug when deleted a reinserted quad. --- graph/graphtest/graphtest.go | 20 ++++++++++++++++++++ graph/kv/indexing.go | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/graph/graphtest/graphtest.go b/graph/graphtest/graphtest.go index 6b817dcff..4a0a61a02 100644 --- a/graph/graphtest/graphtest.go +++ b/graph/graphtest/graphtest.go @@ -55,6 +55,7 @@ var graphTests = []struct { {"iterators and next result order", TestIteratorsAndNextResultOrderA}, {"compare typed values", TestCompareTypedValues}, {"schema", TestSchema}, + {"delete reinserted", TestDeleteReinserted}, } func TestAll(t *testing.T, gen testutil.DatabaseFunc, conf *Config) { @@ -1091,3 +1092,22 @@ func TestSchema(t testing.TB, gen testutil.DatabaseFunc, conf *Config) { require.NoError(t, err) require.Equal(t, p, p2) } + +func TestDeleteReinserted(t testing.TB, gen testutil.DatabaseFunc, _ *Config) { + qs, opts, closer := gen(t) + defer closer() + + w := testutil.MakeWriter(t, qs, opts, MakeQuadSet()...) + + err := w.AddQuadSet([]quad.Quad{ + quad.Make("", "", "Feeling happy", nil), + quad.Make("", "", "", nil), + }) + + for i := 0; i < 2; i++ { + w.AddQuad(quad.Make("", "", "", nil)) + err = w.RemoveQuad(quad.Make("", "", "", nil)) + assert.Nil(t, err, "Remove quad failed") + } + +} diff --git a/graph/kv/indexing.go b/graph/kv/indexing.go index e827a0484..3120c13fe 100644 --- a/graph/kv/indexing.go +++ b/graph/kv/indexing.go @@ -675,9 +675,10 @@ func (qs *QuadStore) hasPrimitive(ctx context.Context, tx BucketTx, p *proto.Pri if !get && unique { return p, nil } - for _, x := range options { + for ix := len(options) - 1; ix >= 0; ix-- { // TODO: batch - prim, err := qs.getPrimitiveFromLog(ctx, tx, x) + prim, err := qs.getPrimitiveFromLog(ctx, tx, options[ix]) + if err != nil { return nil, err } From cac3830c1605045fbb33069b30d804cc2af67716 Mon Sep 17 00:00:00 2001 From: 3pCode Date: Sat, 20 Oct 2018 20:05:43 -0400 Subject: [PATCH 2/3] Update authors and contributors --- AUTHORS | 1 + CONTRIBUTORS | 1 + 2 files changed, 2 insertions(+) diff --git a/AUTHORS b/AUTHORS index cf864cc0f..4835189a4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -18,6 +18,7 @@ Jay Graves Jeremy Jay Jørgen Teunis Pius Uzamere +QlikTech International AB Robert Daniel Kortschak Robert Melton Stefan Koshiw diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 802478604..6ad98d7a1 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -20,6 +20,7 @@ Pius Uzamere Robert Daniel Kortschak Robert Melton Stefan Koshiw +Tad Adams Timothy Armstrong Tyler Gibbons Yannic Bonenberger From 36d239e2866d17b0096c99e2f3414f1f706373d8 Mon Sep 17 00:00:00 2001 From: 3pCode Date: Sun, 21 Oct 2018 07:06:48 -0400 Subject: [PATCH 3/3] update test to check all return codes, update variable name. --- graph/graphtest/graphtest.go | 6 ++++-- graph/kv/indexing.go | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/graph/graphtest/graphtest.go b/graph/graphtest/graphtest.go index 4a0a61a02..007f3c5ad 100644 --- a/graph/graphtest/graphtest.go +++ b/graph/graphtest/graphtest.go @@ -1103,11 +1103,13 @@ func TestDeleteReinserted(t testing.TB, gen testutil.DatabaseFunc, _ *Config) { quad.Make("", "", "Feeling happy", nil), quad.Make("", "", "", nil), }) + require.NoError(t, err, "Add quadset failed") for i := 0; i < 2; i++ { - w.AddQuad(quad.Make("", "", "", nil)) + err = w.AddQuad(quad.Make("", "", "", nil)) + require.NoError(t, err, "Add quad failed") err = w.RemoveQuad(quad.Make("", "", "", nil)) - assert.Nil(t, err, "Remove quad failed") + require.NoError(t, err, "Remove quad failed") } } diff --git a/graph/kv/indexing.go b/graph/kv/indexing.go index 3120c13fe..72d94254f 100644 --- a/graph/kv/indexing.go +++ b/graph/kv/indexing.go @@ -675,9 +675,9 @@ func (qs *QuadStore) hasPrimitive(ctx context.Context, tx BucketTx, p *proto.Pri if !get && unique { return p, nil } - for ix := len(options) - 1; ix >= 0; ix-- { + for i := len(options) - 1; i >= 0; i-- { // TODO: batch - prim, err := qs.getPrimitiveFromLog(ctx, tx, options[ix]) + prim, err := qs.getPrimitiveFromLog(ctx, tx, options[i]) if err != nil { return nil, err