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();
    p.name = "lilei1"+random.nextInt(10000);
    p.age = 26;
    p.addr = "河南"+random.nextInt(10000);
    
    Person p1 = new Person();
    p1.name = "lilong"+random.nextInt(10000);
    p1.age = 25;
    p1.addr = "四川"+random.nextInt(10000);
    p1.frirnd = p;
    
    String json = gson.toJson(p1);
    
    Mutation mu =
    Mutation.newBuilder()
        .setCommitNow(true)
        .setSetJson(ByteString.copyFromUtf8(json.toString()))
        .build();
    
    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 ?