public virtual RaftMachine Build() { _termState.update(_term); LeaderAvailabilityTimers leaderAvailabilityTimers = new LeaderAvailabilityTimers(Duration.ofMillis(_electionTimeout), Duration.ofMillis(_heartbeatInterval), _clock, _timerService, _logProvider); SendToMyself leaderOnlyReplicator = new SendToMyself(_member, _outbound); RaftMembershipManager membershipManager = new RaftMembershipManager(leaderOnlyReplicator, _memberSetBuilder, _raftLog, _logProvider, _expectedClusterSize, leaderAvailabilityTimers.ElectionTimeout, _clock, _catchupTimeout, _raftMembership); membershipManager.RecoverFromIndexSupplier = () => 0; RaftLogShippingManager logShipping = new RaftLogShippingManager(_outbound, _logProvider, _raftLog, _timerService, _clock, _member, membershipManager, _retryTimeMillis, _catchupBatchSize, _maxAllowedShippingLag, _inFlightCache); RaftMachine raft = new RaftMachine(_member, _termStateStorage, _voteStateStorage, _raftLog, leaderAvailabilityTimers, _outbound, _logProvider, membershipManager, logShipping, _inFlightCache, false, false, _monitors); _inbound.registerHandler(incomingMessage => { try { ConsensusOutcome outcome = raft.Handle(incomingMessage); _commitListener.notifyCommitted(outcome.CommitIndex); } catch (IOException e) { throw new Exception(e); } }); try { membershipManager.Start(); } catch (IOException e) { throw new Exception(e); } return(raft); }
public RaftMachine(MemberId myself, StateStorage <TermState> termStorage, StateStorage <VoteState> voteStorage, RaftLog entryLog, LeaderAvailabilityTimers leaderAvailabilityTimers, Outbound <MemberId, RaftMessages_RaftMessage> outbound, LogProvider logProvider, RaftMembershipManager membershipManager, RaftLogShippingManager logShipping, InFlightCache inFlightCache, bool refuseToBecomeLeader, bool supportPreVoting, Monitors monitors) { this._myself = myself; this._leaderAvailabilityTimers = leaderAvailabilityTimers; this._outbound = outbound; this._logShipping = logShipping; this._log = logProvider.getLog(this.GetType()); this._membershipManager = membershipManager; this._inFlightCache = inFlightCache; this._state = new RaftState(myself, termStorage, membershipManager, entryLog, voteStorage, inFlightCache, logProvider, supportPreVoting, refuseToBecomeLeader); _raftMessageTimerResetMonitor = monitors.NewMonitor(typeof(RaftMessageTimerResetMonitor)); }