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
        internal CoreStatus(OutputFormat output, CoreGraphDatabase db) : base(output)
        {
            this._output = output;
            this._db     = db;

            DependencyResolver dependencyResolver = Db.DependencyResolver;

            this._raftMembershipManager        = dependencyResolver.ResolveDependency(typeof(RaftMembershipManager));
            this._databaseHealth               = dependencyResolver.ResolveDependency(typeof(DatabaseHealth));
            this._topologyService              = dependencyResolver.ResolveDependency(typeof(TopologyService));
            this._raftMachine                  = dependencyResolver.ResolveDependency(typeof(RaftMachine));
            this._raftMessageTimerResetMonitor = dependencyResolver.ResolveDependency(typeof(DurationSinceLastMessageMonitor));
            _commandIndexTracker               = dependencyResolver.ResolveDependency(typeof(CommandIndexTracker));
        }
Ejemplo n.º 3
0
        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));
        }