Skip to content

Commit 136f122

Browse files
author
Li
committed
fix(core): fix value loss when reverse predicate is updated and deleted multiple times in one DQL txn
1 parent e648e77 commit 136f122

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

posting/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func (mm *MutableLayer) insertPosting(mpost *pb.Posting, hasCountIndex bool) {
372372
}
373373
res := mm.currentEntries.Postings[:postIndex]
374374
if postIndex+1 <= len(mm.currentEntries.Postings) {
375-
mm.currentEntries.Postings = append(res,
375+
res = append(res,
376376
mm.currentEntries.Postings[(postIndex+1):]...)
377377
}
378378
mm.currentUids = nil

worker/mutation_unit_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,68 @@ func TestReverseEdge(t *testing.T) {
5858
require.Equal(t, c, 0)
5959
}
6060

61+
func TestReverseEdgeSetDel(t *testing.T) {
62+
dir, err := os.MkdirTemp("", "storetest_")
63+
x.Check(err)
64+
defer os.RemoveAll(dir)
65+
66+
opt := badger.DefaultOptions(dir)
67+
ps, err := badger.OpenManaged(opt)
68+
x.Check(err)
69+
pstore = ps
70+
// Not using posting list cache
71+
posting.Init(ps, 0, false)
72+
Init(ps)
73+
err = schema.ParseBytes([]byte("revc: [uid] @reverse @count ."), 1)
74+
require.NoError(t, err)
75+
76+
ctx := context.Background()
77+
txn := posting.Oracle().RegisterStartTs(5)
78+
attr := x.AttrInRootNamespace("revc")
79+
80+
edgeDel := &pb.DirectedEdge{
81+
ValueId: 2,
82+
Attr: attr,
83+
Entity: 3,
84+
Op: pb.DirectedEdge_DEL,
85+
}
86+
87+
edgeSet1 := &pb.DirectedEdge{
88+
ValueId: 2,
89+
Attr: attr,
90+
Entity: 1,
91+
Op: pb.DirectedEdge_SET,
92+
}
93+
94+
edgeSet2 := &pb.DirectedEdge{
95+
ValueId: 2,
96+
Attr: attr,
97+
Entity: 3,
98+
Op: pb.DirectedEdge_SET,
99+
}
100+
101+
102+
edgeSet3 := &pb.DirectedEdge{
103+
ValueId: 2,
104+
Attr: attr,
105+
Entity: 4,
106+
Op: pb.DirectedEdge_SET,
107+
}
108+
109+
110+
x.Check(runMutation(ctx, edgeSet1, txn))
111+
x.Check(runMutation(ctx, edgeSet2, txn))
112+
x.Check(runMutation(ctx, edgeSet3, txn))
113+
x.Check(runMutation(ctx, edgeDel, txn))
114+
115+
pl, err := txn.Get(x.ReverseKey(attr, 2))
116+
require.NoError(t, err)
117+
pl.RLock()
118+
c := pl.GetLength(5)
119+
pl.RUnlock()
120+
require.Equal(t, 2, c)
121+
}
122+
61123
func TestConvertEdgeType(t *testing.T) {
62124
var testEdges = []struct {
63125
input *pb.DirectedEdge

0 commit comments

Comments
 (0)