Last active
September 7, 2015 21:37
-
-
Save rystsov/7f8db599d44ee635655f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _read_write_read(self, test, val, due): | |
n = self._get_n(0) | |
resps = net.send(self.nodes, lambda x: x.prepare(n), due-now()) | |
try: | |
# Waiting for q (majority) succeeded responses. | |
ok = resps.where(lambda x: isinstance(x.msg, Accepted)).wait(self.q) | |
last = ok.max(lambda x: x.msg.n).msg.val | |
if test != None and test(last): | |
candidate = val | |
else: | |
candidate = last | |
acks = net.send(ok.nodes, lambda x: x.accept(n, candidate), due-now()) | |
resps += acks | |
acks.where(lambda x: isinstance(x.msg, OK)).wait(self.q) | |
if test != None and not test(last): return Conflict(val=last) | |
return OK(val=candidate) | |
except CantResolveWait: | |
return NetworkError() | |
finally: | |
resps = resps.abort() # abort the connections and | |
# pick a ballot number greater than any of already known | |
for x in resps.where(lambda x: isinstance(x.msg, Conflict)): | |
self._get_n(x.msg.promise) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment