Beispiel #1
0
        protected override void Restore(NaiadReader reader)
        {
            base.Restore(reader);
            this.isShutdown = reader.Read <bool>();

            if (!this.isShutdown)
            {
                this.internTable.Restore(reader);
                this.inputTrace.Restore(reader);
                this.outputTrace.Restore(reader);

                this.keyIndices.Restore(reader);
                //this.KeysToProcessAtTimes.Restore(reader, keySerializer);

                this.Input.Restore(reader);

                /*
                 * int recordsToProcessCount = reader.Read<int>(PrimitiveSerializers.Int32);
                 *
                 * foreach (NaiadList<Weighted<S>> recordList in this.recordsToProcess.Values)
                 *  recordList.Free();
                 * this.recordsToProcess.Clear();
                 *
                 * for (int i = 0; i < recordsToProcessCount; ++i)
                 * {
                 *  T key = reader.Read<T>(timeSerializer);
                 *  NaiadList<Weighted<S>> value = new NaiadList<Weighted<S>>();
                 *  value.Restore(reader, weightedSSerializer);
                 *  this.recordsToProcess[key] = value;
                 * }
                 */
            }
        }
Beispiel #2
0
        protected override void Restore(NaiadReader reader)
        {
            base.Restore(reader);
            this.isShutdown = reader.Read <bool>();

            if (!this.isShutdown)
            {
                this.internTable.Restore(reader);
                this.inputTrace.Restore(reader);
                this.outputTrace.Restore(reader);

                for (int i = 0; i < this.keyIndices.Length; ++i)
                {
                    int length = reader.Read <int>();
                    if (length == 0)
                    {
                        this.keyIndices[i] = null;
                    }
                    else
                    {
                        Debug.Assert(length == 65536);
                        this.keyIndices[i] = new UnaryKeyIndices[length];
                        for (int j = 0; j < this.keyIndices[i].Length; ++j)
                        {
                            this.keyIndices[i][j] = reader.Read <UnaryKeyIndices>();
                        }
                    }
                }

                this.keysToProcess.Restore(reader);

                this.Input.Restore(reader);
            }
        }
Beispiel #3
0
 public void Restore(NaiadReader reader)
 {
     for (int i = 0; i < this.heaps.Length; ++i)
     {
         this.heaps[i].Restore(reader);
     }
 }
Beispiel #4
0
        public void Restore(NaiadReader reader)
        {
            if (tSerializer == null)
            {
                tSerializer = AutoSerialization.GetSerializer <T>();
            }

            int spineCount = reader.Read <int>(PrimitiveSerializers.Int32);

            this.Spine.Clear();
            this.Spine.EnsureCapacity(spineCount);
            this.Spine.Count = spineCount;
            for (int i = 0; i < spineCount; ++i)
            {
                this.Spine.Array[i] = new T[this.SegmentLength];
                for (int j = 0; j < this.Spine.Array[i].Length; ++j)
                {
                    this.Spine.Array[i][j] = reader.Read <T>(tSerializer);
                }
            }

            this.FreeList.Restore(reader, PrimitiveSerializers.Int32);

            this.Allocated = reader.Read <int>(PrimitiveSerializers.Int32);
        }
        public void Restore(NaiadReader reader, NaiadSerialization <T> timeSerializer)
        {
            int before = reader.objectsRead;

            this.indices.Restore(reader, timeSerializer, PrimitiveSerializers.Int32);

            //Console.Error.WriteLine("% LIT.indices read {0} objects", reader.objectsRead - before);
            before = reader.objectsRead;

            this.times = FaultToleranceExtensionMethods.RestoreArray <T>(reader, n => {
                this.count = n;
                return(this.times.Length >= n ? this.times : new T[1 << BufferPoolUtils.Log2(n)]);
            }, timeSerializer);

            this.redirection = FaultToleranceExtensionMethods.RestoreArray <int>(reader, n => new int[n], PrimitiveSerializers.Int32);

            //Console.Error.WriteLine("% LIT.times read {0} objects", reader.objectsRead - before);

            before = reader.objectsRead;

            this.lastInterned = reader.Read <T>(timeSerializer);

            //Console.Error.WriteLine("% LIT.lastInterned read {0} objects", reader.objectsRead - before);

            before = reader.objectsRead;

            this.lastInternedResult = reader.Read <int>(PrimitiveSerializers.Int32);

            //Console.Error.WriteLine("% LIT.lastInternedResult read {0} objects", reader.objectsRead - before);
        }
Beispiel #6
0
        public override void Restore(NaiadReader reader)
        {
            base.Restore(reader);
            throw new NotImplementedException();

#if false
            //if (!this.terminated)
            {
                var timeSerializer = AutoSerialization.GetSerializer <T>();

                if (sSerializer == null)
                {
                    sSerializer = AutoSerialization.GetSerializer <S>();
                }

                this.accumulations.Clear();
                int accumulationsCount = reader.Read <int>(PrimitiveSerializers.Int32);
                for (int i = 0; i < accumulationsCount; ++i)
                {
                    T key = reader.Read <T>(timeSerializer);
                    Dictionary <S, Int64> value = new Dictionary <S, Int64>();
                    value.Restore(reader, sSerializer, PrimitiveSerializers.Int64);
                    this.accumulations[key] = value;
                }
            }
#endif
        }
Beispiel #7
0
        public void Restore(string path, int epoch)
        {
            throw new NotImplementedException();

#if false
            Stopwatch checkpointWatch = Stopwatch.StartNew();

            // Need to do this to ensure that all stages exist.
            this.currentGraphManager.MaterializeAll();

            foreach (var input in this.currentGraphManager.Inputs)
            {
                using (FileStream collectionFile = File.OpenRead(Path.Combine(path, string.Format("input_{0}_{1}.vertex", input.InputId, epoch))))
                    using (NaiadReader collectionReader = new NaiadReader(collectionFile))
                    {
                        input.Restore(collectionReader);
                        Console.Error.WriteLine("Read  {0}: {1} objects", input.ToString(), collectionReader.objectsRead);
                    }
            }
            foreach (var vertex in this.currentGraphManager.Stages.Values.SelectMany(x => x.Vertices.Where(s => s.Stateful)))
            {
                using (FileStream vertexFile = File.OpenRead(Path.Combine(path, string.Format("{0}_{1}_{2}.vertex", vertex.Stage.StageId, vertex.VertexId, epoch))))
                    using (NaiadReader vertexReader = new NaiadReader(vertexFile))
                    {
                        vertex.Restore(vertexReader);
                        Console.Error.WriteLine("Read  {0}: {1} objects", vertex.ToString(), vertexReader.objectsRead);
                    }
            }
            this.Workers.Activate();
            this.currentGraphManager.Activate();

            Console.Error.WriteLine("!! Total restore took time = {0}", checkpointWatch.Elapsed);
            Logging.Info("! Reactivated the controller");
#endif
        }
Beispiel #8
0
        protected override void Restore(NaiadReader reader)
        {
            base.Restore(reader);

            if (!this.isShutdown)
            {
                this.internTable.Restore(reader);
                this.inputTrace1.Restore(reader);
                this.inputTrace2.Restore(reader);
                this.outputTrace.Restore(reader);

                for (int i = 0; i < this.keyIndices.Length; ++i)
                {
                    int length = reader.Read <int>();
                    if (length >= 0)
                    {
                        this.keyIndices[i] = new BinaryKeyIndices[length];
                        for (int j = 0; j < this.keyIndices[i].Length; ++j)
                        {
                            this.keyIndices[i][j] = reader.Read <BinaryKeyIndices>();
                        }
                    }
                }

                this.Input1.Restore(reader);
                this.Input2.Restore(reader);
            }
        }
Beispiel #9
0
 protected override void Restore(NaiadReader reader)
 {
     base.Restore(reader);
     if (!this.isShutdown)
     {
         this.JoinKeys.Restore(reader);
     }
 }
Beispiel #10
0
 public override void Restore(NaiadReader reader)
 {
     base.Restore(reader);
     if (!this.isShutdown)
     {
         this.JoinKeys.Restore(reader, keySerializer, JoinKeyIndices.Serializer);
     }
 }
        /// <summary>
        /// Reads this list from the given reader.
        /// </summary>
        /// <typeparam name="TElement">The type of elements in the list.</typeparam>
        /// <param name="list">The list to be read.</param>
        /// <param name="reader">The reader.</param>
        public static void Restore <TElement>(this List <TElement> list, NaiadReader reader)
        {
            list.Clear();
            int count = reader.Read <int>();

            for (int i = 0; i < list.Count; ++i)
            {
                list.Add(reader.Read <TElement>());
            }
        }
Beispiel #12
0
        /// <summary>
        /// Enumerates records from a stream in the Naiad serialization format.
        /// </summary>
        /// <typeparam name="TRecord">Type of record in the stream</typeparam>
        /// <param name="stream">A stream containing records serialized in the Naiad messaging format</param>
        /// <param name="codeGenerator">code generator</param>
        /// <returns>An enumeration of records in the stream</returns>
        internal static IEnumerable <TRecord> GetNaiadReaderEnumerable <TRecord>(System.IO.Stream stream, SerializationFormat codeGenerator)
        {
            NaiadReader reader = new NaiadReader(stream, codeGenerator);
            NaiadSerialization <TRecord> deserializer = codeGenerator.GetSerializer <TRecord>();
            TRecord nextElement;

            while (reader.TryRead <TRecord>(deserializer, out nextElement))
            {
                yield return(nextElement);
            }
        }
Beispiel #13
0
 /// <summary>
 /// Enumerates records from a stream in the Naiad serialization format.
 /// </summary>
 /// <typeparam name="TRecord">Type of record in the stream</typeparam>
 /// <param name="stream">A stream containing records serialized in the Naiad messaging format</param>
 /// <returns>An enumeration of records in the stream</returns>
 public static IEnumerable <TRecord> GetNaiadReaderEnumerable <TRecord>(System.IO.Stream stream)
 {
     using (NaiadReader <TRecord> reader = new NaiadReader <TRecord>(stream))
     {
         TRecord nextElement;
         while (reader.TryRead(out nextElement))
         {
             yield return(nextElement);
         }
     }
 }
Beispiel #14
0
        /// <summary>
        /// Restores from NaiadReader
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="serializer"></param>
        /// <param name="intSerializer"></param>
        public void Restore(NaiadReader reader, NaiadSerialization <T> serializer, NaiadSerialization <Int32> intSerializer)
        {
            int readCount = reader.Read(intSerializer);

            this.Count = 0;
            Array.Clear(this.Spine, 0, this.Spine.Length);
            for (int i = 0; i < readCount; ++i)
            {
                this.Add(reader.Read(serializer));
            }
        }
        /// <summary>
        /// Reads an array from the given reader.
        /// </summary>
        /// <typeparam name="TElement">The type of elements in the array.</typeparam>
        /// <param name="reader">The reader.</param>
        /// <param name="allocator">An allocator function that allocates an array with at least as many elements as its argument.</param>
        /// <returns>The array.</returns>
        public static TElement[] RestoreArray <TElement>(NaiadReader reader, Func <int, TElement[]> allocator)
        {
            int count = reader.Read <int>();

            TElement[] ret = allocator(count);
            for (int i = 0; i < count; ++i)
            {
                ret[i] = reader.Read <TElement>();
            }
            return(ret);
        }
Beispiel #16
0
        protected override void Restore(NaiadReader reader)
        {
            this.nextAvailableEpoch = reader.Read <int>();
            this.nextSendEpoch      = reader.Read <int>();
            int inputQueueCount = reader.Read <int>();

            for (int i = 0; i < inputQueueCount; ++i)
            {
                S[]  array  = CheckpointRestoreExtensionMethods.RestoreArray <S>(reader, n => new S[n]);
                bool isLast = reader.Read <bool>();
                this.inputQueue.Enqueue(new Instruction(array, isLast));
            }
        }
Beispiel #17
0
        public void Restore(NaiadReader reader)
        {
            var timeSerializer  = AutoSerialization.GetSerializer <TTime>();
            var valueSerializer = AutoSerialization.GetSerializer <TRecord>();

            int readCount = reader.Read(PrimitiveSerializers.Int32);

            for (int i = 0; i < readCount; ++i)
            {
                TTime time = reader.Read(timeSerializer);
                SpinedList <TRecord> records = new SpinedList <TRecord>();
                records.Restore(reader, valueSerializer);
                this.recordsToProcess[time] = records;
            }
        }
Beispiel #18
0
        protected override void Restore(NaiadReader reader)
        {
            base.Restore(reader);
            this.isShutdown = reader.Read <bool>();

            if (!this.isShutdown)
            {
                this.internTable.Restore(reader);
                this.inputTrace1.Restore(reader);
                this.inputTrace2.Restore(reader);
                this.outputTrace.Restore(reader);

                this.keyIndices.Restore(reader);

                this.Input1.Restore(reader);
                this.Input2.Restore(reader);

                /*
                 * int recordsToProcessCount1 = reader.Read<int>(PrimitiveSerializers.Int32);
                 *
                 * foreach (NaiadList<Weighted<S1>> recordList in this.recordsToProcess1.Values)
                 *  recordList.Free();
                 * this.recordsToProcess1.Clear();
                 *
                 * for (int i = 0; i < recordsToProcessCount1; ++i)
                 * {
                 *  T key = reader.Read<T>(timeSerializer);
                 *  NaiadList<Weighted<S1>> value = new NaiadList<Weighted<S1>>();
                 *  value.Restore(reader, weightedS1Serializer);
                 *  this.recordsToProcess1[key] = value;
                 * }
                 *
                 * int recordsToProcessCount2 = reader.Read<int>(PrimitiveSerializers.Int32);
                 *
                 * foreach (NaiadList<Weighted<S2>> recordList in this.recordsToProcess2.Values)
                 *  recordList.Free();
                 * this.recordsToProcess2.Clear();
                 *
                 * for (int i = 0; i < recordsToProcessCount2; ++i)
                 * {
                 *  T key = reader.Read<T>(timeSerializer);
                 *  NaiadList<Weighted<S2>> value = new NaiadList<Weighted<S2>>();
                 *  value.Restore(reader, weightedS2Serializer);
                 *  this.recordsToProcess2[key] = value;
                 * }
                 */
            }
        }
Beispiel #19
0
        /// <summary>
        /// Restores this buffer from the given <see cref="NaiadReader"/>.
        /// </summary>
        /// <param name="reader">The reader.</param>
        public void Restore(NaiadReader reader)
        {
            var timeSerializer  = this.Vertex.SerializationFormat.GetSerializer <TTime>();
            var valueSerializer = this.Vertex.SerializationFormat.GetSerializer <TRecord>();
            var intSerializer   = this.Vertex.SerializationFormat.GetSerializer <Int32>();

            int readCount = reader.Read(intSerializer);

            for (int i = 0; i < readCount; ++i)
            {
                TTime time = reader.Read(timeSerializer);
                SpinedList <TRecord> records = new SpinedList <TRecord>();
                records.Restore(reader, valueSerializer, intSerializer);
                this.recordsToProcess[time] = records;
            }
        }
Beispiel #20
0
 protected override void Restore(NaiadReader reader)
 {
     base.Restore(reader);
     //if (!this.terminated)
     {
         this.accumulations.Clear();
         int accumulationsCount = reader.Read <int>();
         for (int i = 0; i < accumulationsCount; ++i)
         {
             T key = reader.Read <T>();
             Dictionary <S, Int64> value = new Dictionary <S, Int64>();
             value.Restore(reader);
             this.accumulations[key] = value;
         }
     }
 }
Beispiel #21
0
        public static T[] RestoreArray <T>(NaiadReader reader, Func <int, T[]> allocator, NaiadSerialization <T> serializer)
        {
            if (intSerializer == null)
            {
                intSerializer = AutoSerialization.GetSerializer <int>();
            }

            int count = reader.Read <int>(intSerializer);

            T[] ret = allocator(count);
            for (int i = 0; i < count; ++i)
            {
                ret[i] = reader.Read <T>(serializer);
            }
            return(ret);
        }
Beispiel #22
0
        public static void Restore <S>(this List <S> list, NaiadReader reader, NaiadSerialization <S> serializer)
        //    where S : IEquatable<S>
        {
            if (intSerializer == null)
            {
                intSerializer = AutoSerialization.GetSerializer <int>();
            }

            list.Clear();
            int count = reader.Read <int>(intSerializer);

            for (int i = 0; i < list.Count; ++i)
            {
                list.Add(reader.Read <S>(serializer));
            }
        }
Beispiel #23
0
        public void Restore(NaiadReader reader)
        {
            if (rSerializer == null)
            {
                rSerializer = AutoSerialization.GetSerializer <R>();
            }

            bool isMutable = reader.Read <bool>(PrimitiveSerializers.Bool);

            if (isMutable)
            {
                int headsCount = reader.Read <int>(PrimitiveSerializers.Int32);
                this.heads = new List <int>(headsCount);
                for (int i = 0; i < headsCount; ++i)
                {
                    this.heads.Add(reader.Read <int>(PrimitiveSerializers.Int32));
                }

                int linksCount = reader.Read <int>(PrimitiveSerializers.Int32);
                if (pairSerializer == null)
                {
                    pairSerializer = AutoSerialization.GetSerializer <Naiad.Pair <R, int> >();
                }
                //this.links = new List<Naiad.Pair<R, int>>(linksCount);
                this.links = new SpinedList <Naiad.Pair <R, int> >();
                for (int i = 0; i < linksCount; ++i)
                {
                    this.links.Add(reader.Read <Naiad.Pair <R, int> >(pairSerializer));
                }
            }
            else
            {
                int offsetsLength = reader.Read <int>(PrimitiveSerializers.Int32);
                offsets = new int[offsetsLength];
                for (int i = 0; i < offsets.Length; ++i)
                {
                    offsets[i] = reader.Read <int>(PrimitiveSerializers.Int32);
                }

                int dataLength = reader.Read <int>(PrimitiveSerializers.Int32);
                data = new R[dataLength];
                for (int i = 0; i < data.Length; ++i)
                {
                    data[i] = reader.Read <R>(rSerializer);
                }
            }
        }
Beispiel #24
0
        public void Restore(NaiadReader reader)
        {
            throw new NotImplementedException();

#if false
            foreach (var kvp in this.currentGraphManager.Stages.OrderBy(x => x.Key))
            {
                int before = reader.objectsRead;
                kvp.Value.Restore(reader);
                int after = reader.objectsRead;
                Logging.Info("! Restored collection {0}, objects = {1}", kvp.Value, after - before);
            }
            this.Workers.Activate();
            this.currentGraphManager.Activate();
#endif
            //Logging.Info("! Reactivated the controller");
        }
Beispiel #25
0
        public override void Restore(NaiadReader reader)
        {
            base.Restore(reader);
            this.isShutdown = reader.Read <bool>(PrimitiveSerializers.Bool);

            if (!this.isShutdown)
            {
                if (timeSerializer == null)
                {
                    timeSerializer = AutoSerialization.GetSerializer <T>();
                }
                if (keySerializer == null)
                {
                    keySerializer = AutoSerialization.GetSerializer <K>();
                }
                if (weightedSSerializer == null)
                {
                    weightedSSerializer = AutoSerialization.GetSerializer <Weighted <S> >();
                }

                this.internTable.Restore(reader, timeSerializer);
                this.inputTrace.Restore(reader);
                this.outputTrace.Restore(reader);

                this.keyIndices.Restore(reader, keySerializer, UnaryKeyIndices.Serializer);
                this.keysToProcess.Restore(reader, keySerializer);

                this.Input.Restore(reader);

                /*
                 * int recordsToProcessCount = reader.Read<int>(PrimitiveSerializers.Int32);
                 *
                 * foreach (NaiadList<Weighted<S>> recordList in this.recordsToProcess.Values)
                 *  recordList.Free();
                 * this.recordsToProcess.Clear();
                 *
                 * for (int i = 0; i < recordsToProcessCount; ++i)
                 * {
                 *  T key = reader.Read<T>(timeSerializer);
                 *  NaiadList<Weighted<S>> value = new NaiadList<Weighted<S>>();
                 *  value.Restore(reader, weightedSSerializer);
                 *  this.recordsToProcess[key] = value;
                 * }
                 */
            }
        }
Beispiel #26
0
        public void Restore(NaiadReader reader)
        {
            int spineCount = reader.Read<int>();
            this.Spine.Clear();
            this.Spine.EnsureCapacity(spineCount);
            this.Spine.Count = spineCount;
            for (int i = 0; i < spineCount; ++i)
            {
                this.Spine.Array[i] = new T[this.SegmentLength];
                for (int j = 0; j < this.Spine.Array[i].Length; ++j)
                    this.Spine.Array[i][j] = reader.Read<T>();
            }

            this.FreeList.Restore(reader);

            this.Allocated = reader.Read<int>();
        }
Beispiel #27
0
        public override void Restore(NaiadReader reader)
        {
            if (weightedSSerializer == null)
            {
                weightedSSerializer = AutoSerialization.GetSerializer <S>();
            }

            this.nextAvailableEpoch = reader.Read <int>(PrimitiveSerializers.Int32);
            this.nextSendEpoch      = reader.Read <int>(PrimitiveSerializers.Int32);
            int inputQueueCount = reader.Read <int>(PrimitiveSerializers.Int32);

            for (int i = 0; i < inputQueueCount; ++i)
            {
                S[]  array  = FaultToleranceExtensionMethods.RestoreArray <S>(reader, n => new S[n], weightedSSerializer);
                bool isLast = reader.Read <bool>(PrimitiveSerializers.Bool);
                this.inputQueue.Enqueue(new Instruction(array, isLast));
            }
        }
Beispiel #28
0
        public static void Restore <S>(this NaiadList <S> list, NaiadReader reader, NaiadSerialization <S> serializer)
        //    where S : IEquatable<S>
        {
            if (intSerializer == null)
            {
                intSerializer = AutoSerialization.GetSerializer <int>();
            }

            list.Clear();
            int count = reader.Read <int>(intSerializer);

            list.EnsureCapacity(count);
            list.Count = count;
            for (int i = 0; i < list.Count; ++i)
            {
                list.Array[i] = reader.Read <S>(serializer);
            }
        }
        public override void Restore(NaiadReader reader)
        {
            base.Restore(reader);
            this.isShutdown = reader.Read <bool>(PrimitiveSerializers.Bool);

            if (!this.isShutdown)
            {
                if (timeSerializer == null)
                {
                    timeSerializer = AutoSerialization.GetSerializer <T>();
                }
                if (weightedSSerializer == null)
                {
                    weightedSSerializer = AutoSerialization.GetSerializer <Weighted <S> >();
                }

                this.internTable.Restore(reader, timeSerializer);
                this.inputTrace.Restore(reader);
                this.outputTrace.Restore(reader);

                for (int i = 0; i < this.keyIndices.Length; ++i)
                {
                    int length = reader.Read(PrimitiveSerializers.Int32);
                    if (length == 0)
                    {
                        this.keyIndices[i] = null;
                    }
                    else
                    {
                        Debug.Assert(length == 65536);
                        this.keyIndices[i] = new UnaryKeyIndices[length];
                        for (int j = 0; j < this.keyIndices[i].Length; ++j)
                        {
                            this.keyIndices[i][j] = reader.Read(UnaryKeyIndices.Serializer);
                        }
                    }
                }

                this.keysToProcess.Restore(reader, PrimitiveSerializers.Int32);

                this.Input.Restore(reader);
            }
        }
Beispiel #30
0
        public static void Restore <K, V>(this Dictionary <K, V> dictionary, NaiadReader reader, NaiadSerialization <K> keySerializer, NaiadSerialization <V> valueSerializer)
        //where K : IEquatable<K>
        //where V : IEquatable<V>
        {
            if (intSerializer == null)
            {
                intSerializer = AutoSerialization.GetSerializer <int>();
            }

            dictionary.Clear();
            int count = reader.Read <int>(intSerializer);

            for (int i = 0; i < count; ++i)
            {
                K key   = reader.Read <K>(keySerializer);
                V value = reader.Read <V>(valueSerializer);
                dictionary[key] = value;
            }
        }