Пример #1
0
        public RaftEngineOptions(NodeConnectionInfo connection, StorageEnvironmentOptions storageOptions, ITransport transport, IRaftStateMachine stateMachine)
        {
            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }
            if (String.IsNullOrWhiteSpace(connection.Name))
            {
                throw new ArgumentNullException("connection.Name");
            }
            if (storageOptions == null)
            {
                throw new ArgumentNullException("storageOptions");
            }
            if (transport == null)
            {
                throw new ArgumentNullException("transport");
            }
            if (stateMachine == null)
            {
                throw new ArgumentNullException("stateMachine");
            }

            SelfConnection               = connection;
            StorageOptions               = storageOptions;
            Transport                    = transport;
            StateMachine                 = stateMachine;
            ElectionTimeout              = 1200;
            HeartbeatTimeout             = 300;
            Stopwatch                    = new Stopwatch();
            MaxLogLengthBeforeCompaction = 32 * 1024;
            MaxStepDownDrainTime         = TimeSpan.FromSeconds(15);
            MaxEntriesPerRequest         = 256;
        }
Пример #2
0
 internal LeaderState(IRaftStateMachine stateMachine, bool allowPartitioning, long term)
     : base(stateMachine)
 {
     currentTerm            = term;
     this.allowPartitioning = allowPartitioning;
     timerCancellation      = new CancellationTokenSource();
     forcedReplication      = new AsyncManualResetEvent(false);
 }
Пример #3
0
 internal LeaderState(IRaftStateMachine stateMachine, bool allowPartitioning, long term)
     : base(stateMachine)
 {
     currentTerm            = term;
     this.allowPartitioning = allowPartitioning;
     timerCancellation      = new CancellationTokenSource();
     processingState        = new AtomicBoolean(false);
 }
Пример #4
0
 internal LeaderState(IRaftStateMachine stateMachine, bool allowPartitioning, long term)
     : base(stateMachine)
 {
     currentTerm            = term;
     this.allowPartitioning = allowPartitioning;
     timerCancellation      = new();
     replicationEvent       = new();
     replicationQueue       = new();
     precedingTermCache     = new TermCache(MaxTermCacheSize);
 }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RaftNode"/> class.
        /// </summary>
        /// <param name="nodeId">The node's ID</param>
        /// <param name="stateMachine"><see cref="IRaftStateMachine"/> to replicate</param>
        public RaftNode(uint nodeId, IRaftStateMachine stateMachine)
        {
            this.NodeId       = nodeId;
            this.StateMachine = stateMachine;
            this.Log          = new List <LogEntry>();

            electionTimer  = new Timer(TriggerElection);
            heartbeatTimer = new Timer(SendHeartbeats);

            NextIndex  = new Dictionary <uint, int>();
            MatchIndex = new Dictionary <uint, int>();
        }
Пример #6
0
		public RaftEngineOptions(NodeConnectionInfo connection, StorageEnvironmentOptions storageOptions, ITransport transport, IRaftStateMachine stateMachine)
		{
			if (connection == null) throw new ArgumentNullException("connection");
			if (String.IsNullOrWhiteSpace(connection.Name)) throw new ArgumentNullException("connection.Name");
			if (storageOptions == null) throw new ArgumentNullException("storageOptions");
			if (transport == null) throw new ArgumentNullException("transport");
			if (stateMachine == null) throw new ArgumentNullException("stateMachine");

			SelfConnection = connection;
			StorageOptions = storageOptions;
			Transport = transport;
			StateMachine = stateMachine;
			ElectionTimeout = 1200;
			HeartbeatTimeout = 300;
			Stopwatch = new Stopwatch();
			MaxLogLengthBeforeCompaction = 32 * 1024;
			MaxStepDownDrainTime = TimeSpan.FromSeconds(15);
			MaxEntriesPerRequest = 256;
		}
 internal CandidateState(IRaftStateMachine stateMachine, long term)
     : base(stateMachine)
 {
     votingCancellation = new CancellationTokenSource();
     Term = term;
 }
 internal FollowerState(IRaftStateMachine stateMachine)
     : base(stateMachine)
 {
     refreshEvent        = new AsyncAutoResetEvent(false);
     trackerCancellation = new CancellationTokenSource();
 }
Пример #9
0
 private protected RaftState(IRaftStateMachine stateMachine) => this.stateMachine = stateMachine;
Пример #10
0
 internal StandbyState(IRaftStateMachine stateMachine)
     : base(stateMachine)
 {
 }
Пример #11
0
 internal FollowerState(IRaftStateMachine stateMachine)
     : base(stateMachine)
 {
     refreshEvent = new AutoResetEvent(false);
 }