예제 #1
0
        internal ElectionContextImpl(InstanceId me, CommonContextState commonState, LogProvider logging, Timeouts timeouts, ClusterContext clusterContext, HeartbeatContext heartbeatContext, IList <ElectionRole> roles, IDictionary <string, Election> elections, ElectionCredentialsProvider electionCredentialsProvider) : base(me, commonState, logging, timeouts)
        {
            this._clusterContext              = clusterContext;
            this._heartbeatContext            = heartbeatContext;
            this._roles                       = roles;
            this._elections                   = elections;
            this._electionCredentialsProvider = electionCredentialsProvider;

            heartbeatContext.AddHeartbeatListener(this);
        }
예제 #2
0
        public virtual ElectionContextImpl Snapshot(CommonContextState commonStateSnapshot, LogProvider logging, Timeouts timeouts, ClusterContextImpl snapshotClusterContext, HeartbeatContextImpl snapshotHeartbeatContext, ElectionCredentialsProvider credentialsProvider)

        {
            IDictionary <string, Election> electionsSnapshot = new Dictionary <string, Election>();

            foreach (KeyValuePair <string, Election> election in _elections.SetOfKeyValuePairs())
            {
                electionsSnapshot[election.Key] = election.Value.snapshot();
            }

            return(new ElectionContextImpl(Me, commonStateSnapshot, logging, timeouts, snapshotClusterContext, snapshotHeartbeatContext, new List <ElectionRole>(_roles), electionsSnapshot, credentialsProvider));
        }
예제 #3
0
//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 ClusterClientModule(org.neo4j.kernel.lifecycle.LifeSupport life, org.neo4j.kernel.impl.util.Dependencies dependencies, final org.neo4j.kernel.monitoring.Monitors monitors, final org.neo4j.kernel.configuration.Config config, org.neo4j.logging.internal.LogService logService, org.neo4j.cluster.protocol.election.ElectionCredentialsProvider electionCredentialsProvider)
        public ClusterClientModule(LifeSupport life, Dependencies dependencies, Monitors monitors, Config config, LogService logService, ElectionCredentialsProvider electionCredentialsProvider)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.logging.LogProvider logging = org.neo4j.cluster.logging.AsyncLogging.provider(life, logService.getInternalLogProvider());
            LogProvider logging = AsyncLogging.provider(life, logService.InternalLogProvider);

            InternalLoggerFactory.DefaultFactory = new NettyLoggerFactory(logging);

            TimeoutStrategy timeoutStrategy = (new MessageTimeoutStrategy(new FixedTimeoutStrategy(config.Get(ClusterSettings.default_timeout).toMillis()))).timeout(HeartbeatMessage.sendHeartbeat, config.Get(ClusterSettings.heartbeat_interval).toMillis()).timeout(HeartbeatMessage.timed_out, config.Get(ClusterSettings.heartbeat_timeout).toMillis()).timeout(AtomicBroadcastMessage.broadcastTimeout, config.Get(ClusterSettings.broadcast_timeout).toMillis()).timeout(LearnerMessage.learnTimedout, config.Get(ClusterSettings.learn_timeout).toMillis()).timeout(ProposerMessage.phase1Timeout, config.Get(ClusterSettings.phase1_timeout).toMillis()).timeout(ProposerMessage.phase2Timeout, config.Get(ClusterSettings.phase2_timeout).toMillis()).timeout(ClusterMessage.joiningTimeout, config.Get(ClusterSettings.join_timeout).toMillis()).timeout(ClusterMessage.configurationTimeout, config.Get(ClusterSettings.configuration_timeout).toMillis()).timeout(ClusterMessage.leaveTimedout, config.Get(ClusterSettings.leave_timeout).toMillis()).timeout(ElectionMessage.electionTimeout, config.Get(ClusterSettings.election_timeout).toMillis());

            MultiPaxosServerFactory protocolServerFactory = new MultiPaxosServerFactory(new ClusterConfiguration(config.Get(ClusterSettings.cluster_name), logging), logging, monitors.NewMonitor(typeof(StateMachines.Monitor)));

            NetworkReceiver receiver = dependencies.satisfyDependency(new NetworkReceiver(monitors.NewMonitor(typeof(NetworkReceiver.Monitor)), new ConfigurationAnonymousInnerClass(this, config)
                                                                                          , logging));

//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.protocol.atomicbroadcast.ObjectInputStreamFactory objectInputStreamFactory = new org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory();
            ObjectInputStreamFactory objectInputStreamFactory = new ObjectStreamFactory();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.neo4j.cluster.protocol.atomicbroadcast.ObjectOutputStreamFactory objectOutputStreamFactory = new org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory();
            ObjectOutputStreamFactory objectOutputStreamFactory = new ObjectStreamFactory();

            receiver.AddNetworkChannelsListener(new NetworkChannelsListenerAnonymousInnerClass(this, logging, objectInputStreamFactory, objectOutputStreamFactory));

            NetworkSender sender = dependencies.satisfyDependency(new NetworkSender(monitors.NewMonitor(typeof(NetworkSender.Monitor)), new ConfigurationAnonymousInnerClass(this, config)
                                                                                    , receiver, logging));

            ExecutorLifecycleAdapter stateMachineExecutor = new ExecutorLifecycleAdapter(() => Executors.newSingleThreadExecutor(new NamedThreadFactory("State machine", monitors.NewMonitor(typeof(NamedThreadFactory.Monitor)))));

            AcceptorInstanceStore acceptorInstanceStore = new InMemoryAcceptorInstanceStore();

            _server = protocolServerFactory.NewProtocolServer(config.Get(ClusterSettings.server_id), timeoutStrategy, receiver, sender, acceptorInstanceStore, electionCredentialsProvider, stateMachineExecutor, objectInputStreamFactory, objectOutputStreamFactory, config);

            life.Add(sender);
            life.Add(stateMachineExecutor);
            life.Add(receiver);

            // Timeout timer - triggers every 10 ms
            life.Add(new TimeoutTrigger(_server, monitors));

            life.add(new ClusterJoin(new ConfigurationAnonymousInnerClass(this, config)
                                     , _server, logService));

            ClusterClient = dependencies.SatisfyDependency(new ClusterClient(life, _server));
        }
예제 #4
0
        public TestProtocolServer(LogProvider logProvider, TimeoutStrategy timeoutStrategy, ProtocolServerFactory factory, URI serverUri, InstanceId instanceId, AcceptorInstanceStore acceptorInstanceStore, ElectionCredentialsProvider electionCredentialsProvider)
        {
            this._serverUri = serverUri;
            this.Receiver   = new TestMessageSource(this);
            this.Sender     = new TestMessageSender(this);

            _stateMachineExecutor = new DelayedDirectExecutor(logProvider);

            Config config = mock(typeof(Config));

            when(config.Get(ClusterSettings.MaxAcceptors)).thenReturn(10);
            when(config.Get(ClusterSettings.StrictInitialHosts)).thenReturn(false);

            ServerConflict = factory.NewProtocolServer(instanceId, timeoutStrategy, Receiver, Sender, acceptorInstanceStore, electionCredentialsProvider, _stateMachineExecutor, new ObjectStreamFactory(), new ObjectStreamFactory(), config);

            ServerConflict.listeningAt(serverUri);
        }
예제 #5
0
        public MultiPaxosContext(InstanceId me, IEnumerable <ElectionRole> roles, ClusterConfiguration configuration, Executor executor, LogProvider logging, ObjectInputStreamFactory objectInputStreamFactory, ObjectOutputStreamFactory objectOutputStreamFactory, AcceptorInstanceStore instanceStore, Timeouts timeouts, ElectionCredentialsProvider electionCredentialsProvider, Config config)
        {
            _commonState    = new CommonContextState(configuration, config.Get(ClusterSettings.max_acceptors));
            _paxosInstances = new PaxosInstanceStore();

            _heartbeatContext       = new HeartbeatContextImpl(me, _commonState, logging, timeouts, executor);
            _learnerContext         = new LearnerContextImpl(me, _commonState, logging, timeouts, _paxosInstances, instanceStore, objectInputStreamFactory, objectOutputStreamFactory, _heartbeatContext);
            _clusterContext         = new ClusterContextImpl(me, _commonState, logging, timeouts, executor, objectOutputStreamFactory, objectInputStreamFactory, _learnerContext, _heartbeatContext, config);
            _electionContext        = new ElectionContextImpl(me, _commonState, logging, timeouts, roles, _clusterContext, _heartbeatContext, electionCredentialsProvider);
            _proposerContext        = new ProposerContextImpl(me, _commonState, logging, timeouts, _paxosInstances, _heartbeatContext);
            _acceptorContext        = new AcceptorContextImpl(me, _commonState, logging, timeouts, instanceStore);
            _atomicBroadcastContext = new AtomicBroadcastContextImpl(me, _commonState, logging, timeouts, executor, _heartbeatContext);

            _heartbeatContext.setCircularDependencies(_clusterContext, _learnerContext);
        }
예제 #6
0
        /// <summary>
        /// Create a state snapshot. The snapshot will not duplicate services, and expects the caller to duplicate
        /// <seealso cref="AcceptorInstanceStore"/>, since that is externally provided.
        /// </summary>
        public virtual MultiPaxosContext Snapshot(LogProvider logging, Timeouts timeouts, Executor executor, AcceptorInstanceStore instanceStore, ObjectInputStreamFactory objectInputStreamFactory, ObjectOutputStreamFactory objectOutputStreamFactory, ElectionCredentialsProvider electionCredentialsProvider)
        {
            CommonContextState commonStateSnapshot    = _commonState.snapshot(logging.GetLog(typeof(ClusterConfiguration)));
            PaxosInstanceStore paxosInstancesSnapshot = _paxosInstances.snapshot();

            HeartbeatContextImpl       snapshotHeartbeatContext       = _heartbeatContext.snapshot(commonStateSnapshot, logging, timeouts, executor);
            LearnerContextImpl         snapshotLearnerContext         = _learnerContext.snapshot(commonStateSnapshot, logging, timeouts, paxosInstancesSnapshot, instanceStore, objectInputStreamFactory, objectOutputStreamFactory, snapshotHeartbeatContext);
            ClusterContextImpl         snapshotClusterContext         = _clusterContext.snapshot(commonStateSnapshot, logging, timeouts, executor, objectOutputStreamFactory, objectInputStreamFactory, snapshotLearnerContext, snapshotHeartbeatContext);
            ElectionContextImpl        snapshotElectionContext        = _electionContext.snapshot(commonStateSnapshot, logging, timeouts, snapshotClusterContext, snapshotHeartbeatContext, electionCredentialsProvider);
            ProposerContextImpl        snapshotProposerContext        = _proposerContext.snapshot(commonStateSnapshot, logging, timeouts, paxosInstancesSnapshot, _heartbeatContext);
            AcceptorContextImpl        snapshotAcceptorContext        = _acceptorContext.snapshot(commonStateSnapshot, logging, timeouts, instanceStore);
            AtomicBroadcastContextImpl snapshotAtomicBroadcastContext = _atomicBroadcastContext.snapshot(commonStateSnapshot, logging, timeouts, executor, snapshotHeartbeatContext);

            snapshotHeartbeatContext.SetCircularDependencies(snapshotClusterContext, snapshotLearnerContext);

            return(new MultiPaxosContext(snapshotProposerContext, snapshotAcceptorContext, snapshotLearnerContext, snapshotHeartbeatContext, snapshotElectionContext, snapshotAtomicBroadcastContext, commonStateSnapshot, paxosInstancesSnapshot, snapshotClusterContext));
        }