Skip to content

Use txn.Get in addReverseMutation #3874

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

Merged
merged 2 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
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
49 changes: 49 additions & 0 deletions dgraph/cmd/alpha/upsert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1422,3 +1422,52 @@ upsert {
require.NotContains(t, res, "San Francisco")
require.NotContains(t, res, "Fuller Street, SF")
}

func TestDeleteCountIndex(t *testing.T) {
require.NoError(t, dropAll())
require.NoError(t, alterSchema(`
<game_answer>: uid @count @reverse .
<name>: int @index(int) .`))

m1 := `
{
set {
_:1 <game_answer> _:2 .
_:1 <name> "1" .
_:2 <game_answer> _:3 .
_:2 <name> "2" .
_:4 <game_answer> _:2 .
_:3 <name> "3" .
_:4 <name> "4" .
}
}`

_, _, _, err := mutationWithTs(m1, "application/rdf", false, true, 0)
require.NoError(t, err)

m2 := `
upsert {
query {
u3 as var(func: eq(name, "3"))
u2 as var(func: eq(name, "2"))
}
mutation {
delete {
uid(u2) <game_answer> uid(u3) .
}
}
}`
_, _, _, err = mutationWithTs(m2, "application/rdf", false, true, 0)
require.NoError(t, err)

q1 := `
{
me(func: eq(count(~game_answer), 1)) {
name
count(~game_answer)
}
}`
res, _, err := queryWithTs(q1, "application/graphql+-", "", 0)
require.NoError(t, err)
require.NotContains(t, res, "count(~game_answer)")
}
14 changes: 12 additions & 2 deletions posting/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,18 @@ func (txn *Txn) addReverseMutationHelper(ctx context.Context, plist *List,

func (txn *Txn) addReverseMutation(ctx context.Context, t *pb.DirectedEdge) error {
key := x.ReverseKey(t.Attr, t.ValueId)
plist, err := txn.cache.GetFromDelta(key)
hasCountIndex := schema.State().HasCount(t.Attr)

var getFn func(key []byte) (*List, error)
if hasCountIndex {
// We need to retrieve the full posting list from disk, to allow us to get the length of the
// posting list for the counts.
getFn = txn.Get
} else {
// We are just adding a reverse edge. No need to read the list from disk.
getFn = txn.GetFromDelta
}
plist, err := getFn(key)
if err != nil {
return err
}
Expand All @@ -184,7 +195,6 @@ func (txn *Txn) addReverseMutation(ctx context.Context, t *pb.DirectedEdge) erro
Facets: t.Facets,
}

hasCountIndex := schema.State().HasCount(t.Attr)
cp, err := txn.addReverseMutationHelper(ctx, plist, hasCountIndex, edge)
if err != nil {
return err
Expand Down