Beispiel #1
0
 public override Task <VoteResult> Vote(VoteRequest request)
 {
     if (!GrantVotes)
     {
         return(Task.FromResult(new VoteResult(Term, false)));
     }
     return(base.Vote(request));
 }
Beispiel #2
0
 public override Task<VoteResult> Vote(VoteRequest request)
 {
     if (!GrantVotes)
     {
         return Task.FromResult(new VoteResult(Term, false));
     }
     return base.Vote(request);
 }
Beispiel #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));
                }
            }
Beispiel #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);
                }
            }
Beispiel #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));
                }
            }
Beispiel #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);
                }
            }
Beispiel #7
0
 public async Task <VoteResult> RequestVote(VoteRequest request)
 {
     return(await requestVote(request));
 }
Beispiel #8
0
 public virtual async Task <VoteResult> Vote(VoteRequest request)
 {
     return(await requestHandler.Vote(request));
 }
Beispiel #9
0
 public async Task<VoteResult> RequestVote(VoteRequest request)
 {
     var voteResult = await requestVote(request);
     return voteResult;
 }
Beispiel #10
0
        public async Task <VoteResult> RequestVote(VoteRequest request)
        {
            var voteResult = await requestVote(request);

            return(voteResult);
        }
Beispiel #11
0
 public virtual async Task<VoteResult> Vote(VoteRequest request)
 {
     return await requestHandler.Vote(request);
 }