Skip to content
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
1 change: 1 addition & 0 deletions dgraph/cmd/bulk/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (ld *loader) mapStage() {
for i := range ld.mappers {
ld.mappers[i] = nil
}
ld.xids.EvictAll()
x.Check(ld.xidDB.Close())
ld.xids = nil
runtime.GC()
Expand Down
6 changes: 6 additions & 0 deletions query/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ func expandEdges(ctx context.Context, m *intern.Mutations) ([]*intern.DirectedEd
edgeCopy.Attr = pred
edges = append(edges, &edgeCopy)

// We only want to delete the pred from <uid> + <_predicate_> posting list if this is
// a SP* deletion operation. Otherwise we just continue.
if edge.Op == intern.DirectedEdge_DEL && string(edge.Value) != x.Star {
continue
}

e := &intern.DirectedEdge{
Op: edge.Op,
Entity: edge.GetEntity(),
Expand Down
54 changes: 54 additions & 0 deletions systest/mutations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestSystem(t *testing.T) {
t.Run("set after delete for list", wrap(SetAfterDeletionListType))
t.Run("empty strings with exact", wrap(EmptyNamesWithExact))
t.Run("empty strings with term", wrap(EmptyRoomsWithTermIndex))
t.Run("delete with expand all", wrap(DeleteWithExpandAll))
}

func ExpandAllLangTest(t *testing.T, c *client.Dgraph) {
Expand Down Expand Up @@ -920,3 +921,56 @@ func EmptyRoomsWithTermIndex(t *testing.T, c *client.Dgraph) {
require.NoError(t, err)
require.Equal(t, `{"offices":[{"count(office.room)":1}]}`, string(resp.GetJson()))
}

func DeleteWithExpandAll(t *testing.T, c *client.Dgraph) {
ctx := context.Background()
assigned, err := c.NewTxn().Mutate(ctx, &api.Mutation{
SetNquads: []byte(`
_:a <to> _:b .
_:b <name> "b" .
_:a <to> _:c .
_:a <to> _:d .
`),
CommitNow: true,
})
require.NoError(t, err)
auid := assigned.Uids["a"]
buid := assigned.Uids["b"]

_, err = c.NewTxn().Mutate(ctx, &api.Mutation{
DelNquads: []byte(`
<` + auid + `> <to> <` + buid + `> .
<` + buid + `> * * .
`),
CommitNow: true,
})
require.NoError(t, err)

q := `query test($id: string) {
me(func: uid($id)) {
_predicate_
}
}`

type Preds struct {
Predicates []string `json:"_predicate_"`
}

type Root struct {
Me []Preds `json:"me"`
}

var r Root
resp, err := c.NewTxn().QueryWithVars(ctx, q, map[string]string{"$id": auid})
require.NoError(t, err)
json.Unmarshal(resp.Json, &r)
// S P O deletion shouldn't delete "to" .
require.Equal(t, 1, len(r.Me[0].Predicates))
require.Equal(t, "to", r.Me[0].Predicates[0])

// b should not have any _predicate_.
resp, err = c.NewTxn().QueryWithVars(ctx, q, map[string]string{"$id": buid})
require.NoError(t, err)
json.Unmarshal(resp.Json, &r)
require.Equal(t, 0, len(r.Me))
}