Skip to content

Commit 65e9f03

Browse files
committed
Add option for server-side linearizability
1 parent 3c25a72 commit 65e9f03

File tree

5 files changed

+68
-24
lines changed

5 files changed

+68
-24
lines changed

pydgraph/proto/api.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,13 @@ message Version {
9696
}
9797

9898
message LinRead {
99+
enum Sequencing {
100+
CLIENT_SIDE = 0;
101+
SERVER_SIDE = 1;
102+
}
103+
99104
map<uint32, uint64> ids = 1;
105+
Sequencing sequencing = 2;
100106
}
101107

102108
message Latency {

pydgraph/proto/api_pb2.py

Lines changed: 51 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pydgraph/proto/api_pb2_grpc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
22
import grpc
33

4-
import api_pb2 as api__pb2
4+
from . import api_pb2 as api__pb2
55

66

77
class DgraphStub(object):

pydgraph/txn.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def __init__(self, client):
4747

4848
self._finished = False
4949
self._mutated = False
50+
self._sequencing = api.LinRead.CLIENT_SIDE
51+
52+
def sequencing(self, sequencing):
53+
self._sequencing = sequencing
5054

5155
def query(self, q, variables=None, timeout=None, metadata=None, credentials=None):
5256
req = self._common_query(q, variables=variables)
@@ -57,8 +61,10 @@ def query(self, q, variables=None, timeout=None, metadata=None, credentials=None
5761
def _common_query(self, q, variables=None):
5862
if self._finished:
5963
raise Exception('Transaction has already been committed or discarded')
60-
61-
req = api.Request(query=q, start_ts=self._ctx.start_ts, lin_read=self._ctx.lin_read)
64+
65+
lin_read = self._ctx.lin_read
66+
lin_read.sequencing = self._sequencing
67+
req = api.Request(query=q, start_ts=self._ctx.start_ts, lin_read=lin_read)
6268
if variables is not None:
6369
for key, value in variables.items():
6470
if util.is_string(key) and util.is_string(value):

tests/test_txn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,8 @@ def test_mutate_conflict(self):
328328

329329
txn2.commit()
330330

331-
_ = txn.mutate(set_obj={'uid': uid, 'name': 'Manish2'})
332-
self.assertRaises(pydgraph.AbortedError, txn.commit)
331+
with self.assertRaises(pydgraph.AbortedError):
332+
_ = txn.mutate(set_obj={'uid': uid, 'name': 'Manish2'})
333333

334334
def test_conflict_ignore(self):
335335
"""Tests a mutation with ignore index conflict."""

0 commit comments

Comments
 (0)