Ejemplo n.º 1
0
    def __init__(self, _id, member_ids=None, timeout=0, random_num=None):
        self._id = _id

        if random_num is None:
            random_num = NativeRandomNumber(ServerProcess.MIN_ELECTION_TIMEOUT, 30)

        init_term = 0
        logs = []
        if member_ids is not None:
            config = Configuration(Configuration.STATE_STABLE)
            config.set_servers(member_ids)
            logs.append((init_term, config.to_log()))

        self._member_ids = list(member_ids)
        self._member_ids.remove(self._id)

        self._role = ServerProcess.Follower(
            self._id, random_num, logs, init_term, None, {}, -1, -1)
Ejemplo n.º 2
0
    def get_latest_config(logs):
        for _, entry in reversed(logs):
            if entry[0] == 'config':
                return Configuration.from_log(entry)

        return None