/// <summary> /// called from lock try..catch /// </summary> /// <param name="address"></param> /// <param name="data"></param> public void ParseStateLogRedirectRequest(NodeRaftAddress address, object data) { StateLogEntryRedirectRequest req = data as StateLogEntryRedirectRequest; if (this.stateMachine.States.NodeState != eNodeState.Leader) //Just return { return; } this.AddStateLogEntryForDistribution(req.Data, req.ExternalID);//, redirectId); this.EnqueueAndDistrbuteLog(); //Don't answer, committed value wil be delivered via standard channel }
public async Task OnRecieve(IChannelHandlerContext context, string msgstr) { // if (!string.IsNullOrEmpty(msgstr)) { //RaftCommand msgObj = Newtonsoft.Json.JsonConvert.DeserializeObject<RaftCommand>(msgstr, new JsonSerializerSettings() //{ // NullValueHandling = NullValueHandling.Ignore, // TypeNameHandling = TypeNameHandling.All, // TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Full //} //); int index = msgstr.IndexOf(','); string num = msgstr.Substring(0, index); string base64 = msgstr.Substring(index + 1); byte[] data = Convert.FromBase64String(base64); RaftCommand cmd = new RaftCommand(); cmd.Code = Convert.ToInt32(num); switch (cmd.Code) { case RaftCommand.Handshake: cmd.Message = TcpMsgHandshake.BiserDecode(data); break; case RaftCommand.HandshakeACK: cmd.Message = TcpMsgHandshake.BiserDecode(data); break; case RaftCommand.RaftMessage: cmd.Message = TcpMsgRaft.BiserDecode(data); TcpMsgRaft t = (TcpMsgRaft)cmd.Message; switch (t.RaftSignalType) { case eRaftSignalType.LeaderHearthbeat: t.orginalObject = LeaderHeartbeat.BiserDecode(t.Data); break; case eRaftSignalType.CandidateRequest: t.orginalObject = CandidateRequest.BiserDecode(t.Data); break; case eRaftSignalType.StateLogEntryAccepted: t.orginalObject = StateLogEntryApplied.BiserDecode(t.Data); break; case eRaftSignalType.StateLogEntryRequest: t.orginalObject = StateLogEntryRequest.BiserDecode(t.Data); break; case eRaftSignalType.StateLogEntrySuggestion: t.orginalObject = StateLogEntrySuggestion.BiserDecode(t.Data); break; case eRaftSignalType.StateLogRedirectRequest: t.orginalObject = StateLogEntryRedirectRequest.BiserDecode(t.Data); break; case eRaftSignalType.VoteOfCandidate: t.orginalObject = VoteOfCandidate.BiserDecode(t.Data); break; } break; case RaftCommand.FreeMessage: cmd.Message = TcpMsg.BiserDecode(data); break; } this.packetParser(cmd as RaftCommand); } }