Multi index on edge cause parallels upsert Transaction aborted


Report a Dgraph Bug

What version of Dgraph are you using?

Latest dgrah/standalone docker image for testing.

Have you tried reproducing the issue with the latest release?

Yes

What is the hardware spec (RAM, OS)?

Linux/MacOS

Steps to reproduce the issue (command/config used to run Dgraph).

1.Using latest dgraph/standalone and start server

docker pull dgraph/standalone

docker run -it --rm \
    --name dgraph \
    -p 8000:8000 \
    -p 8080:8080 \
    -p 9080:9080 \
    dgraph/standalone
  1. Adding schema for test case
curl localhost:8080/alter -X POST -d $'
  name: string @index(term) .
  email: string @index(exact) @upsert .
  cc: [uid]  @reverse @count .
  age: int @index(int) .' | jq
  1. mock parallels upsert some emails(the added one is not same), all connect to user@company0.io for test purpose.
var dg = func() *dgo.Dgraph {
	cc, err := grpc.Dial("localhost:9080", grpc.WithInsecure())
	if err != nil {
		panic(err)
	}
	return dgo.NewDgraphClient(api.NewDgraphClient(cc))
}()

func TestY(t *testing.T) {

	wg := &sync.WaitGroup{}

	for i := 0; i < 20; i++ {
		wg.Add(1)
		q := fmt.Sprintf(`query {
			q(func: eq(email, "user@company%d.io")) {
			  v1 as uid
			}
			q2(func: eq(email, "user@company0.io")) {
			  v2 as uid
			}
		  }`, i)

		m := fmt.Sprintf(`
		  uid(v1) <name> "first last" .
		  uid(v1) <email> "user@company%d.io" .
		  uid(v1) <cc> uid(v2) .
		  `, i)

		go func() {
			defer wg.Done()

			resp, err := dg.NewTxn().Do(context.Background(), &api.Request{
				Query: q,
				Mutations: []*api.Mutation{{
					SetNquads: []byte(m),
				}},
				CommitNow: true,
			})

			_ = resp
			if err != nil {
				t.Log(err)
			}
		}()
	}

	wg.Wait()
}

Expected behaviour and actual result.

Some of my experiment and result.

1. Run TestY --> OK
2. Run TestY --> Failed with lots of : "Transaction has been aborted. Please retry"
3. Remove index @count for cc
4. Run TestY --> OK
5. Adding index @count back to cc
6. Run TestY --> OK
7. Drop ALL data
8. Run TestY twice --> First is OK, and second same as step2
9. Do same as step3 to remove index @reverse, the result as same like 3~6

That’s really confused. When delete one and add back, it works. But after truncate data, the parallels upsert failed.