schema
curl localhost:8080/alter -X POST -d $'
name: string @index(term) .
email: string @index(exact) @upsert .
cc: [uid] .
age: int @index(int) .' | jq
test code
func TestZ(t *testing.T) {
wg := &sync.WaitGroup{}
for i := 0; i < 20; i++ {
wg.Add(1)
q := fmt.Sprintf(`query {
q(func: eq(email, "[email protected]")) {
v1 as uid
}
}`)
m := fmt.Sprintf(`
uid(v1) <name> "first last" .
uid(v1) <email> "[email protected]" .
`)
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()
}
When TestZ first time run, it create 20 nodes with same email.
But when TestZ second time run, only 1 ok, but the others are Transaction has been aborted. Please retry
(as for doc: this is what we expected)
For data pre-exist or not has different handle strategy.
Any suggest or policy for avoid creating the other 19 node when first time run?