public override async Task <AppendEntriesResult> AppendEntries(AppendEntriesRequest request) { if (SleepOnAppendEntries) { await Task.Delay(Timeout.Infinite); } return(await base.AppendEntries(request)); }
public override async Task<AppendEntriesResult> AppendEntries(AppendEntriesRequest request) { if (SleepOnAppendEntries) { await Task.Delay(Timeout.Infinite); } return await base.AppendEntries(request); }
public async Task<AppendEntriesResult> AppendEntries(AppendEntriesRequest request) { Debug.WriteLine("{0}: GOT APPEND ENTRIES CALL {1}: leader commit {2} : entries: {3}", node.NodeInfo(), request.Id, request.CommitIndex, String.Concat(request.Entries.Select(e => e.Log + " "))); if (request.Term <= node.Term) { return new AppendEntriesResult(node.Term, false); } node.CurrentLeader = request.Id; node.requestHandler = new Follower(node); node.Term = request.Term; node.lastHeartBeat = node.settings.Scheduler.Now; return await node.requestHandler.AppendEntries(request); }
public async Task <AppendEntriesResult> AppendEntries(AppendEntriesRequest request) { Debug.WriteLine("{0}: GOT APPEND ENTRIES CALL {1}: leader commit {2} : entries: {3}", node.NodeInfo(), request.Id, request.CommitIndex, String.Concat(request.Entries.Select(e => e.Log + " "))); if (request.Term <= node.Term) { return(new AppendEntriesResult(node.Term, false)); } node.CurrentLeader = request.Id; node.requestHandler = new Follower(node); node.Term = request.Term; node.lastHeartBeat = node.settings.Scheduler.Now; return(await node.requestHandler.AppendEntries(request)); }
public async Task <AppendEntriesResult> AppendEntries(AppendEntriesRequest request) { Debug.WriteLine("{0}: GOT APPEND ENTRIES CALL {1}: leader commit {2} : entries: {3}", node.NodeInfo(), request.Id, request.CommitIndex, String.Concat(request.Entries.Select(e => e.Log + " "))); if (request.Term < node.Term) { return(new AppendEntriesResult(node.Term, false)); } node.CurrentLeader = request.Id; node.Term = request.Term; node.lastHeartBeat = node.settings.Scheduler.Now; if (request.Entries == null || !request.Entries.Any()) //heartbeat { if (request.CommitIndex > node.ServerLog.LastIndex) { Debug.WriteLine("{0}: HeartBeat Adding To Server Log up to index {1} leaderCommitIndex {2}", node.NodeInfo(), request.PreviousLogIndex, request.CommitIndex); node.LocalLog.Entries.Where(e => e.Index > node.ServerLog.LastIndex && e.Index <= request.CommitIndex).ForEach(e => node.ServerLog.Add(e.Term, e.Log)); } return(new AppendEntriesResult(node.Term, true)); } if (request.PreviousLogIndex == 0 || (request.PreviousLogIndex <= node.ServerLog.LastIndex && node.ServerLog.LastTerm == request.PreviousLogTerm)) { Debug.WriteLine("{0}: huh"); } //reply false if log doesnt contain an entry at prevLogIndex whose node.term matches prevlogTerm if (!node.LocalLog.Entries.Any(e => e.Index == request.PreviousLogIndex && e.Term == request.PreviousLogTerm)) //not to sure about this line yet { Debug.WriteLine("follower node.LocalLog doesnt contain an entry at request.prevLogIndex({0}) whose node.term matches request.prevlogTerm{1}", request.PreviousLogIndex, request.Term); // return new AppendEntriesResult(Term, false); } if (node.LocalLog.Entries.Any(e => e.Index == request.PreviousLogIndex && e.Term != request.PreviousLogTerm)) { //delete the entry and all that follow it node.LocalLog.RemoveEntryAndThoseAfterIt(request.PreviousLogIndex); } if (request.Entries.Max(e => e.Index) > node.LocalLog.LastIndex) { Debug.WriteLine("{0}: Adding To Local Log up to index {1} leaderCommitIndex {2}", node.NodeInfo(), request.Entries.Max(e => e.Index), request.CommitIndex); request.Entries.Where(e => e.Index > node.LocalLog.LastIndex).ForEach(e => node.LocalLog.Add(e.Term, e.Log)); } if (request.CommitIndex > node.ServerLog.LastIndex) { Debug.WriteLine("{0}: Adding To Server Log up to index {1} leaderCommitIndex {2}", node.NodeInfo(), request.PreviousLogIndex, request.CommitIndex); request.Entries.Where(e => e.Index > node.ServerLog.LastIndex && e.Index <= request.CommitIndex).ForEach(e => node.ServerLog.Add(e.Term, e.Log)); } if (request.CommitIndex > node.CommitIndex) { node.CommitIndex = Math.Min(request.CommitIndex, node.LocalLog.LastIndex); } return(new AppendEntriesResult(node.Term, true)); }
public async Task <AppendEntriesResult> AppendEntries(AppendEntriesRequest request) { return(await appendEntries(request)); }
public async Task<AppendEntriesResult> AppendEntries(AppendEntriesRequest request) { Debug.WriteLine("{0}: GOT APPEND ENTRIES CALL {1}: leader commit {2} : entries: {3}", node.NodeInfo(), request.Id, request.CommitIndex, String.Concat(request.Entries.Select(e => e.Log + " "))); if (request.Term < node.Term) { return new AppendEntriesResult(node.Term, false); } node.CurrentLeader = request.Id; node.Term = request.Term; node.lastHeartBeat = node.settings.Scheduler.Now; if (request.Entries == null || !request.Entries.Any()) //heartbeat { if (request.CommitIndex > node.ServerLog.LastIndex) { Debug.WriteLine("{0}: HeartBeat Adding To Server Log up to index {1} leaderCommitIndex {2}", node.NodeInfo(), request.PreviousLogIndex, request.CommitIndex); node.LocalLog.Entries.Where(e => e.Index > node.ServerLog.LastIndex && e.Index <= request.CommitIndex).ForEach(e => node.ServerLog.Add(e.Term, e.Log)); } return new AppendEntriesResult(node.Term, true); } if (request.PreviousLogIndex == 0 || (request.PreviousLogIndex <= node.ServerLog.LastIndex && node.ServerLog.LastTerm == request.PreviousLogTerm)) { Debug.WriteLine("{0}: huh"); } //reply false if log doesnt contain an entry at prevLogIndex whose node.term matches prevlogTerm if (!node.LocalLog.Entries.Any(e => e.Index == request.PreviousLogIndex && e.Term == request.PreviousLogTerm)) //not to sure about this line yet { Debug.WriteLine("follower node.LocalLog doesnt contain an entry at request.prevLogIndex({0}) whose node.term matches request.prevlogTerm{1}", request.PreviousLogIndex, request.Term); // return new AppendEntriesResult(Term, false); } if (node.LocalLog.Entries.Any(e => e.Index == request.PreviousLogIndex && e.Term != request.PreviousLogTerm)) { //delete the entry and all that follow it node.LocalLog.RemoveEntryAndThoseAfterIt(request.PreviousLogIndex); } if (request.Entries.Max(e => e.Index) > node.LocalLog.LastIndex) { Debug.WriteLine("{0}: Adding To Local Log up to index {1} leaderCommitIndex {2}", node.NodeInfo(), request.Entries.Max(e => e.Index), request.CommitIndex); request.Entries.Where(e => e.Index > node.LocalLog.LastIndex).ForEach(e => node.LocalLog.Add(e.Term, e.Log)); } if (request.CommitIndex > node.ServerLog.LastIndex) { Debug.WriteLine("{0}: Adding To Server Log up to index {1} leaderCommitIndex {2}", node.NodeInfo(), request.PreviousLogIndex, request.CommitIndex); request.Entries.Where(e => e.Index > node.ServerLog.LastIndex && e.Index <= request.CommitIndex).ForEach(e => node.ServerLog.Add(e.Term, e.Log)); } if (request.CommitIndex > node.CommitIndex) { node.CommitIndex = Math.Min(request.CommitIndex, node.LocalLog.LastIndex); } return new AppendEntriesResult(node.Term, true); }
public virtual async Task <AppendEntriesResult> AppendEntries(AppendEntriesRequest request) { return(await requestHandler.AppendEntries(request)); }
public async Task<AppendEntriesResult> AppendEntries(AppendEntriesRequest request) { return await appendEntries(request); }
public virtual async Task <AppendEntriesResult> AppendEntries(AppendEntriesRequest request) { Debug.WriteLine("{0}: GOT APPEND ENTRIES CALL {1}: leader commit {2} : entries: {3}", NodeInfo(), request.Id, request.CommitIndex, String.Concat(request.Entries.Select(e => e.Log + " "))); HeartBeat(request.Id, request.Term); if (request.Entries == null || !request.Entries.Any()) //heartbeat { if (request.CommitIndex > ServerLog.LastIndex) { Debug.WriteLine("{0}: HeartBeat Adding To Server Log up to index {1} leaderCommitIndex {2}", NodeInfo(), request.PreviousLogIndex, request.CommitIndex); LocalLog.Entries.Where(e => e.Index > ServerLog.LastIndex && e.Index <= request.CommitIndex).ForEach(e => ServerLog.Add(e.Term, e.Log)); } return(new AppendEntriesResult(Term, true)); } if (Term < request.Term) //servers term is behind. we need to ensure we are in follower state and reset who we have voted for { StepDown(request.Term, request.Id); return(new AppendEntriesResult(Term, false)); } if (request.Term < Term) { return(new AppendEntriesResult(Term, false)); } if (request.PreviousLogIndex == 0 || (request.PreviousLogIndex <= ServerLog.LastIndex && ServerLog.LastTerm == request.PreviousLogTerm)) { Debug.WriteLine("{0}: huh"); } //reply false if log doesnt contain an entry at prevLogIndex whose term matches prevlogTerm if (!LocalLog.Entries.Any(e => e.Index == request.PreviousLogIndex && e.Term == request.PreviousLogTerm)) //not to sure about this line yet { return(new AppendEntriesResult(Term, false)); } if (LocalLog.Entries.Any(e => e.Index == request.PreviousLogIndex && e.Term != request.PreviousLogTerm)) { //delete the entry and all that follow it LocalLog.RemoveEntryAndThoseAfterIt(request.PreviousLogIndex); } if (request.Entries.Max(e => e.Index) > LocalLog.LastIndex) { Debug.WriteLine("{0}: Adding To Local Log up to index {1} leaderCommitIndex {2}", NodeInfo(), request.Entries.Max(e => e.Index), request.CommitIndex); request.Entries.Where(e => e.Index > LocalLog.LastIndex).ForEach(e => LocalLog.Add(e.Term, e.Log)); } if (request.CommitIndex > ServerLog.LastIndex) { Debug.WriteLine("{0}: Adding To Server Log up to index {1} leaderCommitIndex {2}", NodeInfo(), request.PreviousLogIndex, request.CommitIndex); request.Entries.Where(e => e.Index > ServerLog.LastIndex && e.Index <= request.CommitIndex).ForEach(e => ServerLog.Add(e.Term, e.Log)); } if (request.CommitIndex > CommitIndex) { CommitIndex = Math.Min(request.CommitIndex, LocalLog.LastIndex); } return(new AppendEntriesResult(Term, true)); }
public virtual async Task<AppendEntriesResult> AppendEntries(AppendEntriesRequest request) { return await requestHandler.AppendEntries(request); }