add docstrings for methods of PrimaryDecider and refactor them a bit
@@ -13,8 +13,6 @@ logger = getlogger()
class PrimaryDecider(HasActionQueue, MessageProcessor):
def __init__(self, node):
HasActionQueue.__init__(self)
- # TODO: How does primary decider ensure that a node does not have a
- # primary while its catching up
self.node = node
self.name = node.name
@@ -50,30 +48,36 @@ class PrimaryDecider(HasActionQueue, MessageProcessor):
def supported_msg_types(self) -> Iterable[type]:
return [k for k, v in self.routes]
- def decidePrimaries(self):
+ def decidePrimaries(self) -> None:
"""
- Choose the primary replica for each protocol instance in the system
- using a PrimaryDecider.
+ Start election of the primary replica for each protocol instance
"""
raise NotImplementedError
async def serviceQueues(self, limit):
# TODO: this should be abstract
- return 0
+ raise NotImplementedError
def viewChanged(self, viewNo: int):
- if viewNo > self.viewNo:
+ """
+ Notifies primary decider about the fact that view changed to let it
+ prepare for election, which then will be started from outside by
+ calling decidePrimaries()
+ """
+ if viewNo <= self.viewNo:
+ logger.warning("Provided view no {} is not greater than the "
+ "current view no {}".format(viewNo, self.viewNo))
+ return False
self.viewNo = viewNo
self.previous_master_primary = self.node.master_primary_name
for replica in self.replicas:
replica.primaryName = None
return True
- else:
- logger.warning("Provided view no {} is not greater than the "
- "current view no {}".format(viewNo, self.viewNo))
- return False
- def get_msgs_for_lagged_nodes(self) -> List[int]:
+ def get_msgs_for_lagged_nodes(self) -> List[object]:
+ """
+ Returns election messages from the last view change
+ """
raise NotImplementedError
def send(self, msg):
