这是indexloc提供的服务,不要输入任何密码
Skip to content

Support mutations that come in SetJson field of api.Mutation in Unique #9437

@matthewmcneely

Description

@matthewmcneely

Describe the bug

A panic ("index out of range") can occur in the edgraph.verifyUniqueWithinMutation function when processing a request that includes a mix of KEPT and PRUNED SetJson mutations with conditional upsert logic (@if). The issue appears to be related to how mutation indices are handled after some mutations are pruned based on their conditions, leading to stale or incorrect indices being used.

To Reproduce

The panic can be reliably reproduced using the following Go test case (TestPanicWithConditionallyPrunedJsonMutations). This test is on my branch, matthewmcneely/test-for-panic-with-conditionally-pruned-mutations. The test involves two sequential mutation requests:

The first request creates an initial set of entities.
The second request is looped (e.g., 10 times) and contains:
One SetJson mutation that is KEPT (creates a new entity).
Two SetJson mutations that are PRUNED (attempt to create duplicate entities, but their conditions evaluate to false).
The panic typically occurs within a few iterations of the second request.

< panic: runtime error: index out of range [1] with length 0
 
 goroutine 479 [running]:
U github.com/hypermodeinc/dgraph/v25/edgraph.verifyUniqueWithinMutation(0x40328232c0)
;       /Users/matthew/code/dgraph/edgraph/server.go:2174 +0x2c8
� github.com/hypermodeinc/dgraph/v25/edgraph.(*Server).doMutate(0x15f0cb8?, {0x15f0cb8, 0x403281fbc0}, 0x40328232c0, 0x4032815880)
9       /Users/matthew/code/dgraph/edgraph/server.go:543 +0xb4
r github.com/hypermodeinc/dgraph/v25/edgraph.(*Server).doQuery(0x2395320, {0x15f0cb8, 0x4032c7c540}, 0x40324df6f8)
;       /Users/matthew/code/dgraph/edgraph/server.go:1387 +0xc90
v github.com/hypermodeinc/dgraph/v25/edgraph.(*Server).QueryNoGrpc(0x2395320, {0x15f0cb8, 0x403281f980}, 0x4032814980)
;       /Users/matthew/code/dgraph/edgraph/server.go:1237 +0x358
j github.com/hypermodeinc/dgraph/v25/edgraph.(*Server).Query(0x2322210?, {0x15f0cb8, 0x403281f980}, 0x18?)
:       /Users/matthew/code/dgraph/edgraph/server.go:1184 +0x28
� github.com/dgraph-io/dgo/v250/protos/api._Dgraph_Query_Handler.func1({0x15f0cb8?, 0x403281f980?}, {0x129a9a0?, 0x4032814980?})
p       /Users/matthew/go/pkg/mod/github.com/dgraph-io/dgo/v250@v250.0.0-preview4/protos/api/api_grpc.pb.go:186 +0xd0
� github.com/hypermodeinc/dgraph/v25/audit.AuditRequestGRPC({0x15f0cb8?, 0x403281f980?}, {0x129a9a0?, 0x4032814980?}, 0x80?, 0x12a9980?)
;       /Users/matthew/code/dgraph/audit/interceptor.go:72 +0xd4
� github.com/dgraph-io/dgo/v250/protos/api._Dgraph_Query_Handler({0x12b3e20, 0x2395320}, {0x15f0cb8, 0x403281f980}, 0x4032814900, 0x13f1c18)
q       /Users/matthew/go/pkg/mod/github.com/dgraph-io/dgo/v250@v250.0.0-preview4/protos/api/api_grpc.pb.go:188 +0x148
� google.golang.org/grpc.(*Server).processUnaryRPC(0x400001e800, {0x15f0cb8, 0x403281f860}, 0x403284a240, 0x4011daf200, 0x234f578, 0x0)
Q       /Users/matthew/go/pkg/mod/google.golang.org/grpc@v1.72.1/server.go:1405 +0xc9c
f google.golang.org/grpc.(*Server).handleStream(0x400001e800, {0x15f1e90, 0x40001be820}, 0x403284a240)
Q       /Users/matthew/go/pkg/mod/google.golang.org/grpc@v1.72.1/server.go:1815 +0x900
9 google.golang.org/grpc.(*Server).serveStreams.func2.1()
P       /Users/matthew/go/pkg/mod/google.golang.org/grpc@v1.72.1/server.go:1035 +0x84
Q created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 490
Q       /Users/matthew/go/pkg/mod/google.golang.org/grpc@v1.72.1/server.go:1046 +0x138

Expected behavior

The second set of mutations should complete, with no UIDs effected (and of course no panic)

Environment

  • OS: OSX, but running under the dgraphtest suite with Linux build
  • Version v25.0.0-preview4, although this seems to go back to v24 as well... about a year ago when verifyUniqueWithinMutation was added/refactored.

Additional context

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions