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

add option to choose client/server side linerizability #54

Merged
merged 4 commits into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function quit {

function start {
echo -e "Starting first server."
dgraph server -p build/p -w build/w --memory_mb 4096 --zero localhost:5080 > build/server.log 2>&1 &
dgraph server -p build/p -w build/w --lru_mb 4096 --zero localhost:5080 > build/server.log 2>&1 &
# Wait for membership sync to happen.
sleep $sleepTime
return 0
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/io/dgraph/DgraphClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,20 @@ public class Transaction implements AutoCloseable {
TxnContext context;
boolean finished;
boolean mutated;
LinRead.Sequencing sequencing;

Transaction() {
context = TxnContext.newBuilder().setLinRead(DgraphClient.this.getLinRead()).build();
sequencing = LinRead.Sequencing.CLIENT_SIDE;
}

/**
* Sets the sequencing for this transaction. By default client_side_sequencing is used
*
* @param sequencing Sequencing Mode (ClIENT_SIDE or SERVER_SIDE).
*/
public void setSequencing(LinRead.Sequencing sequencing) {
this.sequencing = sequencing;
}

/**
Expand All @@ -187,12 +198,14 @@ public class Transaction implements AutoCloseable {
*/
public Response queryWithVars(final String query, final Map<String, String> vars) {
logger.debug("Starting query...");
LinRead.Builder lr = LinRead.newBuilder(context.getLinRead());
lr.setSequencing(this.sequencing);
final Request request =
Request.newBuilder()
.setQuery(query)
.putAllVars(vars)
.setStartTs(context.getStartTs())
.setLinRead(context.getLinRead())
.setLinRead(lr.build())
.build();
final DgraphGrpc.DgraphBlockingStub client = anyClient();
logger.debug("Sending request to Dgraph...");
Expand Down
11 changes: 10 additions & 1 deletion src/main/proto/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ message Response {
message Assigned {
map<string, string> uids = 1;
TxnContext context = 2;
Latency latency = 12;
}

message Mutation {
Expand All @@ -60,7 +61,7 @@ message Mutation {
repeated NQuad del = 11;
uint64 start_ts = 13;
bool commit_now = 14;
bool ignore_index_conflict = 15;
bool ignore_index_conflict = 15; // this field is not parsed or used by the server anymore.
}


Expand Down Expand Up @@ -95,7 +96,13 @@ message Version {
}

message LinRead {
enum Sequencing {
CLIENT_SIDE = 0;
SERVER_SIDE = 1;
}

map<uint32, uint64> ids = 1;
Sequencing sequencing = 2;
}

message Latency {
Expand Down Expand Up @@ -154,6 +161,8 @@ message SchemaNode {
bool reverse = 5;
bool count = 6;
bool list = 7;
bool upsert = 8;
bool lang = 9;
}

// vim: noexpandtab sw=2 ts=2
6 changes: 3 additions & 3 deletions src/test/java/io/dgraph/AcctUpsertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ private void setup() {

String schema =
"\n"
+ " first: string @index(term) .\n"
+ " last: string @index(hash) .\n"
+ " age: int @index(int) .\n"
+ " first: string @index(term) @upsert .\n"
+ " last: string @index(hash) @upsert .\n"
+ " age: int @index(int) @upsert .\n"
+ " when: int .\n";
Operation op = Operation.newBuilder().setSchema(schema).build();
dgraphClient.alter(op);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/dgraph/DeleteEdgeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void deleteEdgesTest() {
+ " }\n"
+ " schools {\n"
+ " uid\n"
+ " name@en\n"
+ " name\n"
+ " }\n"
+ " }\n"
+ " }";
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/dgraph/DgraphClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void testMergeContext() throws Exception {
@Test
public void testTxnQueryVariables() throws Exception {
// Set schema
Operation op = Operation.newBuilder().setSchema("name: string @index(exact) .").build();
Operation op = Operation.newBuilder().setSchema("name: string @index(exact) @upsert .").build();
dgraphClient.alter(op);

// Add data
Expand Down Expand Up @@ -173,7 +173,7 @@ public void testClientWithDeadline() throws Exception {
DgraphGrpc.DgraphBlockingStub blockingStub = DgraphGrpc.newBlockingStub(channel);
dgraphClient = new DgraphClient(Collections.singletonList(blockingStub), 1);

Operation op = Operation.newBuilder().setSchema("name: string @index(exact) .").build();
Operation op = Operation.newBuilder().setSchema("name: string @index(exact) @upsert .").build();

// Alters schema without exceeding the given deadline.
dgraphClient.alter(op);
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/io/dgraph/MutatesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class MutatesTest extends DgraphIntegrationTest {

@Test
public void testInsert3Quads() throws Exception {
Operation op = Operation.newBuilder().setSchema("name: string @index(fulltext) .").build();
Operation op =
Operation.newBuilder().setSchema("name: string @index(fulltext) @upsert .").build();
dgraphClient.alter(op);

Transaction txn = dgraphClient.newTransaction();
Expand Down