Пример #1
0
        //protected override bool VoteRequest(Client client, VoteRequest request)
        //{
        //    if (StepDown(request.Term))
        //        return false;

        //    client.SendVoteReply(false);
        //    return true;
        //}

        protected override bool VoteReply(Client client, VoteReply reply)
        {
            if (StepDown(reply.Term))
                return true;

            client.RpcDue = long.MaxValue;
            client.VoteGranted = reply.Granted;
            Console.WriteLine("{0}: Peer {1} voted {2}", _server.Name, client.ID, reply.Granted);
            return true;
        }
Пример #2
0
 protected override bool VoteReply(Client client, VoteReply reply)
 {
     return true;
 }
Пример #3
0
 protected abstract bool VoteReply(Client client, VoteReply reply);
Пример #4
0
        //public bool VoteRequest(VoteRequest request)
        //{
        //    var client = _server.GetClient(request.From);
        //    return VoteRequest(client, request);
        //}

        public bool VoteReply(VoteReply reply)
        {
            var client = _server.GetClient(reply.From);
            return VoteReply(client, reply);
        }
Пример #5
0
 protected override bool VoteReply(Client client, VoteReply reply)
 {
     StepDown(reply.Term);
     return true;
 }
Пример #6
0
        //public void SendRequest(Peer peer, StatusRequest request)
        //{
        //    SendMessage(peer, request);
        //}

        public void SendReply(Peer peer, VoteReply reply)
        {
            SendMessage(peer, reply);
        }
Пример #7
0
 protected override bool VoteReply(Client client, VoteReply reply)
 {
     LastMessage = reply;
     LastClient = client;
     return true;
 }
Пример #8
0
        //protected override bool VoteRequest(Client client, VoteRequest request)
        //{
        //    var _persistedState = _server.PersistedStore;
        //    if (_persistedState.Term < request.Term)
        //    {
        //        _persistedState.Term = request.Term;
        //        if (_heatbeatTimeout <= _server.Tick)
        //            resetHeartbeat();
        //    }

        //    var ourLastLogTerm = _persistedState.GetLastTerm();
        //    var termCheck = _persistedState.Term == request.Term;
        //    var canVote = _persistedState.VotedFor == null || _persistedState.VotedFor == request.From;
        //    var ourLogIsBetter = _persistedState.LogIsBetter(request.LogLength, request.LastTerm);
        //    //var logTermFurther = request.LastTerm > ourLastLogTerm;
        //    //var logIndexLonger = request.LastTerm == ourLastLogTerm && request.LogLength >= _persistedState.Length;
        //    var granted = termCheck && canVote && !ourLogIsBetter;

        //    if (!termCheck)
        //        Console.WriteLine("{0}: Can not vote for {1} because term {2}, expected {3}", _server.Name, client.ID, request.Term, _persistedState.Term);

        //    if (!canVote)
        //        Console.WriteLine("{0}: Can not vote for {1} because I already voted for {2}", _server.Name, client.ID, _persistedState.VotedFor);

        //    if (ourLogIsBetter)
        //        Console.WriteLine("{0}: Can not vote for {1} because my log is more update to date", _server.Name, client.ID);

        //    if (granted)
        //    {
        //        Console.WriteLine("{0}: Voted for {1}", _server.Name, client.ID);
        //        _persistedState.VotedFor = client.ID;
        //        _leader = null;
        //        resetHeartbeat();
        //    }

        //    client.SendVoteReply(granted);
        //    return true;
        //}

        protected override bool VoteReply(Client client, VoteReply reply)
        {
            //we aren't looking for votes, ignore
            return true;
        }
Пример #9
0
        protected void handleRequestVoteReply(IConsensus model, VoteReply reply)
        {
            if (_persistedState.Term < reply.Term)
                stepDown(model, reply.Term);

            if (_state == ServerState.Candidate && _persistedState.Term == reply.Term)
            {
                var peer = _peers.First(x => x.ID == reply.From);
                peer.RpcDue = int.MaxValue;
                peer.VoteGranted = reply.Granted;

                //Console.WriteLine("{0}: Peer {1} voted {2}", _id, peer.ID, peer.VotedGranted);
            }
        }