Beispiel #1
0
 public async Task <AppendEntriesResult> AppendEntriesAsync(AppendEntriesArguments request)
 {
     lock (_lock)
     {
         Log.Verbose("Recieved AppendEntriesAsync from {LeaderId}", request.LeaderId);
         if (request.Term > _currentTerm)
         {
             Log.Information("Term {Term} is greater than my term {CurrentTerm}, resetting to follower. Leader: {LeaderId}", request.Term, _currentTerm, request.LeaderId);
             _currentTerm = request.Term;
             _votedFor    = null;
             State        = NodeState.Follower;
         }
         if (request.Term == _currentTerm && State == NodeState.Candidate)
         {
             Log.Information("Term {Term} equals my term {CurrentTerm}, resetting to follower. Leader: {LeaderId}", request.Term, _currentTerm, request.LeaderId);
             _currentTerm = request.Term;
             _votedFor    = null;
             State        = NodeState.Follower;
         }
         if (request.Term == _currentTerm)
         {
             ResetElectionTimeout();
             // TODO: Implement me
         }
         return(new AppendEntriesResult
         {
             Term = _currentTerm,
             Success = false,
         });
     }
 }
Beispiel #2
0
        private async Task AppendEntries(string node)
        {
            try
            {
                int index   = Array.IndexOf(_nodes, node);
                var prevLog = _log.SingleOrDefault(l => l.Index == _nextIndex[index] - 1);

                if (_nextIndex[index] == _matchIndex[index])
                {
                    var request = new AppendEntriesArguments
                    {
                        Term         = _currentTerm,
                        LeaderId     = NodeName,
                        PrevLogIndex = prevLog?.Index ?? 0,
                        PrevLogTerm  = prevLog?.Term ?? 0,
                        Entries      = _log.Where(l => l.Index >= _nextIndex[index]).ToArray(),
                        LeaderCommit = _commitIndex
                    };
                    var result = await Communication.AppendEntriesAsync(node, request);
                }
                else
                {
                    // Don't send actual logs until we know how up-to-date the node is
                    var request = new AppendEntriesArguments
                    {
                        Term         = _currentTerm,
                        LeaderId     = NodeName,
                        PrevLogIndex = prevLog?.Index ?? 0,
                        PrevLogTerm  = prevLog?.Term ?? 0,
                        LeaderCommit = _commitIndex
                    };
                    var result = await Communication.AppendEntriesAsync(node, request);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Error in RequestVote");
            }
        }
Beispiel #3
0
 public async Task <AppendEntriesResult> AppendEntriesAsync(string destination, AppendEntriesArguments message)
 {
     return((AppendEntriesResult) await SendMessageAsync(destination, message));
 }
        public async Task <AppendEntriesResult> AppendEntriesAsync(string destination, AppendEntriesArguments message)
        {
            var communication = _communication.GetCommunication(destination);

            return(await communication.Server.AppendEntriesAsync(message));
        }