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

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