Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 public RaftMembershipManager(SendToMyself sendToMyself, RaftGroup_Builder <MemberId> memberSetBuilder, ReadableRaftLog raftLog, LogProvider logProvider, int minimumConsensusGroupSize, long electionTimeout, Clock clock, long catchupTimeout, StateStorage <RaftMembershipState> membershipStorage)
 {
     this._sendToMyself              = sendToMyself;
     this._memberSetBuilder          = memberSetBuilder;
     this._raftLog                   = raftLog;
     this._minimumConsensusGroupSize = minimumConsensusGroupSize;
     this._storage                   = membershipStorage;
     this._log = logProvider.getLog(this.GetType());
     this._membershipChanger = new RaftMembershipChanger(raftLog, clock, electionTimeout, logProvider, catchupTimeout, this);
 }