Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

startTs mismatch when running multiple upserts within one transaction #136

Closed
Grandys opened this issue Mar 23, 2020 · 0 comments · Fixed by #137
Closed

startTs mismatch when running multiple upserts within one transaction #136

Grandys opened this issue Mar 23, 2020 · 0 comments · Fixed by #137
Assignees
Labels
kind/bug Something is broken. status/accepted We were able to reproduce the issue and accept to work on it

Comments

@Grandys
Copy link
Contributor

Grandys commented Mar 23, 2020

Dgraph4j version: v2.1.0
Dgraph version: v1.2.0

I got following error when running multiple upserts within single transaction:

java.lang.RuntimeException: java.util.concurrent.CompletionException: java.lang.RuntimeException: The doRequest encountered an execution exception:
....
Caused by: java.util.concurrent.ExecutionException: io.dgraph.DgraphException: startTs mismatch
	at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
	at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1908)
	at io.dgraph.DgraphAsyncClient.lambda$runWithRetries$2(DgraphAsyncClient.java:180)
	... 6 more
Caused by: io.dgraph.DgraphException: startTs mismatch
	at io.dgraph.AsyncTransaction.mergeContext(AsyncTransaction.java:252)
	at io.dgraph.AsyncTransaction.lambda$null$0(AsyncTransaction.java:165)
	at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:616)
	...

Sample code:

DgraphProto.Operation op =
        DgraphProto.Operation.newBuilder()
            .setSchema("email: string @index(exact) @upsert .")
            .build();
dgraphClient.alter(op);

JsonArray jsonData = new JsonArray();
JsonObject person = new JsonObject();
person.addProperty("uid", "uid(v)");
person.addProperty("name", "wrong");
jsonData.add(person);

JsonObject person2 = new JsonObject();
person2.addProperty("email", "[email protected]");
person2.addProperty("uid", "uid(v)");
jsonData.add(person2);

String query =
    "{\n"
        + "    me(func: eq(email, \"[email protected]\")) {\n"
        + "        v as uid\n"
        + "    }\n"
        + "}\n";
Mutation mu =
Mutation.newBuilder().setSetJson(ByteString.copyFromUtf8(jsonData.toString())).build();
Request request = Request.newBuilder().addMutations(mu).setQuery(query).build();

Transaction transaction = dgraphClient.newTransaction();

// This upsert works
transaction.doRequest(request);

try {
  transaction.doRequest(request);
} catch (RuntimeException e) {
  transaction.discard();
  fail(e.getMessage());
}

Problem does not occur for multiple Queries and Mutations. When running queryWithVars or mutate, new Request object is build and property startTs is inherited from context. When raw Request is passed into doRequest it does not happen, so this may cause the problem?

@mangalaman93 mangalaman93 self-assigned this Mar 25, 2020
@mangalaman93 mangalaman93 added status/accepted We were able to reproduce the issue and accept to work on it kind/bug Something is broken. labels Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something is broken. status/accepted We were able to reproduce the issue and accept to work on it
Development

Successfully merging a pull request may close this issue.

2 participants