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)); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: //ORIGINAL LINE: public ConsensusModule(org.neo4j.causalclustering.identity.MemberId myself, final org.neo4j.graphdb.factory.module.PlatformModule platformModule, org.neo4j.causalclustering.messaging.Outbound<org.neo4j.causalclustering.identity.MemberId,RaftMessages_RaftMessage> outbound, java.io.File clusterStateDirectory, org.neo4j.causalclustering.discovery.CoreTopologyService coreTopologyService) public ConsensusModule(MemberId myself, PlatformModule platformModule, Outbound <MemberId, RaftMessages_RaftMessage> outbound, File clusterStateDirectory, CoreTopologyService coreTopologyService) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.configuration.Config config = platformModule.config; Config config = platformModule.Config; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.logging.internal.LogService logging = platformModule.logging; LogService logging = platformModule.Logging; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.io.fs.FileSystemAbstraction fileSystem = platformModule.fileSystem; FileSystemAbstraction fileSystem = platformModule.FileSystem; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.kernel.lifecycle.LifeSupport life = platformModule.life; LifeSupport life = platformModule.Life; LogProvider logProvider = logging.InternalLogProvider; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.causalclustering.core.state.storage.SafeChannelMarshal<org.neo4j.causalclustering.core.replication.ReplicatedContent> marshal = org.neo4j.causalclustering.messaging.marshalling.CoreReplicatedContentMarshal.marshaller(); SafeChannelMarshal <ReplicatedContent> marshal = CoreReplicatedContentMarshal.marshaller(); RaftLog underlyingLog = CreateRaftLog(config, life, fileSystem, clusterStateDirectory, marshal, logProvider, platformModule.JobScheduler); _raftLog = new MonitoredRaftLog(underlyingLog, platformModule.Monitors); StateStorage <TermState> termState; StateStorage <VoteState> voteState; StateStorage <RaftMembershipState> raftMembershipStorage; StateStorage <TermState> durableTermState = life.Add(new DurableStateStorage <TermState>(fileSystem, clusterStateDirectory, RAFT_TERM_NAME, new TermState.Marshal(), config.Get(CausalClusteringSettings.term_state_size), logProvider)); termState = new MonitoredTermStateStorage(durableTermState, platformModule.Monitors); voteState = life.Add(new DurableStateStorage <>(fileSystem, clusterStateDirectory, RAFT_VOTE_NAME, new VoteState.Marshal(new MemberId.Marshal()), config.Get(CausalClusteringSettings.vote_state_size), logProvider)); raftMembershipStorage = life.Add(new DurableStateStorage <>(fileSystem, clusterStateDirectory, RAFT_MEMBERSHIP_NAME, new RaftMembershipState.Marshal(), config.Get(CausalClusteringSettings.raft_membership_state_size), logProvider)); TimerService timerService = new TimerService(platformModule.JobScheduler, logProvider); _leaderAvailabilityTimers = CreateElectionTiming(config, timerService, logProvider); int?minimumConsensusGroupSize = config.Get(CausalClusteringSettings.minimum_core_cluster_size_at_runtime); MemberIdSetBuilder memberSetBuilder = new MemberIdSetBuilder(); SendToMyself leaderOnlyReplicator = new SendToMyself(myself, outbound); _raftMembershipManager = new RaftMembershipManager(leaderOnlyReplicator, memberSetBuilder, _raftLog, logProvider, minimumConsensusGroupSize.Value, _leaderAvailabilityTimers.ElectionTimeout, systemClock(), config.Get(join_catch_up_timeout).toMillis(), raftMembershipStorage); platformModule.Dependencies.satisfyDependency(_raftMembershipManager); life.Add(_raftMembershipManager); _inFlightCache = InFlightCacheFactory.create(config, platformModule.Monitors); RaftLogShippingManager logShipping = new RaftLogShippingManager(outbound, logProvider, _raftLog, timerService, systemClock(), myself, _raftMembershipManager, _leaderAvailabilityTimers.ElectionTimeout, config.Get(catchup_batch_size), config.Get(log_shipping_max_lag), _inFlightCache); bool supportsPreVoting = config.Get(CausalClusteringSettings.enable_pre_voting); _raftMachine = new RaftMachine(myself, termState, voteState, _raftLog, _leaderAvailabilityTimers, outbound, logProvider, _raftMembershipManager, logShipping, _inFlightCache, config.Get(refuse_to_be_leader), supportsPreVoting, platformModule.Monitors); DurationSinceLastMessageMonitor durationSinceLastMessageMonitor = new DurationSinceLastMessageMonitor(); platformModule.Monitors.addMonitorListener(durationSinceLastMessageMonitor); platformModule.Dependencies.satisfyDependency(durationSinceLastMessageMonitor); string dbName = config.Get(CausalClusteringSettings.database); life.Add(new RaftCoreTopologyConnector(coreTopologyService, _raftMachine, dbName)); life.Add(logShipping); }