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);