Пример #1
0
        public void Resend(TupleID id, string operatorId, int replicaId, string destination)
        {
            if (operatorId == this.OperatorId && this.ID == replicaId)
            {
                return;
            }

            destinations[operatorId].Resend(id, replicaId, destination);
        }
Пример #2
0
        public override void Resend(TupleID id, int replicaId, string address)
        {
            List <CTuple> toDeliver = new List <CTuple>();
            var           rep       = Helper.GetStub <IReplica>(address);

            lock (this)
            {
                //Console.WriteLine("New destination: " + destination.ToString());
                if (id >= new TupleID(0, 0) && (CachedOutputTuples.Count == 0 || id < CachedOutputTuples[0].ID))
                {
                    // Missing tuples!!!
                    Console.WriteLine($"Tuple {id} is missing");
                    throw new TuplesNotCachedException(id, CachedOutputTuples[0].ID);
                }
                var upTo = SentTupleIds[replicaId];
                for (int i = 0; i < CachedOutputTuples.Count; i++)
                {
                    if (CachedOutputTuples[i].ID > upTo)
                    {
                        break;
                    }
                    if (CachedOutputTuples[i].ID <= id)
                    {
                        continue;
                    }
                    if (CachedOutputTuples[i].destinationId != replicaId)
                    {
                        continue;
                    }
                    toDeliver.Add(CachedOutputTuples[i]);
                }
            }
            foreach (var t in toDeliver)
            {
                // Console.WriteLine($"****Resending {t.ID} to {this.info.ID} ({replicaId})");
                try
                {
                    rep.ProcessAndForward(t, replicaId);
                } catch (Exception e)
                {
                    Console.WriteLine("Error while resending: " + e.Message);
                }
            }
        }
Пример #3
0
        private void mainLoop()
        {
            int i = 0;

            while (true)
            {
                try
                {
                    var t = inBuffer.Next();
                    lock (this)
                    {
                        var result = Process(t);
                        foreach (var tuple in result)
                        {
                            SendToAll(tuple);
                            LastSentId = tuple.ID;
                        }
                        if (!result.Any() && t.ID.GlobalID > 0)
                        {
                            // if there are no results, update lastSentId anyways

                            var newId = new TupleID(t.ID.GlobalID - 1, 0);
                            LastSentId = LastSentId > newId ? LastSentId : newId;
                        }

                        // every 20 tuples, flush
                        if (i % 20 == 0)
                        {
                            foreach (var d in destinations.Values)
                            {
                                d.Flush(LastSentId);
                            }
                        }
                    }
                    i++;
                } catch (Exception e)
                {
                    Console.WriteLine("Replica.mainloop : " + e.Message);
                    Thread.Sleep(10000);
                }
            }
        }
Пример #4
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);
        }
Пример #5
0
        public override void GarbageCollect(TupleID id, int replicaId)
        {
            int i = 0;

            lock (this)
            {
                GarbageCollectedTupleIds[replicaId] = id;
                var garbageMin = GarbageCollectedTupleIds.Min();
                //Console.WriteLine($"GC-ing up to {id}");
                while (CachedOutputTuples.Count > 0 && garbageMin > CachedOutputTuples[0].ID)
                {
                    CachedOutputTuples.RemoveAt(0);
                    i++;
                }
            }
            if (i > 0)
            {
                Console.WriteLine($"GarbageCollect: Removed {i} tuples");
            }
        }
Пример #6
0
 public override void Flush(TupleID flushId)
 {
     for (int i = 0; i < replicas.Count; i++)
     {
         if (!somethingSentInRecentPast[i])
         {
             // Console.WriteLine($"Checking if need to flush. {SentTupleIds[i]} < {flushId}");
             if (flushId >= new TupleID(0, 0) && SentTupleIds[i] < flushId)
             {
                 //   Console.WriteLine($"Emitting flush {master.LastSentId} from {master.ID} to {i}");
                 try
                 {
                     var flushTuple = new CTuple(null, flushId.GlobalID, flushId.SubID, master.OperatorId, master.ID);
                     flushTuple.destinationId = i;
                     Insert(flushTuple);
                 }
                 catch (Exception)
                 {
                     Console.WriteLine("Error while flushing");
                 }
             }
         }
     }
 }
Пример #7
0
 public void Flush(TupleID id, string operatorId, int repId, int destinationId)
 {
     replicas[destinationId].Flush(id, operatorId, repId);
 }
Пример #8
0
 public void GarbageCollect(TupleID tupleId, string senderOpName, int senderRepId, int destinationId)
 {
     replicas[destinationId].GarbageCollect(tupleId, senderOpName, senderRepId);
 }
Пример #9
0
 public void Resend(TupleID id, string operatorId, int replicaId, int destinationId, string destination)
 {
     Console.WriteLine($"{operatorId} ({replicaId}) asked to resend tuples from {id}");
     replicas[destinationId].Resend(id, operatorId, replicaId, destination);
 }
Пример #10
0
 public virtual void GarbageCollect(TupleID id, int replicaId)
 {
     Console.WriteLine("GarbageCollect not implemented.");
 }
Пример #11
0
 public virtual void Resend(TupleID id, int replicaId, string destination)
 {
     Console.WriteLine("Resend not implemented.");
 }
Пример #12
0
 public virtual void Flush(TupleID id)
 {
     return;
 }
Пример #13
0
 public UpdateCommand(TupleID tupleId, Tuple tuple)
 {
     this.tupleId = tupleId;
     this.tuple = tuple;
 }
 public TuplesNotCachedException(TupleID idFirstTuple, TupleID idLastTuple) : base($"Tuples from {idFirstTuple} up to {idLastTuple} were not found in cache")
 {
     FirstTupleNotCached = idFirstTuple;
     LastTupleNotCached  = idLastTuple;
 }
Пример #15
0
 public void GarbageCollect(TupleID id, string operatorId, int replicaId)
 {
     //Console.WriteLine("Garbage Collecting");
     destinations[operatorId].GarbageCollect(id, replicaId);
 }
Пример #16
0
 public void Flush(TupleID id, string operatorId, int repId)
 {
     ProcessAndForward(new CTuple(null, id.GlobalID, 0, operatorId, repId));
 }