Transaction has already been committed or discarded

Posted by weickdev:

I run my java code, it works well at beginning, but after a while it throws below exception:

[pool-2-thread-1] ERROR com.haizhi.graph.lab.dgraph.datamaker.DgraphDataMaker - Node create error:
io.grpc.StatusRuntimeException: RESOURCE_EXHAUSTED: io.grpc.netty.NettyClientTransport$3: Frame size 6250043 exceeds maximum: 4194304.
	at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:210)
	at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:191)
	at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:124)
	at io.dgraph.DgraphGrpc$DgraphBlockingStub.mutate(DgraphGrpc.java:298)
	at io.dgraph.DgraphClient$Transaction.mutate(DgraphClient.java:211)
	at com.haizhi.graph.lab.dgraph.datamaker.DgraphDataMaker.saveVertices(DgraphDataMaker.java:128)
	at com.haizhi.graph.lab.dgraph.datamaker.DgraphDataMaker.lambda$ansySaveVertex$3(DgraphDataMaker.java:146)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Exception in thread "pool-2-thread-1" io.dgraph.TxnFinishedException: Transaction has already been committed or discarded
	at io.dgraph.DgraphClient$Transaction.commit(DgraphClient.java:243)
	at com.haizhi.graph.lab.dgraph.datamaker.DgraphDataMaker.saveVertices(DgraphDataMaker.java:132)
	at com.haizhi.graph.lab.dgraph.datamaker.DgraphDataMaker.lambda$ansySaveVertex$3(DgraphDataMaker.java:146)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

my code looks like:

private void saveVertices(List<Map<String, Object>> itemList) {
        long startTime = System.currentTimeMillis();
        DgraphClient.Transaction transaction = dgraphClient.newTransaction();
        try {
            try {
                logger.info("saving {} items", itemList.size());
                String json = JSON.toJSONString(itemList);
                DgraphProto.Mutation mutation = DgraphProto.Mutation.newBuilder().setIgnoreIndexConflict(true).setSetJson(ByteString.copyFromUtf8(json)).build();
                transaction.mutate(mutation);
            } catch (Exception e) {
                logger.error("Node create error: ", e);
            }
            transaction.commit();
        } finally {
            transaction.discard();
        }
        logger.info("save {} items costs {}ms", itemList.size(), System.currentTimeMillis() - startTime);
    }

weickdev commented :

I think the ‘RESOURCE_EXHAUSTED’ cause this problem If so, why dose RESOURCE_EXHAUSTED happen?

deepakjois commented :

This RESOURCE_EXHAUSTED seems to be an error thrown by Netty, and not by Dgraph. There seems to be a problem with grpc.

Googling this error led to this thread: Hit the frame size limit of 100MB. Any way to increase this limit? · Issue #917 · grpc/grpc-java · GitHub

But before we proceed further with the investigation, do you think you could put a minimal working example replicating your problem somewhere on github, so that I can try running it myself in AWS and replicate the problem?