Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rystsov
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rystsov/1614f7499d0aca0f8fb4 to your computer and use it in GitHub Desktop.
Save rystsov/1614f7499d0aca0f8fb4 to your computer and use it in GitHub Desktop.
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