Пример #1
0
 public override Task <VoteResult> Vote(VoteRequest request)
 {
     if (!GrantVotes)
     {
         return(Task.FromResult(new VoteResult(Term, false)));
     }
     return(base.Vote(request));
 }
Пример #2
0
 public override Task<VoteResult> Vote(VoteRequest request)
 {
     if (!GrantVotes)
     {
         return Task.FromResult(new VoteResult(Term, false));
     }
     return base.Vote(request);
 }
Пример #3
0
            public async Task <VoteResult> Vote(VoteRequest request)
            {
                if (request.Term < node.Term)
                {
                    return(new VoteResult(node.Term, false));
                }
                //this needs some sort of lock around it. although it would be very rare in a deployed system, the nodes in unit tests have hit
                //this block at the exact same time, resulting in both nodes getting the vote.
                //using a lock for now. should be replaced at some point with interlocked for perf
                lock (node.grantVoteLocker)
                {
                    if (request.Term > node.Term)
                    {
                        node.StepDown(node.Term, request.Id);
                    }

                    return(new VoteResult(node.Term, false));
                }
            }
Пример #4
0
            public async Task<VoteResult> Vote(VoteRequest request)
            {
                if (request.Term < node.Term)
                {
                    return new VoteResult(node.Term, false);
                }
                //this needs some sort of lock around it. although it would be very rare in a deployed system, the nodes in unit tests have hit
                //this block at the exact same time, resulting in both nodes getting the vote.
                //using a lock for now. should be replaced at some point with interlocked for perf
                lock (node.grantVoteLocker)
                {
                    if (request.Term > node.Term)
                    {
                        node.StepDown(node.Term, request.Id);
                    }

                    return new VoteResult(node.Term, false);
                }
            }
Пример #5
0
            public async Task <VoteResult> Vote(VoteRequest request)
            {
                if (request.Term < node.Term)
                {
                    return(new VoteResult(node.Term, false));
                }
                //this needs some sort of lock around it. although it would be very rare in a deployed system, the nodes in unit tests have hit
                //this block at the exact same time, resulting in both nodes getting the vote.
                //using a lock for now. should be replaced at some point with interlocked for perf
                lock (node.grantVoteLocker)
                {
                    if (node.CurrentLeader == null || node.CurrentLeader == request.Id)
                    {
                        Debug.WriteLine("{0}: Voting for {1} for term {2}", node.NodeInfo(), request.Id, request.Term);
                        node.requestHandler = new Follower(node);
                        node.CurrentLeader  = request.Id;
                        node.Term           = request.Term;
                        node.lastHeartBeat  = node.settings.Scheduler.Now;
                        return(new VoteResult(node.Term, true));
                    }

                    return(new VoteResult(node.Term, false));
                }
            }
Пример #6
0
            public async Task<VoteResult> Vote(VoteRequest request)
            {
                if (request.Term < node.Term)
                {
                    return new VoteResult(node.Term, false);
                }
                //this needs some sort of lock around it. although it would be very rare in a deployed system, the nodes in unit tests have hit
                //this block at the exact same time, resulting in both nodes getting the vote.
                //using a lock for now. should be replaced at some point with interlocked for perf
                lock (node.grantVoteLocker)
                {
                    if (node.CurrentLeader == null || node.CurrentLeader == request.Id)
                    {
                        Debug.WriteLine("{0}: Voting for {1} for term {2}", node.NodeInfo(), request.Id, request.Term);
                        node.requestHandler = new Follower(node);
                        node.CurrentLeader = request.Id;
                        node.Term = request.Term;
                        node.lastHeartBeat = node.settings.Scheduler.Now;
                        return new VoteResult(node.Term, true);
                    }

                    return new VoteResult(node.Term, false);
                }
            }
Пример #7
0
 public async Task <VoteResult> RequestVote(VoteRequest request)
 {
     return(await requestVote(request));
 }
Пример #8
0
 public virtual async Task <VoteResult> Vote(VoteRequest request)
 {
     return(await requestHandler.Vote(request));
 }
Пример #9
0
 public async Task<VoteResult> RequestVote(VoteRequest request)
 {
     var voteResult = await requestVote(request);
     return voteResult;
 }
Пример #10
0
        public async Task <VoteResult> RequestVote(VoteRequest request)
        {
            var voteResult = await requestVote(request);

            return(voteResult);
        }
Пример #11
0
 public virtual async Task<VoteResult> Vote(VoteRequest request)
 {
     return await requestHandler.Vote(request);
 }