Skip to content

Commit

Permalink
fixed another test
Browse files Browse the repository at this point in the history
  • Loading branch information
harshil-goel committed Jan 29, 2025
1 parent 0f16d38 commit d15410e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion posting/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (txn *Txn) addReverseAndCountMutation(ctx context.Context, t *pb.DirectedEd
Facets: t.Facets,
}

cp, err := txn.addReverseMutationHelper(ctx, plist, hasCountIndex, edge)
cp, err := txn.addReverseMutationHelper(ctx, plist, true, edge)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion posting/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ func (l *List) addMutationInternal(ctx context.Context, txn *Txn, t *pb.Directed
isSingleUidUpdate := ok && !pred.GetList() && pred.GetValueType() == pb.Posting_UID &&
pk.IsData() && mpost.Op != Del && mpost.PostingType == pb.Posting_REF

if err != l.updateMutationLayer(mpost, isSingleUidUpdate, pred.GetCount() && pk.IsData()) {
if err != l.updateMutationLayer(mpost, isSingleUidUpdate, pred.GetCount() && (pk.IsData() || pk.IsReverse())) {
return errors.Wrapf(err, "cannot update mutation layer of key %s with value %+v",
hex.EncodeToString(l.key), mpost)
}
Expand Down
61 changes: 60 additions & 1 deletion worker/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,65 @@ func writePostingListToDisk(kvs []*bpb.KV) error {
return writer.Flush()
}

func TestMultipleTxnListCount(t *testing.T) {
dir, err := os.MkdirTemp("", "storetest_")
x.Check(err)
defer os.RemoveAll(dir)

opt := badger.DefaultOptions(dir)
ps, err := badger.OpenManaged(opt)
x.Check(err)
pstore = ps
posting.Init(ps, 0, false)
Init(ps)
err = schema.ParseBytes([]byte("scalarPredicateCount3: [uid] @count ."), 1)
require.NoError(t, err)

ctx := context.Background()
attr := x.GalaxyAttr("scalarPredicateCount3")

runM := func(startTs, commitTs uint64, edges []*pb.DirectedEdge) {
txn := posting.Oracle().RegisterStartTs(startTs)
for _, edge := range edges {
x.Check(runMutation(ctx, edge, txn))
}
txn.Update()
writer := posting.NewTxnWriter(pstore)
require.NoError(t, txn.CommitToDisk(writer, commitTs))
require.NoError(t, writer.Flush())
txn.UpdateCachedKeys(commitTs)
}

runM(9, 11, []*pb.DirectedEdge{{
ValueId: 3,
ValueType: pb.Posting_UID,
Attr: attr,
Entity: 1,
Op: pb.DirectedEdge_SET,
}, {
ValueId: 2,
ValueType: pb.Posting_UID,
Attr: attr,
Entity: 1,
Op: pb.DirectedEdge_SET,
}})

txn := posting.Oracle().RegisterStartTs(13)
key := x.CountKey(attr, 1, false)
l, err := txn.Get(key)
require.Nil(t, err)
uids, err := l.Uids(posting.ListOptions{ReadTs: 13})
require.Nil(t, err)
require.Equal(t, 0, len(uids.Uids))

key = x.CountKey(attr, 2, false)
l, err = txn.Get(key)
require.Nil(t, err)
uids, err = l.Uids(posting.ListOptions{ReadTs: 13})
require.Nil(t, err)
require.Equal(t, 1, len(uids.Uids))
}

func TestScalarPredicateRevCount(t *testing.T) {
dir, err := os.MkdirTemp("", "storetest_")
x.Check(err)
Expand Down Expand Up @@ -110,7 +169,7 @@ func TestScalarPredicateRevCount(t *testing.T) {
}})

txn := posting.Oracle().RegisterStartTs(13)
key := x.CountKey(attr, 1, false)
key := x.DataKey(attr, 1)
l, err := txn.Get(key)

Check failure on line 173 in worker/sort_test.go

View check run for this annotation

Trunk.io / Trunk Check

golangci-lint(ineffassign)

[new] ineffectual assignment to err
l.RLock()
require.Equal(t, 0, l.GetLength(13))
Expand Down

0 comments on commit d15410e

Please sign in to comment.