Last active
August 29, 2015 14:27
-
-
Save rystsov/1614f7499d0aca0f8fb4 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
Accepted = namedtuple('Accepted', ['n', 'val']) | |
class Register: | |
def __init__(self, nodes, q): | |
self.q = q # quorum size | |
self.nodes = nodes # addresses of all nodes (including current) | |
self.promise = -1 # promise | |
self.accepted = None # accepted pair of a value and its ballot num | |
self.chosen = None # stores cached chosen value | |
@synchronized | |
def prepare(self, n): | |
if self.promise < n: | |
self.promise = n | |
return self.accepted | |
return Conflict(promise=self.promise) | |
@synchronized | |
def accept(self, n, val): | |
if self.promise == n: | |
self.accepted = Accepted(n, val) | |
return OK() | |
return Conflict(promise=self.promise) | |
@synchronized | |
def choose(self, val): | |
self.chosen = val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment