Skip to content

Commit

Permalink
rename Request to Requester
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Nov 10, 2014
1 parent 56b8340 commit f00975b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 36 deletions.
36 changes: 18 additions & 18 deletions cluster/CHAPTER.rst
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ The method uses a simple Queue to wait for the result from the protocol thread.
self.thread = threading.Thread(target=self.network.run)
self.thread.start()
def invoke(self, input_value, request_cls=Request):
def invoke(self, input_value, request_cls=Requester):
assert self.current_request is None
q = Queue.Queue()
self.current_request = request_cls(self.node, input_value, q.put)
Expand Down Expand Up @@ -423,17 +423,17 @@ Furthermore, if the consensus for the selected slot is for a different proposal,
.. code-block:: none
Local
Request --------- Replica Current
*--->>---/ Invoke /--------+ Leader
--------- : ----------
*--->>---/ Propose /-----+
---------- :
(multi-paxos)
----------- :
+-------/ Decision /-<<--*
---------- : -----------
*--------/ Invoked /---<<--*
: ----------
Requester --------- Replica Current
*--->>---/ Invoke /--------+ Leader
--------- : ----------
*--->>---/ Propose /-----+
---------- :
(multi-paxos)
----------- :
+-------/ Decision /-<<--*
---------- : -----------
*--------/ Invoked /---<<--*
: ----------
``Decision`` messages represent slots on which the cluster has come to consensus.
Here, replicas store the new decision, then run the state machine until it reaches an undecided slot.
Expand Down Expand Up @@ -928,22 +928,22 @@ Seed emulates the ``Join``/``Welcome`` part of the bootstrap - replica interacti
}}}

Request
.......
Requester
.........

The request role manages a request to the distributed state machine.
The requester role manages a request to the distributed state machine.
The role class simply sends ``Invoke`` messages to the local replica until it receives a corresponding ``Invoked``.
See the "Replica" section, above, for this role's communication diagram.

{{{ code_block cluster.py 'class Request'
{{{ code_block cluster.py 'class Requester'
.. code-block:: python
class Request(Role):
class Requester(Role):
client_ids = itertools.count(start=100000)
def __init__(self, node, n, callback):
super(Request, self).__init__(node)
super(Requester, self).__init__(node)
self.client_id = self.client_ids.next()
self.n = n
self.output = None
Expand Down
1 change: 0 additions & 1 deletion cluster/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ Editing:
- define "network partition"
- Transition after components (Network/------)
- at "Interactive debuggers", also hard to debug over multiple machines
- s/Request/Requester/g
16 changes: 8 additions & 8 deletions cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,12 +480,12 @@ def finish(self):
bs.start()
self.stop()

class Request(Role):
class Requester(Role):

client_ids = itertools.count(start=100000)

def __init__(self, node, n, callback):
super(Request, self).__init__(node)
super(Requester, self).__init__(node)
self.client_id = self.client_ids.next()
self.n = n
self.output = None
Expand Down Expand Up @@ -515,18 +515,18 @@ def __init__(self, state_machine, network, peers, seed=None,
execute_fn=state_machine)
else:
self.startup_role = bootstrap_cls(self.node, execute_fn=state_machine, peers=peers)
self.current_request = None
self.requester = None

def start(self):
self.startup_role.start()
self.thread = threading.Thread(target=self.network.run)
self.thread.start()

def invoke(self, input_value, request_cls=Request):
assert self.current_request is None
def invoke(self, input_value, request_cls=Requester):
assert self.requester is None
q = Queue.Queue()
self.current_request = request_cls(self.node, input_value, q.put)
self.current_request.start()
self.requester = request_cls(self.node, input_value, q.put)
self.requester.start()
output = q.get()
self.current_request = None
self.requester = None
return output
10 changes: 5 additions & 5 deletions cluster/test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def request_done(output):
self.event("request done: %s" % output)
def make_request(n, node):
self.event("request: %s" % n)
req = Request(node, n, request_done)
req = Requester(node, n, request_done)
req.start()
for time, callback in [
(1.0, lambda: make_request(5, nodes[1])),
Expand All @@ -77,7 +77,7 @@ def test_parallel_requests(self):
nodes = self.setupNetwork(5)
results = []
for n in range(1, N+1):
req = Request(nodes[n % 4], n, results.append)
req = Requester(nodes[n % 4], n, results.append)
self.network.set_timer(None, 1.0, req.start)

self.network.set_timer(None, 10.0, self.network.stop)
Expand All @@ -91,7 +91,7 @@ def test_failed_nodes(self):
nodes = self.setupNetwork(7)
results = []
for n in range(1, N+1):
req = Request(nodes[n % 3], n, results.append)
req = Requester(nodes[n % 3], n, results.append)
self.network.set_timer(None, n+1, req.start)

# kill nodes 3 and 4 at N/2 seconds
Expand All @@ -113,11 +113,11 @@ def identity(state, input):
nodes = self.setupNetwork(7, execute_fn=identity)
results = []
for n in range(1, N+1):
req = Request(nodes[n % 6], n, results.append)
req = Requester(nodes[n % 6], n, results.append)
self.network.set_timer(None, n+1, req.start)

# kill the leader node at N/2 seconds (it should be stable by then). Some of the
# Request roles were attached to this node, so we fake success of those requests
# Requester roles were attached to this node, so we fake success of those requests
# since we don't know what state they're in right now.
def is_leader(n):
try:
Expand Down
2 changes: 1 addition & 1 deletion cluster/test/test_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ def test_invoke(self):
sh = Member(self.state_machine, network=self.network,
peers=['p1', 'p2'], **self.cls_args)
res = sh.invoke('ROTATE', request_cls=FakeRequest)
self.assertEqual(sh.current_request, None)
self.assertEqual(sh.requester, None)
self.assertEqual(res, ('ROTATED', sh.node, 'ROTATE'))
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class Tests(utils.ComponentTestCase):
def setUp(self):
super(Tests, self).setUp()
self.callback = mock.Mock(name='callback')
with mock.patch.object(Request, 'client_ids') as client_ids:
with mock.patch.object(Requester, 'client_ids') as client_ids:
client_ids.next.return_value = CLIENT_ID
self.req = Request(self.node, 10, self.callback)
self.req = Requester(self.node, 10, self.callback)
self.assertEqual(self.req.client_id, CLIENT_ID)

def test_function(self):
"""Request should repeatedly send INVOKE until receiving a matching INVOKED"""
"""Requester should repeatedly send INVOKE until receiving a matching INVOKED"""
self.req.start()
self.assertMessage(['F999'], Invoke(caller='F999', client_id=CLIENT_ID, input_value=10))
self.network.tick(INVOKE_RETRANSMIT)
Expand Down

0 comments on commit f00975b

Please sign in to comment.