Skip to content
Snippets Groups Projects
Commit 2336d9d6 authored by WinJ's avatar WinJ
Browse files

type declaration

parent fcd2134c
No related branches found
No related tags found
No related merge requests found
# http://pymotw.com/2/SocketServer/
from functools import total_ordering
from typing import Dict, Set, Tuple, DefaultDict
from message import *
import socketserver
import pickle
......@@ -14,24 +16,22 @@ class Paxos(socketserver.TCPServer):
self.servers = servers # All servers addresses
# Sets up other variables
self.is_leader = False # Are we the leader?
self.ballot = BallotNumber(1, self.address) # Our ballot number
self.highest_ballot_seen = BallotNumber(0, self.address) # Highest ballot number seen
self.proposals = dict() # Used by leader to send P2A to acceptors
self.accepted = dict() # Used by acceptors in P2A and also P1B
self.log = dict() # The log
self.leader_recent_ping = False
self.is_leader: bool = False # Are we the leader?
self.ballot: BallotNumber = BallotNumber(1, self.address) # Our ballot number
self.highestBallotSeen: BallotNumber = BallotNumber(0, self.address) # Highest ballot number seen
self.proposals: Dict[int, BallotValuePair] = dict() # Used by leader to send P2A to acceptors, slot number -> proposal
self.accepted: Dict[int, BallotValuePair] = dict() # Used by acceptors in P2A and also P1B, slot number -> proposal
self.log: Dict[int, BallotValuePair] = dict() # The log
self.leader_recent_ping: bool = False # True if we think leader is alive
# for proposal phase
self.slot_in = 1 # First non-executed proposal slot (+1 last executed slot)
self.slot_out = 1 # First empty slot (+1 last proposed slot)
# Multimap equivalent in python is defaultdict: https://stackoverflow.com/questions/1731971/is-there-a-multimap-implementation-in-python
self.slot_to_acceptors = defaultdict(set) # Used by leader to decide majority for each slot after P2B
self.slot_in: int = 1 # First non-executed proposal slot (+1 last executed slot)
self.slot_out: int = 1 # First empty slot (+1 last proposed slot)
self.slot_to_acceptors: DefaultDict[int, Set[Tuple[str, int]]] = defaultdict(set) # Used by leader to decide majority for each slot after P2B, Multimap<Integer, Address>
# for leader election
self.voters = set() # Yes votes for leader election
self.p1b_replies = dict() # Accepted values for each slot by acceptors that voted yes
self.voters: Set[Tuple[str, int]] = set() # Yes votes for leader election
self.p1b_replies: Dict[int, BallotValuePair] = dict() # Accepted values for each slot by acceptors that voted yes, slot number -> proposal
# ...
# Default leader during setup
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment