error:Transaction has already been committed or discarded

This kind of error occurred when I was doing dgraph pressure test:

ERROR TestUtils - Exception:io.dgraph.TxnFinishedException: Transaction has already been committed or discarded

My main logic code

    Random random = new Random();
    Person p = new Person(); = "lilei1"+random.nextInt(10000);
    p.age = 26;
    p.addr = "河南"+random.nextInt(10000);
    Person p1 = new Person(); = "lilong"+random.nextInt(10000);
    p1.age = 25;
    p1.addr = "四川"+random.nextInt(10000);
    p1.frirnd = p;
    String json = gson.toJson(p1);
    Mutation mu =
    Response res = txn.mutate(mu);

Hi @tss,

I see that you are using dgraph4j (Dgraph Client for Java) . Looking at the error, it seems that you are using AsyncTransaction .

The error is caused when a .commit or .doRequest is called on the same mutation more than once.

As the Mutation mu is constructed with setCommitNow(true) , there is no need to commit the transaction after .mutate has been executed.

I suspect that .commit or .doRequest is being executed after the last .mutate which is causing the error.

Can you confirm if that’s the case ?