private void deadReplicaDetected(string url) { if (!primary) { electPrimaryOperator(url); //we will try to start this operator like from 0 and send request to sources startOperator(); } foreach (IList <string> source in sources) { foreach (string sourc in source) { if (sourc.Contains("tcp://")) { channel = new TcpChannel(); IRemoteOperator op = (IRemoteOperator)Activator.GetObject(typeof(Operator), sourc); if (op == null) { throw new CannotAccessRemoteObjectException("Cannot get remote replica Operator from " + sourc); } op.sendDeadReplica(url); } } } urls.Remove(url); }
private void pingFunction(object sender, EventArgs e) { //resends requests if a lot of time passes foreach (KeyValuePair <string, IList <IList <string> > > entry in not_acked) { if (!notAckedCounters.ContainsKey(entry.Key)) { notAckedCounters.Add(entry.Key, 0); } notAckedCounters[entry.Key] += 1; if (notAckedCounters[entry.Key] == notAckedLimit) { notAckedCounters.Remove(entry.Key); string[] splited = entry.Key.Split(';'); string machine = splited[0]; string actualSeq = splited[1]; string destinationMachine = splited[2]; doProcessTuples(machine, actualSeq, entry.Value); not_acked.Remove(entry.Key); } } //end of resend foreach (string url in urls) { if (!pings.ContainsKey(url)) { pings[url] = 0; } if (!url.Equals(url[0])) { if (pings[url] >= pingsLimit) { deadReplicaDetected(url); return; } pings[url] += 1; channel = new TcpChannel(); IRemoteOperator op = (IRemoteOperator)Activator.GetObject(typeof(Operator), url); if (op == null) { throw new CannotAccessRemoteObjectException("Cannot get remote replica Operator from " + url); } RemoteAsyncPingDelegate remoteDeleg = new RemoteAsyncPingDelegate(op.ping); IAsyncResult remoteResulte = remoteDeleg.BeginInvoke(urls[0], null, null); } } }
public void ping(string machine) { channel = new TcpChannel(); IRemoteOperator op = (IRemoteOperator)Activator.GetObject(typeof(Operator), machine); if (op == null) { throw new CannotAccessRemoteObjectException("Cannot get remote replica Operator from " + machine); } RemoteAsyncPongDelegate remoteDeleg = new RemoteAsyncPongDelegate(op.pong); IAsyncResult remoteResulte = remoteDeleg.BeginInvoke(urls[0], null, null); }
private void doFreezeCommand(string[] line, int lineNr) { int opId = -1; int opReplica = -1; if (line.Length != 3 || !Int32.TryParse(line[1].ToLower().Replace("op", ""), out opId) || !Int32.TryParse(line[2], out opReplica)) { throw new ParseException("Error parsing file in line " + lineNr + ". The correct format is Crash process_name replica_number"); } IRemoteOperator op = operators[opId][opReplica]; RemoteAsyncNoArgsOpDelegate RemoteDel = new RemoteAsyncNoArgsOpDelegate(op.freeze); IAsyncResult RemAr = RemoteDel.BeginInvoke(null, null); }
public void sendAckToPrevious(string url, string previousMachineSeq) { channel = new TcpChannel(); IRemoteOperator op = (IRemoteOperator)Activator.GetObject(typeof(Operator), url); if (op == null) { throw new CannotAccessRemoteObjectException("Cannot get remote Operator from " + url); } //RemoteAsyncAckTuplesDelegate remoteDel = new RemoteAsyncAckTuplesDelegate(op.doAckTuples); //IAsyncResult remoteResult = remoteDel.BeginInvoke(previousMachineSeq, null, null); if (semantics.Equals(SysConfig.AT_LEAST_ONCE)) { op.doAckTuples(previousMachineSeq); } }
private void sendRequestToSources(IList <string> opsAsSources) { //so o primario faz request às sources if (primary && this.routing.Equals(SysConfig.PRIMARY) || repId == random && routing.Equals(SysConfig.RANDOM) || primary && routing.StartsWith(SysConfig.HASHING)) { foreach (string source in opsAsSources) { channel = new TcpChannel(); IRemoteOperator op = (IRemoteOperator)Activator.GetObject(typeof(Operator), source); if (op == null) { throw new CannotAccessRemoteObjectException("Cannot get remote Operator from " + source); } RemoteAsyncReqTuplesDelegate remoteDel = new RemoteAsyncReqTuplesDelegate(op.requestTuples); IAsyncResult remoteResult = remoteDel.BeginInvoke(routing, random, urls, null, null); //op.requestTuples(urls); } } }
public void requestTuples(string receiverRouting, int receiverTarget, IList <string> receiverUrls) { if (!requested) { requested = true; this.receiver_routing = receiverRouting; this.receiver_target = receiverTarget; //Dictionary for hashing routing if (receiver_routing.StartsWith(SysConfig.HASHING) && this.res.Count == 0 && notSentTuples.Count != 0) { string[] aux = this.receiver_routing.Split('('); int field = Int32.Parse(aux[1].First() + ""); foreach (KeyValuePair <string, IList <IList <string> > > entry in notProcessedTuples) { foreach (List <string> tuple in entry.Value) { int replica = Math.Abs(tuple[field - 1].GetHashCode()) % receiverUrls.Count; IList <IList <string> > set; if (!(res.ContainsKey(replica))) { set = new List <IList <string> >(); set.Add(tuple); res.Add(replica, set); } else { set = res[replica]; set.Add(tuple); res[replica] = set; } } } } foreach (string url in receiverUrls) { channel = new TcpChannel(); IRemoteOperator op = (IRemoteOperator)Activator.GetObject(typeof(Operator), url); if (op == null) { throw new CannotAccessRemoteObjectException("Cannot get remote Operator from " + url); } receivers.Add(op); this.receivers_urls.Add(url); if (notSentTuples.Count > 0) { if ((this.receiver_routing.Equals(SysConfig.PRIMARY) && url.Equals(receiverUrls[0]))) { //ERROR can be here, there was notProcessedTuples foreach (KeyValuePair <string, IList <IList <string> > > entry in notSentTuples) { string machine = entry.Key.Split(';')[0]; string sequence = entry.Key.Split(';')[1]; relationingSequences.Add("" + seq, "" + sequence); not_acked.Add(machine + ";" + seq + ";" + receivers_urls[0], entry.Value); RemoteAsyncProcessTuplesDelegate remoteDel = new RemoteAsyncProcessTuplesDelegate(op.doProcessTuples); seq += 1; IAsyncResult remoteResult = remoteDel.BeginInvoke(urls[0], "" + seq, entry.Value, null, null); //receiver.doProcessTuples(notSentTuples); } } else if (url.Equals(receiverUrls[0]) && this.receiver_routing.Equals(SysConfig.RANDOM)) //RANDOM ROUTING { foreach (KeyValuePair <string, IList <IList <string> > > entry in notSentTuples) { string machine = entry.Key.Split(';')[0]; string sequence = entry.Key.Split(';')[1]; relationingSequences.Add("" + seq, "" + sequence); not_acked.Add(machine + ";" + seq + ";" + receivers_urls[0], entry.Value); RemoteAsyncProcessTuplesDelegate remoteProcTupleDel = new RemoteAsyncProcessTuplesDelegate(op.doProcessTuples); seq += 1; IAsyncResult remoteResult = remoteProcTupleDel.BeginInvoke(urls[0], "" + seq, entry.Value, null, null); } } else if (this.receiver_routing.StartsWith(SysConfig.HASHING)) //HASHING ROUTING { foreach (int rep in res.Keys) { if (url.Equals(receiverUrls[rep])) { relationingSequences.Add("" + seq, "" + seq); not_acked.Add(this.urls[0] + ";" + seq + ";" + url, res[rep]); RemoteAsyncProcessTuplesDelegate remoteProcTupleDel = new RemoteAsyncProcessTuplesDelegate(op.doProcessTuples); seq += 1; IAsyncResult remoteResult = remoteProcTupleDel.BeginInvoke(this.urls[0], "" + seq, res[rep], null, null); } } } notSentTuples = new Dictionary <string, IList <IList <string> > >(); } } } else { foreach (string url in receivers_bad_urls) { sendDeadReplica(url); } receivers_bad_urls = new List <string>(); } }
private void doCreateOperator(string pmurl, string id, IList <IList <string> > sources, String rep_fact, String routing, IList <String> urls, string type, IList <string> op_specs) { IList <IRemoteOperator> replicas = new List <IRemoteOperator>(); string primary = "true"; int repId = 0; //Random generator Random r = new Random(); int random = r.Next(urls.Count); foreach (string url in urls) { string[] aux1 = url.Split('/'); string address = aux1[aux1.Length - 2]; string nameOp = aux1[aux1.Length - 1]; string[] aux2 = address.Split(':'); string pcs_address = aux1[0]; string port = aux2[1]; for (int j = 1; j < aux1.Length - 1; j++) { if (j == aux1.Length - 2) { pcs_address += "/" + aux2[0] + ":" + SysConfig.PCS_PORT + "/" + SysConfig.PCS_NAME; } else { pcs_address += "/" + aux1[j]; } } IRemoteProcessCreation pcs = (IRemoteProcessCreation)Activator.GetObject(typeof(IRemoteProcessCreation), pcs_address); if (pcs == null) { throw new CannotAccessRemoteObjectException("Cannot get remote Operator from " + pcs_address); } //first url is of machine and others are from replicas IList <string> orderedUrls = new List <string>(); orderedUrls.Add(url); foreach (string s in urls) { if (!s.Equals(url)) { orderedUrls.Add(s); } } RemoteAsyncCreateOpDelegate RemoteDel = new RemoteAsyncCreateOpDelegate(pcs.createOP); IAsyncResult RemAr = RemoteDel.BeginInvoke(primary, nameOp, port, sysConfig, pmurl, sources, rep_fact, routing, orderedUrls, repId, random, null, null); primary = "false"; repId++; IRemoteOperator op = (IRemoteOperator)Activator.GetObject(typeof(IRemoteOperator), url); if (op == null) { throw new CannotAccessRemoteObjectException("Cannot get remote Operator from " + url); } byte[] code; RemoteAsyncSendOpDelegate RemoteSendDel = new RemoteAsyncSendOpDelegate(op.SendOperator); IAsyncResult RemSendAr; if (type.ToLower().Equals(SysConfig.CUSTOM)) { if (op_specs.Count != 3 || op_specs[0].Equals("") || op_specs[1].Equals("") || op_specs[2].Equals("")) { throw new WrongOpSpecsException("Custom Operator Specification needs 3 arguments."); } code = File.ReadAllBytes(op_specs[0]); RemSendAr = RemoteSendDel.BeginInvoke(code, op_specs[1], op_specs[2], null, null, null); } else { string className = ""; code = File.ReadAllBytes(LIB_OPERATORS_PATH); if (type.ToLower().Equals(SysConfig.UNIQUE)) { className = "UniqueOperator"; } else if (type.ToLower().Equals(SysConfig.COUNT)) { className = "CountOperator"; } else if (type.ToLower().Equals(SysConfig.FILTER)) { className = "FilterOperator"; } else if (type.ToLower().Equals(SysConfig.DUP)) { className = "DupOperator"; } RemSendAr = RemoteSendDel.BeginInvoke(code, className, DEFAULT_METHOD, op_specs, null, null); } replicas.Add(op); } operators.Add(Int32.Parse(id), replicas); }