Skip to content

Commit

Permalink
release v20.03.2 (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhimanyusinghgaur authored Oct 27, 2020
1 parent b7dce2a commit 02fbe75
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 209 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ grab via Maven:
<dependency>
<groupId>io.dgraph</groupId>
<artifactId>dgraph4j</artifactId>
<version>20.03.1</version>
<version>20.03.2</version>
</dependency>
```
or Gradle:
```groovy
compile 'io.dgraph:dgraph4j:20.03.1'
compile 'io.dgraph:dgraph4j:20.03.2'
```

## Supported Versions
Expand Down Expand Up @@ -106,7 +106,7 @@ use a different version of this client.
| 1.7.0 | 1.15.0 | 2.0.12.Final |
| 1.7.3-1.7.5 | 1.15.1 | 2.0.12.Final |
| 2.0.0-2.1.0 | 1.22.1 | 2.0.25.Final |
| 20.03.0 | 1.26.0 | 2.0.26.Final |
| 20.03.0-20.03.2 | 1.26.0 | 2.0.26.Final |

So, for example, if you were using `dgraph4j v20.03.0`, then you would need to use `2.0.26-Final`
as the version for `netty-tcnative-boringssl-static` dependency as suggested by gRPC docs for
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ apply plugin: 'signing'

group = 'io.dgraph'
archivesBaseName = 'dgraph4j'
version = '20.03.1'
version = '20.03.2'
sourceCompatibility = 1.8
targetCompatibility = 1.8

Expand Down
Original file line number Diff line number Diff line change
@@ -1,111 +1,140 @@
package io.dgraph.example;

import io.dgraph.DgraphProto.Mutation;
import io.dgraph.DgraphProto.Request;
import com.google.gson.Gson;
import io.dgraph.DgraphProto.Response;
import com.google.protobuf.ByteString;
import io.dgraph.DgraphClient;
import io.dgraph.DgraphProto.Mutation;
import io.dgraph.DgraphProto.Request;
import io.dgraph.DgraphProto.Response;
import io.dgraph.Transaction;
import io.dgraph.TxnConflictException;
import java.util.Collections;
import java.util.Map;

public class MultiThreadedMutation implements Runnable {
// maximum retries
static final int MAX_RETRY_COUNT = 5;
static Integer globalThreadNumberCount = 1;
int threadNumber = 0;
//
private DgraphClient dgraphClient;
private Transaction txn;

public MultiThreadedMutation(DgraphClient dgraphClient) {
//assign a thread number
synchronized (globalThreadNumberCount) {
this.threadNumber = globalThreadNumberCount++;
this.dgraphClient = dgraphClient;
}

}
// maximum retries
static final int MAX_RETRY_COUNT = 5;
static Integer globalThreadNumberCount = 1;
int threadNumber = 0;
//
private DgraphClient dgraphClient;
private Transaction txn;

public void run() {
boolean successFlag = false;
int retryCount = 0;
while (retryCount < MAX_RETRY_COUNT) {
try {
//fire the mutation and check for exceptions
doMutation();
successFlag = true;
System.out.println(System.currentTimeMillis() + " Thread #" + threadNumber + " succeeded after "
+ retryCount + " retries");
break;
} catch (TxnConflictException txnConflictException) {
try {
System.out.println(System.currentTimeMillis() + " Thread #" + threadNumber
+ " found a concurrent modification conflict, sleeping for 1 second...");
Thread.sleep(1000);
System.out.println(System.currentTimeMillis() + " Thread #" + threadNumber + " resuming");
} catch (InterruptedException e) {
e.printStackTrace();
}
retryCount++;
} catch (Exception e) {
// cannot retry
e.printStackTrace();
break;
}
}
//check if maximum retries has been crossed
if (!successFlag && retryCount >= MAX_RETRY_COUNT) {
System.out.println(System.currentTimeMillis() + " Thread #" + threadNumber + " giving up transaction after "
+ (retryCount - 1) + " retries");
}
}
public MultiThreadedMutation(DgraphClient dgraphClient) {
// assign a thread number
synchronized (globalThreadNumberCount) {
this.threadNumber = globalThreadNumberCount++;
this.dgraphClient = dgraphClient;
}
}

private void doMutation() throws Exception {
txn = dgraphClient.newTransaction();
Gson gson = new Gson();
// Query
String query = "query all($a: string){\n" + " all(func: eq(name, $a)) {\n" + " " + "uid\n" + "name\n"
+ "clickCount\n" + " }\n" + "}\n";
public void run() {
boolean successFlag = false;
int retryCount = 0;
while (retryCount < MAX_RETRY_COUNT) {
try {
// fire the mutation and check for exceptions
doMutation();
successFlag = true;
System.out.println(
System.currentTimeMillis()
+ " Thread #"
+ threadNumber
+ " succeeded after "
+ retryCount
+ " retries");
break;
} catch (TxnConflictException txnConflictException) {
try {
System.out.println(
System.currentTimeMillis()
+ " Thread #"
+ threadNumber
+ " found a concurrent modification conflict, sleeping for 1 second...");
Thread.sleep(1000);
System.out.println(System.currentTimeMillis() + " Thread #" + threadNumber + " resuming");
} catch (InterruptedException e) {
e.printStackTrace();
}
retryCount++;
} catch (Exception e) {
// cannot retry
e.printStackTrace();
break;
}
}
// check if maximum retries has been crossed
if (!successFlag && retryCount >= MAX_RETRY_COUNT) {
System.out.println(
System.currentTimeMillis()
+ " Thread #"
+ threadNumber
+ " giving up transaction after "
+ (retryCount - 1)
+ " retries");
}
}

Map<String, String> vars = Collections.singletonMap("$a", "Alice");
private void doMutation() throws Exception {
txn = dgraphClient.newTransaction();
Gson gson = new Gson();
// Query
String query =
"query all($a: string){\n"
+ " all(func: eq(name, $a)) {\n"
+ " "
+ "uid\n"
+ "name\n"
+ "clickCount\n"
+ " }\n"
+ "}\n";

Response response = dgraphClient.newReadOnlyTransaction().queryWithVars(query, vars);
People ppl = gson.fromJson(response.getJson().toStringUtf8(), People.class);
//
for (Person person : ppl.all) {
System.out.println(System.currentTimeMillis() + " Thread #" + threadNumber
+ " increasing clickCount for uid " + person.uid + ", Name: " + person.name);
//increment clickCount
person.clickCount = person.clickCount + 1;
Map<String, String> vars = Collections.singletonMap("$a", "Alice");

try {
//find and update alice's clickCount in a transaction
String upsertQuery = "query {\n" + "user as var(func: eq(name, \"" + person.name + "\"))\n" + "}\n";
Mutation mu2 = Mutation.newBuilder()
.setSetNquads(ByteString.copyFromUtf8("uid(user) <clickCount> \"" + person.clickCount + "\" ."))
.build();
Response response = dgraphClient.newReadOnlyTransaction().queryWithVars(query, vars);
People ppl = gson.fromJson(response.getJson().toStringUtf8(), People.class);
//
for (Person person : ppl.all) {
System.out.println(
System.currentTimeMillis()
+ " Thread #"
+ threadNumber
+ " increasing clickCount for uid "
+ person.uid
+ ", Name: "
+ person.name);
// increment clickCount
person.clickCount = person.clickCount + 1;

Request request = Request.newBuilder().setQuery(upsertQuery).addMutations(mu2).setCommitNow(true)
.build();
txn.doRequest(request);
txn.close();
} catch (Exception ex) {
// if its a conflict exception, we can retry
if (ex.getCause().getCause() instanceof TxnConflictException) {
TxnConflictException txnConflictException = (TxnConflictException) ex.getCause().getCause();
txn.close();
throw (txnConflictException);
} else {
throw ex;
}
try {
// find and update alice's clickCount in a transaction
String upsertQuery =
"query {\n" + "user as var(func: eq(name, \"" + person.name + "\"))\n" + "}\n";
Mutation mu2 =
Mutation.newBuilder()
.setSetNquads(
ByteString.copyFromUtf8(
"uid(user) <clickCount> \"" + person.clickCount + "\" ."))
.build();

} finally {
txn.discard();
}
Request request =
Request.newBuilder().setQuery(upsertQuery).addMutations(mu2).setCommitNow(true).build();
txn.doRequest(request);
txn.close();
} catch (Exception ex) {
// if its a conflict exception, we can retry
if (ex.getCause().getCause() instanceof TxnConflictException) {
TxnConflictException txnConflictException =
(TxnConflictException) ex.getCause().getCause();
txn.close();
throw (txnConflictException);
} else {
throw ex;
}

}
}
} finally {
txn.discard();
}
}
}
}
Loading

0 comments on commit 02fbe75

Please sign in to comment.