riaps.run.dc module
Distributed coordination
Python implementation of group formation, communications, leader election, consensus and action coordination.
Created on Feb 23, 2019 Author: riaps
- class riaps.run.dc.Coordinator(parent)[source]
Bases:
objectCoordinator object. Each component has a coordinator object that creates the group objects for a component. A group instance can be created only once in a component, subsequent creations return the same group object
- class riaps.run.dc.Group(parent, thread, groupType, groupInstance, componentId, groupSpec, groupMinSize)[source]
Bases:
objectGroup object, represents one group instance that belongs to a component. Acts as the front-end for the GroupThread, channels messages to/from. Some of its methods are run in the GroupThread
- GROUP_ACK = b'ack'
- GROUP_ANN = b'ann'
- GROUP_ERR = b'err'
- GROUP_LEL = b'lel'
- GROUP_LEX = b'lex'
- GROUP_MFL = b'mfl'
- GROUP_MJD = b'mjd'
- GROUP_MLT = b'mlt'
- GROUP_MSG = b'msg'
- GROUP_MTL = b'mtl'
- GROUP_NLD = b'nld'
- GROUP_PARAMETERS = {'consensusTimeout': 1500, 'electionMax': 2000, 'electionMin': 1500, 'heartbeat': 1000, 'peerTimeout': 3000}
- GROUP_RCM = b'rcm'
- GROUP_RFV = b'rfv'
- GROUP_RTC = b'rtc'
- GROUP_UPD = b'upd'
- groupSocketName(groupType, groupName, componentId)[source]
Forms the unique name for the inproc socket.
- handleMessage(msgFrames=None)[source]
Receives message from the worker thread and handles it Runs in component thread (called from component polling loop, or from send_port)
- recv()[source]
Receive a bytes object message from the worker thread Runs in component thread, called from a component
- recv_msg(is_pyobj)[source]
Receive a message from the worker thread. Message are coming through a message queue. Runs in component thread, called from a component
- recv_pyobj()[source]
Receive a Python object message from the worker thread Runs in component thread, called from a component
- requestVote(topic, kind='majority', timeout=None)[source]
Request a vote on a topic (with timeout). Topic is a bytes. A message is sent to the leader (if any) that starts a voting process. Returns None if there is no leader, otherwise a generated id string for the request.
- requestVote_pyobj(topic, kind='majority', timeout=None)[source]
Request a vote on a topic (with timeout). Topic is a Python object. A message is sent to the leader (if any) that starts a voting process. Returns None if there is no leader, otherwise a generated id string for the request.
- send(msg)[source]
Sends a bytes object as a message to all members of the group Runs in component thread
- sendToLeader(msg)[source]
Send message to group leader from a member Raise an exception if the group is not coordinated Return False (indicating operation failure) if no leader Runs in component thread.
- sendToLeader_pyobj(msg)[source]
Send PyObject message to group leader from a member Raise an exception if the group is not coordinated Return False (indicating operation failure) if no leader Runs in component thread.
- sendToMember(msg, identity=None)[source]
Send message to group member (with identity) from the leader If identity is not supplied, last value of identity is used. Raise an exception if the group is not coordinated Return False (indicating operation failure) if no leader Runs in component thread.
- sendToMember_pyobj(msg, identity=None)[source]
Send PyObject message to group member (with identity) from the leader If identity is not supplied, last value of identity is used. Raise an exception if the group is not coordinated Return False (indicating operation failure) if no leader Runs in component thread.
- sendVote(rfvId, vote)[source]
Send a vote (True/False) to the leader on a requested topic identified by the id of the request for vote.
- send_port(msgType, msg, has_identity=False)[source]
Send a message to the worker thread. Used by all messages - the messages have multiple frames Runs in component thread
- class riaps.run.dc.GroupThread(group)[source]
Bases:
ThreadWorker thread for DC behavior
- AUTHORITY = b'ldr'
- CANDIDATE = 2
- FOLLOWER = 1
- HEARTBEAT = b'tic'
- LEADER = 3
- NO_LEADER = 0
- REQVOTE = b'req'
- RSPVOTE = b'vot'
- handleNetMessage(now)[source]
Handle (broadcast) messages coming from the group. Messages could be data messages (to be handed over to the component), peer heartbeat messages, or election-related messages
- heartbeat(now)[source]
Send out a group heartbeat (so that group members can maintain an accurate membership list)