public LoggerDestination(Replica parent, Semantic semantic, string senderID, string loggerUrl) : base(parent, semantic)
 {
     SenderID = senderID;
     Logger   = (ILogger)Activator.GetObject(typeof(ILogger), loggerUrl);
     if (Logger == null)
     {
         Console.WriteLine($"Could not locate logging service at {loggerUrl}");
     }
     else
     {
         Console.WriteLine("PMLogService was successfully initiated.");
     }
 }
Example #2
0
        public NeighbourOperator(Replica master, DestinationInfo info, Semantic semantic) : base(master, semantic)
        {
            this.master               = master;
            this.info                 = info;
            CachedOutputTuples        = new List <CTuple>();
            GarbageCollectedTupleIds  = new List <TupleID>(new TupleID[info.Addresses.Count]);
            SentTupleIds              = new List <TupleID>(new TupleID[info.Addresses.Count]);
            somethingSentInRecentPast = new List <bool>(new bool[info.Addresses.Count]);
            replicas = new List <IReplica>(new IReplica[info.Addresses.Count]);
            for (int i = 0; i < GarbageCollectedTupleIds.Count; i++)
            {
                GarbageCollectedTupleIds[i]  = new TupleID();
                SentTupleIds[i]              = new TupleID();
                somethingSentInRecentPast[i] = false;
            }
            if (info.RtStrategy == SharedTypes.RoutingStrategy.Primary)
            {
                RoutingStrategy = new PrimaryStrategy(info.Addresses.Count);
            }
            else if (info.RtStrategy == SharedTypes.RoutingStrategy.Hashing)
            {
                RoutingStrategy = new HashingStrategy(info.Addresses.Count, info.HashingArg);
            }
            else
            {
                RoutingStrategy = new RandomStrategy(info.Addresses.Count, (master.OperatorId + info.ID + master.ID.ToString()).GetHashCode());
            }
            var replicasTask = Helper.GetAllStubs <IReplica>(info.Addresses);
            var initTask     = Task.Run(async() =>
            {
                this.replicas = (await replicasTask).ToList();
            });

            flushTimer = new Timer((e) =>
            {
                Flush(master.LastSentId);
                for (int i = 0; i < replicas.Count; i++)
                {
                    somethingSentInRecentPast[i] = false;
                }
            }, null, 1000, 1000);
        }
Example #3
0
        static void Main(string[] args)
        {
            //var c = new List<string> { "a", "b" };
            //var op = Operations.GetOperation("COUNT");
            //op.Process(c);
            //op.Process(c);
            //var a = Operations.GetCustomOperation(@"SharedTypes.dll", "SharedTypes.CustomFunctions", "reverse");
            // var b = Operations.GetCustomOperation(@"C:\Users\Goncalo\Source\Repos\DAD2016\Operator\Operator\bin\Debug\SharedTypes.dll", "SharedTypes.CustomFunctions", "dup");
            //var c = a(new List<string> { "a", "b" });
            // var d = b(new List<string> { "a", "b" });
            if (args.Length < 1)
            {
                Console.WriteLine("Missing creation info argument.");
                loop();
            }



            TextReader tr = new StringReader(args[0]);

            ReplicaCreationInfo rep = null;

            try
            {
                DataContractSerializer serializer = new DataContractSerializer(typeof(ReplicaCreationInfo));
                rep = (ReplicaCreationInfo)serializer.ReadObject(XmlReader.Create(tr));
            }
            catch (Exception e)
            {
                Console.WriteLine($"Creation info XML has a wrong format. Exception: {e.Message}");
                throw;
            } finally
            {
                tr.Close();
            }

            if (rep == null)
            {
                loop();
            }
            var info = rep.Operator;

            Console.WriteLine($"Successfully initiated replica {info.Addresses.IndexOf(rep.Address)} of {info.ID}.");
            string address = rep.Address;


            Replica        replica    = new Replica(rep);
            ReplicaManager repManager = new ReplicaManager(replica, info);

            Regex portRegex = new Regex(@"tcp://(\w|\.)+:(?<port>(\d+))(/(?<name>\w*))?", RegexOptions.IgnoreCase);
            var   match     = portRegex.Match(address);

            if (!match.Groups["port"].Success || !match.Groups["name"].Success)
            {
                Console.WriteLine($"URL ({address}) malformed. Unable to create process.");
                return;
            }
            var port = Int32.Parse(match.Groups["port"].Value);
            var name = match.Groups["name"].Value;

            try
            {
                TcpChannel channel = new TcpChannel(port);
                ChannelServices.RegisterChannel(channel, false);
            } catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            RemotingServices.Marshal(repManager, name, typeof(ReplicaManager));
            Console.WriteLine($"Listening at {address}. Press Enter to exit.");
            Console.ReadLine();
        }
        public void Recover(int failedId)
        {
            Dictionary <int, Replica> replicasCopy;

            lock (replicas)
            {
                replicasCopy = new Dictionary <int, Replica>(replicas);
            }

            Replica      r        = CreateReplica(failedId);
            ReplicaState repState = otherReplicasStates[failedId]; //get the last state of crashed replica
            Dictionary <string, OriginState> os = repState.InputStreamsIds;

            Console.WriteLine($"Started to recover replica {failedId} from state {repState}");
            r.LoadState(repState);
            AddReplica(r);
            allReplicas[failedId] = this;

            foreach (string opName in os.Keys)
            {
                var sentIds = os[opName].SentIds; // Only keeps the last id sent to each destination
                                                  //for each operator ask a re-sent
                if (opName == this.info.ID)
                {
                    continue;
                }
                for (int j = 0; j < sentIds.Count; j++)
                {
                    while (true)
                    {
                        try
                        {
                            Console.WriteLine($"Asking for resend to {opName} ({j})");
                            inputReplicas[opName][j].Resend(sentIds[j], this.info.ID, failedId, j, SelfURL);
                            break;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Resending failed. Trying again. Stay positive." + e.Message);
                        }
                    }
                }
            }

            //  Console.WriteLine("Phase 1 completed: Tuples were resent.");



            foreach (string opName in inputReplicas.Keys)
            {
                for (int i = 0; i < inputReplicas[opName].Count; i++)
                {
                    try
                    {
                        inputReplicas[opName][i].ReRoute(this.adresses[failedId], this.SelfURL);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("ReplicaManager.Recover: Reroute of input replicas failed " + e.Message);
                    }
                }
            }

            // Console.WriteLine("Phase 2 completed: Input replicas were rerouted.");
            foreach (string opName in outputReplicas.Keys)
            {
                for (int i = 0; i < outputReplicas[opName].Count; i++)
                {
                    try
                    {
                        outputReplicas[opName][i].ReRoute(this.adresses[failedId], this.SelfURL);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("ReplicaManager.Recover: Reroute of output replicas failed" + e.Message);
                    }
                }
            }


            // Console.WriteLine("Phase 3 completed: Output replicas were rerouted.");

            try
            {
                puppetMaster.ReRoute(this.info.ID, failedId, this.SelfURL);
            }
            catch (Exception e)
            {
                Console.WriteLine("ReplicaManager.Recover: Reroute of puppet master failed" + e.Message);
            }

            //Console.WriteLine("Phase 4 completed: Puppet master was rerouted.");


            adresses[failedId] = SelfURL;
            Console.WriteLine("MISSION COMPLETED: all recovered!");
            if (repState.IsFrozen)
            {
                r.Freeze();
            }
            if (replicas.First().Value.processingState)
            {
                r.Start();
            }
            r.Init();
            //resend
        }
        public ReplicaManager(Replica rep, OperatorInfo info)
        {
            rep.Init();
            this.SelfURL  = rep.SelfURL;
            this.replicas = new Dictionary <int, Replica>();
            this.replicas.Add(rep.ID, rep);
            this.adresses            = info.Addresses;
            this.info                = info;
            this.inputReplicas       = new Dictionary <string, List <IReplica> >();
            this.outputReplicas      = new Dictionary <string, List <IReplica> >();
            this.otherReplicasStates = new List <ReplicaState>(new ReplicaState[adresses.Count]);
            //await Task.Delay(10000);
            var initialState = rep.GetState();

            for (int i = 0; i < info.Addresses.Count; i++)
            {
                otherReplicasStates[i] = initialState;
            }

            this.pfd             = new PerfectFailureDetector();
            this.pfd.NodeFailed += OnFail;

            var initTask = Task.Run(async() =>
            {
                this.allReplicas =
                    (await Helper.GetAllStubs <IReplica>(
                         // hack to not get his own stub
                         info.Addresses.Select((address) => (rep.SelfURL != address ? address : null)).ToList()))
                    .ToList();
                allReplicas[rep.ID] = this;

                for (int i = 0; i < info.Addresses.Count; i++)
                {
                    if (i == rep.ID)
                    {
                        continue;
                    }

                    pfd.StartMonitoringNewNode(info.Addresses[i], allReplicas[i]);
                }

                foreach (var op in info.InputReplicas.Keys)
                {
                    this.inputReplicas[op] = (await Helper.GetAllStubs <IReplica>(info.InputReplicas[op])).ToList();
                }

                foreach (var op in info.OutputOperators)
                {
                    this.outputReplicas[op.ID] = (await Helper.GetAllStubs <IReplica>(op.Addresses)).ToList();
                }
            });

            propagateStateTimer = new Timer((e) =>
            {
                Dictionary <int, Replica> replicasCopy;
                lock (replicas)
                {
                    replicasCopy = new Dictionary <int, Replica>(replicas);
                }
                foreach (var repId in replicasCopy.Keys)
                {
                    PropagateState(repId);
                }
            }, null, PROPAGATE_STATE_PERIOD, PROPAGATE_STATE_PERIOD);

            puppetMaster  = (ILogger)Activator.GetObject(typeof(ILogger), info.MasterURL);
            Console.Title = $"{rep.OperatorId} ({rep.ID})";
        }
Example #6
0
 public OutputFile(Replica parent, Semantic semantic, string filepath = "output.dat") : base(parent, semantic)
 {
     FilePath     = filepath;
     OutputStream = new StreamWriter(filepath);
 }