dgraph-io / dgraph4j

Official Dgraph Java client
https://dgraph.io
Apache License 2.0
159 stars 63 forks source link

Encountered invalid UTF-8 error, and cannot proceed further #25

Closed lxwithgod closed 6 years ago

lxwithgod commented 7 years ago

when i insert into data in loop,i meet Caused by: com.dataPlatform.protobuf.InvalidProtocolBufferException: Protocol message had invalid UTF-8. after,i can't insert into any new data unitil i restart server.

deepakjois commented 7 years ago

Could you post a minmal example here, which reproduces the problem.

lxwithgod commented 7 years ago

this is v0.9.1

JsonObject json = new JsonObject(); json.addProperty("name", "Alice"); // System.out.println(json.toString()); for(int i=0;i<10000;i++) { System.out.println(json.toString()); Mutation mu = Mutation.newBuilder() .setSetJson(ByteString.copyFromUtf8(json.toString())) .build(); dgraphClient.newTransaction().mutate(mu); }

deepakjois commented 6 years ago

This is a duplicate of #29. This is a bug that will need to be fixed in the server. I will update that issue with more details. Please follow there.

I had some comments about your client code, however. You do not seem to be committing the transaction. You have two options:

Either set the CommitNow field in the mutation.

Mutation mu =
Mutation.newBuilder()
.setSetJson(ByteString.copyFromUtf8(json.toString()))
.setCommitNow(true)
.build();

or, a better solution is to call Transaction#Commit() sometime. You can call it immediately after the mutation, or at the end of your loop after all the mutations have been done.

Transaction txn = dgraphClient.newTransaction()
for(int i=0;i<10000;i++) {
  System.out.println(json.toString());
  Mutation mu =
    Mutation.newBuilder()
    .setSetJson(ByteString.copyFromUtf8(json.toString()))
    .build();
    txn.mutate(mu);
}
txn.commit()

Hope that helps.

deepakjois commented 6 years ago

Closed in favor of #29