Exemple #1
0
 def debug_statistics(self):
     return {
         "node":
         lib.raft_get_nodeid(self.raft),
         "state":
         state2str(lib.raft_get_state(self.raft)),
         "current_idx":
         lib.raft_get_current_idx(self.raft),
         "last_log_term":
         lib.raft_get_last_log_term(self.raft),
         "current_term":
         lib.raft_get_current_term(self.raft),
         "commit_idx":
         lib.raft_get_commit_idx(self.raft),
         "last_applied_idx":
         lib.raft_get_last_applied_idx(self.raft),
         "log_count":
         lib.raft_get_log_count(self.raft),
         "peers":
         lib.raft_get_num_nodes(self.raft),
         "voting_peers":
         lib.raft_get_num_voting_nodes(self.raft),
         "connection_status":
         connectstatus2str(self.connection_status),
         "voting_change_in_progress":
         lib.raft_voting_change_is_in_progress(self.raft),
         "removed":
         getattr(self, 'removed', False),
     }
Exemple #2
0
    def _check_id_monoticity(self, ety):
        """
        Check last entry has smaller ID than new entry.
        This is a virtraft specific check to make sure entry passing is
        working correctly.
        """
        if ety.type == lib.RAFT_LOGTYPE_NO_OP:
            return

        ci = lib.raft_get_current_idx(self.raft)
        if 0 < ci and not lib.raft_get_snapshot_last_idx(self.raft) == ci:
            try:
                prev_ety = lib.raft_get_entry_from_idx(self.raft, ci)
                assert prev_ety
                if prev_ety.type == lib.RAFT_LOGTYPE_NO_OP:
                    if lib.raft_get_snapshot_last_idx(self.raft) != ci - 1:
                        lib.raft_entry_release(prev_ety)
                        prev_ety = lib.raft_get_entry_from_idx(
                            self.raft, ci - 1)
                        assert prev_ety
                    else:
                        lib.raft_entry_release(prev_ety)
                        return
                other_id = prev_ety.id
                assert other_id < ety.id
                lib.raft_entry_release(prev_ety)
            except Exception as e:
                logger.error(other_id, ety.id)
                self.abort_exception = e
                raise
Exemple #3
0
 def _check_current_idx_validity(self, server):
     """
     Check that current idx is valid, ie. it exists
     """
     ci = lib.raft_get_current_idx(server.raft)
     if 0 < ci and not lib.raft_get_snapshot_last_idx(server.raft) == ci:
         ety = lib.raft_get_entry_from_idx(server.raft, ci)
         try:
             assert ety
         except Exception:
             print('current idx ', ci)
             print('count', lib.raft_get_log_count(server.raft))
             print('last snapshot', lib.raft_get_snapshot_last_idx(server.raft))
             print(server.debug_log())
             raise
Exemple #4
0
 def _check_id_monoticity(self, ety):
     """
     Check last entry has smaller ID than new entry.
     This is a virtraft specific check to make sure entry passing is
     working correctly.
     """
     ci = lib.raft_get_current_idx(self.raft)
     if 0 < ci and not lib.raft_get_snapshot_last_idx(self.raft) == ci:
         try:
             prev_ety = lib.raft_get_entry_from_idx(self.raft, ci)
             assert prev_ety
             other_id = prev_ety.id
             assert other_id < ety.id
         except Exception as e:
             logging.error(other_id, ety.id)
             self.abort_exception = e
             raise