예제 #1
0
        public static void FetchNeighborUpdate(SDSStack.Entry target, Link neighbor, RCS candidate)
        {
            var  existing    = target.InboundRCS[neighbor.LinearIndex];
            bool significant = existing != null && candidate.IC.OneCount < existing.IC.OneCount;

            if (existing != null && candidate.IC.OneCount > existing.IC.OneCount)
            {
                Log.Error("Unable to incorportate RCS from " + neighbor + ": RCS at generation " + target.Generation + " is worse than known");
                return;
            }
            target.InboundRCS[neighbor.LinearIndex] = candidate;
            if (significant)
            {
                target.SignificantInboundChange = true;
            }
            Log.Message(neighbor.Name + ": RCS[" + neighbor.LinearIndex + "] @g" + target.Generation + " IC ones: " + candidate.IC.OneCount);
        }
예제 #2
0
        public SDSComputation(DateTime applicationBeginDeadline, ExtMessagePack clientMessages, TimeSpan entityLogicTimeout, EntityChange.ExecutionContext ctx)
        {
            this.ctx   = ctx;
            generation = ctx.GenerationNumber;
            Deadline   = applicationBeginDeadline;
            SDSStack stack = Simulation.Stack;

            SDSStack.Entry input = stack.FindGeneration(generation - 1);
            if (input == null)
            {
                throw new IntegrityViolation("Unable to locate previous SDS at generation " + (generation - 1));
            }
            if (!input.IsFinished)
            {
                throw new IntegrityViolation("Previous SDS at generation " + (generation - 1) + " exists but is not finished");
            }

            //if (input.Generation != generation-1)
            //	throw new IntegrityViolation("Generation mismatch");
            old = stack.FindGeneration(generation);
            if (old == null)
            {
                throw new IntegrityViolation("Unable to locate original SDS at generation " + generation);
            }

            data = new IntermediateSDS();
            data.inputConsistent = input.IsFullyConsistent;

            {
                using (var ms = new MemoryStream())
                {
                    input.SDS.AddToStream(ms);
                    clientMessages.AddToStream(ms);
                    ms.Seek(0, SeekOrigin.Begin);
                    data.inputHash = new Digest(SHA256.Create().ComputeHash(ms), true);
                }
            }


            //old bad or dont exist, new maybe good
            if (clientMessages.HasBeenDiscarded)
            {
                throw new IntegrityViolation("Available client messages are incomplete but recorded messages have been discarded");
            }
            this.clientMessages = clientMessages.MessagePack;

            if (old.IntermediateSDS != null && old.IntermediateSDS.inputHash == data.inputHash)
            {
                data = old.IntermediateSDS;
                return;
            }



            data.entities       = new EntityPool(input.SDS.FinalEntities, ctx);
            data.localChangeSet = new EntityChangeSet();
            data.ic             = input.SDS.IC.Clone();
            if (!this.clientMessages.Completed)
            {
                Log.Message("Client messages are not complete for generation " + generation + ", setting everything inconsistent");
                data.ic.SetAllOne();
            }
            //bool doSendClientMessages = freshClientMessages != null && freshClientMessages.ArchivedGeneration == generation;
            errors = data.localChangeSet.Evolve(input.SDS.FinalEntities, this.clientMessages.Messages, data.ic, entityLogicTimeout, ctx);
            if (errors == null && input.IsFullyConsistent && data.ic.OneCount != 0 && clientMessages.MessagePack.Completed)
            {
                throw new IntegrityViolation("Input is fully consistent, and there are no errors. IC should have remaining empty");
            }

            InconsistencyCoverage untrimmed = data.ic.Grow(false);

            if (untrimmed.Size != InconsistencyCoverage.CommonResolution + 2)
            {
                throw new IntegrityViolation("IC of unsupported size: " + untrimmed.Size);
            }
            data.ic = untrimmed.Sub(new Int3(1), new Int3(InconsistencyCoverage.CommonResolution));



            foreach (var n in Simulation.Neighbors)
            {
                IntBox remoteBox = n.ICExportRegion;
                var    ic        = untrimmed.Sub(remoteBox);
                RCS    rcs       = new RCS(new EntityChangeSet(data.localChangeSet, n.WorldSpace, ctx), ic);
                var    oID       = n.GetOutboundRCSID(Generation);
                if (generation >= n.OldestGeneration)
                {
                    Log.Message("Dispatched " + oID + ", IC ones=" + ic.OneCount);
                    n.Set(oID.ToString(), new RCS.Serial(rcs, generation));
                    if (rcs.IsFullyConsistent)
                    {
                        n.UploadToDB(generation, rcs);
                    }
                }
                else
                {
                    Log.Error("Recomputed generation, but remote shard will not want generated RCS");
                }
            }
            data.localChangeSet.FilterByTargetLocation(Simulation.MySpace, ctx);
        }
예제 #3
0
파일: RCS.cs 프로젝트: IronFox/Shard
 public Serial(RCS rcs, int generation)
 {
     Generation = generation;
     Data       = rcs.Export();
 }
예제 #4
0
 public void UploadToDB(int generation, RCS rcs)
 {
     DB.PutAsync(new SerialRCS(GetOutboundRCSID(generation), rcs)).Wait();
     OnPutRCS?.Invoke(rcs, generation);
 }
예제 #5
0
파일: SerialRCS.cs 프로젝트: IronFox/Shard
 public SerialRCS(RCS.GenID id, RCS data)
 {
     Data      = data.Export();
     NumericID = id.IntArray;
     _id       = id.ToString();
 }