Skip to content

Commit 577260c

Browse files
author
Lucas Wang
committed
Addeng best effort flag, shorten ACL test timing to match changes in dgraph
1 parent b4bf3bf commit 577260c

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

src/main/java/io/dgraph/AsyncTransaction.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class AsyncTransaction implements AutoCloseable {
4444
private volatile boolean mutated;
4545
private volatile boolean finished;
4646
private volatile boolean readOnly;
47+
private volatile boolean bestEffort;
4748

4849
private final DgraphAsyncClient client;
4950
private final DgraphStub stub;
@@ -53,6 +54,7 @@ public class AsyncTransaction implements AutoCloseable {
5354
this.client = client;
5455
this.stub = stub;
5556
this.readOnly = false;
57+
this.bestEffort = false;
5658
}
5759

5860
AsyncTransaction(DgraphAsyncClient client, DgraphStub stub, final boolean readOnly) {
@@ -81,6 +83,7 @@ public CompletableFuture<Response> queryWithVars(
8183
.setStartTs(context.getStartTs())
8284
.setLinRead(lr.build())
8385
.setReadOnly(readOnly)
86+
.setBestEffort(bestEffort)
8487
.build();
8588

8689
LOG.debug("Sending request to Dgraph...");
@@ -111,6 +114,18 @@ public CompletableFuture<Response> query(final String query) {
111114
return queryWithVars(query, Collections.emptyMap());
112115
}
113116

117+
/**
118+
* Sets the best effort flag for this transaction. The Best effort flag can only be set for
119+
* read-only transactions, and setting the best effort flag will enable a read-only transaction to
120+
* see mutations made by other transactions even if those mutations have not been committed.
121+
*/
122+
public void setBestEffort(boolean bestEffort) {
123+
if (!this.readOnly) {
124+
throw new RuntimeException("Best effort only works for read-only queries");
125+
}
126+
this.bestEffort = bestEffort;
127+
}
128+
114129
/**
115130
* Allows data stored on dgraph instances to be modified. The fields in Mutation come in pairs,
116131
* set and delete. Mutations can either be encoded as JSON or as RDFs.

src/main/proto/api.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ message Request {
5050
uint64 start_ts = 13;
5151
LinRead lin_read = 14;
5252
bool read_only = 15;
53+
bool best_effort = 16;
5354
}
5455

5556
message Response {

src/test/java/io/dgraph/AclTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public void testAuthorization() throws Exception {
6666
alterPredicateWithUserAccount(false);
6767

6868
createGroupAndAcls(UNUSED_GROUP, false);
69-
System.out.println("Sleep for 35 seconds for acl caches to be refreshed");
70-
Thread.sleep(35 * 1000);
69+
System.out.println("Sleep for 6 seconds for acl caches to be refreshed");
70+
Thread.sleep(6 * 1000);
7171

7272
// now all the operations should fail since there are rules defined on the unusedGroup
7373
queryPredicateWithUserAccount(true);
@@ -77,18 +77,18 @@ public void testAuthorization() throws Exception {
7777

7878
// create the dev group and add the user to it
7979
createGroupAndAcls(DEV_GROUP, true);
80-
System.out.println("Sleep for 35 seconds for acl caches to be refreshed");
81-
Thread.sleep(35 * 1000);
80+
System.out.println("Sleep for 6 seconds for acl caches to be refreshed");
81+
Thread.sleep(6 * 1000);
8282

8383
// now the operations should succeed again through the dev group
8484
queryPredicateWithUserAccount(false);
8585
// sleep long enough (10s per the docker-compose.yml in this directory)
8686
// for the accessJwt to expire in order to test auto login through refresh jwt
87-
System.out.println("Sleep for 12 seconds for the accessJwt to expire");
88-
Thread.sleep(12 * 1000);
87+
System.out.println("Sleep for 4 seconds for the accessJwt to expire");
88+
Thread.sleep(4 * 1000);
8989
mutatePredicateWithUserAccount(false);
90-
System.out.println("Sleep for 12 seconds for the accessJwt to expire");
91-
Thread.sleep(12 * 1000);
90+
System.out.println("Sleep for 4 seconds for the accessJwt to expire");
91+
Thread.sleep(4 * 1000);
9292
alterPredicateWithUserAccount(false);
9393
}
9494

@@ -144,7 +144,7 @@ private void createGroupAndAcls(String group, boolean addUserToGroup)
144144
group,
145145
"-p",
146146
PREDICATE_TO_READ,
147-
"-P",
147+
"-m",
148148
"4",
149149
"-x",
150150
GROOT_PASSWORD);
@@ -161,7 +161,7 @@ private void createGroupAndAcls(String group, boolean addUserToGroup)
161161
group,
162162
"-p",
163163
QUERY_ATTR,
164-
"-P",
164+
"-m",
165165
"4",
166166
"-x",
167167
GROOT_PASSWORD);
@@ -177,7 +177,7 @@ private void createGroupAndAcls(String group, boolean addUserToGroup)
177177
group,
178178
"-p",
179179
PREDICATE_TO_WRITE,
180-
"-P",
180+
"-m",
181181
"2",
182182
"-x",
183183
GROOT_PASSWORD);
@@ -192,7 +192,7 @@ private void createGroupAndAcls(String group, boolean addUserToGroup)
192192
group,
193193
"-p",
194194
PREDICATE_TO_ALTER,
195-
"-P",
195+
"-m",
196196
"1",
197197
"-x",
198198
GROOT_PASSWORD);

0 commit comments

Comments
 (0)