Retry Logic Getting Exhausted

I have been reading up on upsert and implemented this for one of our datasets. In this scenario I am trying to upsert a source and target node and then a edge in between. This works perfect when run in a single thread. But if I run the load in parallel I am getting “Transaction has been aborted. Please retry” errors.

This is not unexpected so I added retry logic to my code. But even with the retry when loading 2 million edges in batches of 500 eventually the retry (30 attempts, 1000ms sleep between) gets exhausted.

I have tried many things including:

  • Removing the upsert of the nodes and loading them prior to the edges
  • Creating separate mutations for each record
  • Creating separate mutations for each source\target\edge
  • Playing around w/ different batch sizes

But each time eventually the retry exhausts.

The data looks like this:


And the code:

private static final int BATCH_SIZE = 500;
protected static final int NUM_RECORDS = 2_000_000;
private static final int NUM_RETRIES = 30;

public void process(String line) throws Exception
      batch.add(parser.parseEdge(line, AddEdgesBatchRepo.EDGE_COLUMNS));
      if (batch.size() >= BATCH_SIZE)
        int retryNum = 0;
        while (true)
          catch (Exception e)
            System.out.println("Retrying Transaction [" + retryNum + "]");
            if (++retryNum > NUM_RETRIES)
              throw e;
  public void addEdges(List<EdgeRecord> edgeRecords) throws Exception
    Set<String> idFuncs = new HashSet<>();
    StringBuilder query = new StringBuilder();
    StringBuilder nodeUpsertBuilder = new StringBuilder();
    StringBuilder edgeUpsertBuilder = new StringBuilder();
    query.append("query {\n");
    for(EdgeRecord record : edgeRecords)
      String sourceLabel = escapeValue(record.getFromId()).toString();
      String targetLabel = escapeValue(record.getToId()).toString();
      String sourceId = record.getFromLabel() + ":" + sourceLabel;
      String targetId = record.getToLabel() + ":" + targetLabel;
      String sourceIdFunc = "ID_" + sourceId.replaceAll("[:/]", "_");
      String targetIdFunc = "ID_" + targetId.replaceAll("[:/]", "_");

        nodeUpsertBuilder.append("uid(").append(sourceIdFunc).append(") <_stp_id> \"").append(sourceId).append("\" .\n");
        nodeUpsertBuilder.append("uid(").append(sourceIdFunc).append(") <_stp_label> \"").append(sourceLabel).append("\" .\n");
        nodeUpsertBuilder.append("uid(").append(sourceIdFunc).append(") <dgraph.type> \"").append(record.getFromLabel()).append("\" .\n");

        query.append("\tvar(func: eq(<_stp_id>, \"" + sourceId + "\")) { ").append(sourceIdFunc).append(" as uid }\n");

        nodeUpsertBuilder.append("uid(").append(targetIdFunc).append(") <_stp_id> \"").append(targetId).append("\" .\n");
        nodeUpsertBuilder.append("uid(").append(targetIdFunc).append(") <_stp_label> \"").append(targetLabel).append("\" .\n");
        nodeUpsertBuilder.append("uid(").append(targetIdFunc).append(") <dgraph.type> \"").append(record.getToLabel()).append("\" .\n");

        query.append("\tvar(func: eq(<_stp_id>, \"" + targetId + "\")) { ").append(targetIdFunc).append(" as uid }\n");

      edgeUpsertBuilder.append("uid(").append(sourceIdFunc).append(") <").append(record.getName()).append("> uid(").append(targetIdFunc).append(")");
      if (record.getProperties().size() > 0)
        Boolean first = true;
        for (String name : record.getProperties().keySet())
          if (!first)
            edgeUpsertBuilder.append(", ");
          first = false;
      edgeUpsertBuilder.append(" .\n");

    if(edgeUpsertBuilder.length() > 0)
      Mutation mu = Mutation.newBuilder()

      Request request = Request.newBuilder()


@MichelDiz any thoughts on this?

Note I also tried adding @upsert to the appropriate predicates as well as using hash instead of exact for indexing (according to the doc I believe these should accomplish the same thing).

Sorry, I’m not a JAVA developer. I’ll to see if there’s anyone available to see this.

OK. Thanks. As noted in other posts I am evaluating your product (including customer support - which if there is a more appropriate channel to direct those queries let me know) against other databases, so I am looking for solutions or explanations to issues I encounter. If the problem’s are on my side I need to understand what I am doing wrong…

Hi Luke,
We can give you access to our trial support, which is done via a different (dedicated) channel
I am sending you a private message

Hi @luke.daugherty, thanks for sharing above information with us. Please also share your schema with us. Indexing can be one of the reason for transaction abortions. So you can try to insert records with same value in single transactions and compare your retries.
If insertion is one time task then, you can try inserting records without any schema and then change schema, so that indexing can be performed after insertion.
Let us know your findings.

Note, a trial support ticket has been opened on this topic and was being looked at by Alvin Khaled.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.