/// <nodoc />
        public IEnumerable <ContentLocationEventData> DeserializeEvents(BuildXLReader reader)
        {
            return(SynchronizeIfNeeded(
                       synchronized =>
            {
                // Need to "materialize" the result if synchronization is needed.
                // Otherwise the lock will be released before all the data is consumed from the
                if (synchronized)
                {
                    return deserializeEventsCore().ToList();
                }
                else
                {
                    return deserializeEventsCore();
                }
            }));

            IEnumerable <ContentLocationEventData> deserializeEventsCore()
            {
                var entriesCount = reader.ReadInt32Compact();

                for (int i = 0; i < entriesCount; i++)
                {
                    // Using default as eventTimeUtc because reconciliation events should not have touches.
                    yield return(ContentLocationEventData.Deserialize(reader, eventTimeUtc: default));
                }
            }
        }
예제 #2
0
        /// <nodoc />
        public IEnumerable <ContentLocationEventData> DeserializeReconcileData(BuildXLReader reader)
        {
            var entriesCount = reader.ReadInt32Compact();

            for (int i = 0; i < entriesCount; i++)
            {
                // Using default as eventTimeUtc because reconciliation events should not have touches.
                yield return(ContentLocationEventData.Deserialize(reader, eventTimeUtc: default));
            }
        }
예제 #3
0
        private string GetTraceInfo(ContentLocationEventData eventData)
        {
            switch (eventData)
            {
            case ReconcileContentLocationEventData reconcile:
                return($"{reconcile.BlobId}");

            default:
                return(string.Join(", ", Enumerable.Range(0, eventData.ContentHashes.Count).Select(index => PrintHashInfo(eventData, index))));
            }
        }
예제 #4
0
        private string PrintHashInfo(ContentLocationEventData eventData, int index)
        {
            switch (eventData)
            {
            case AddContentLocationEventData add:
                return($"{add.ContentHashes[index]}: {add.ContentSizes[index]}");

            default:
                return(eventData.ContentHashes[index].ToString());
            }
        }
예제 #5
0
        /// <nodoc />
        public IReadOnlyList <ContentLocationEventData> DeserializeEvents(EventData message, DateTime?eventTimeUtc = null)
        {
            if (eventTimeUtc == null)
            {
                Contract.Assert(message.SystemProperties != null, "Either eventTimeUtc argument must be provided or message.SystemProperties must not be null. Did you forget to provde eventTimeUtc arguments in tests?");
                eventTimeUtc = message.SystemProperties.EnqueuedTimeUtc;
            }

            var data = message.Body;

            return(_reader.DeserializeSequence(data, reader => ContentLocationEventData.Deserialize(reader, eventTimeUtc.Value)).ToList());
        }
예제 #6
0
        /// <nodoc />
        public void SerializeReconcileData(OperationContext context, BuildXLWriter writer, MachineId machine, IReadOnlyList <ShortHashWithSize> addedContent, IReadOnlyList <ShortHash> removedContent)
        {
            var entries = new ContentLocationEventData[]
            {
                new AddContentLocationEventData(machine, addedContent),
                new RemoveContentLocationEventData(machine, removedContent)
            };

            var finalEntries = SplitLargeInstancesIfNeeded(entries);

            context.TraceDebug($"{nameof(ContentLocationEventDataSerializer)}: EntriesCount={finalEntries.Count}");

            writer.WriteCompact(finalEntries.Count);
            foreach (var eventData in finalEntries)
            {
                eventData.Serialize(writer);
            }
        }
예제 #7
0
        private static bool Equal(ContentLocationEventData left, int leftIndex, ContentLocationEventData right, int rightIndex)
        {
            if (left.Kind != right.Kind || left.Sender != right.Sender)
            {
                return(false);
            }

            if (left.Kind == EventKind.Reconcile)
            {
                // Reconcile blobs do not have hashes so just check blob id equality
                var leftReconcile  = (ReconcileContentLocationEventData)left;
                var rightReconcile = (ReconcileContentLocationEventData)right;
                return(leftReconcile.BlobId == rightReconcile.BlobId);
            }

            if (left.ContentHashes.Count == 0 || right.ContentHashes.Count == 0)
            {
                // This is a strange case where an event other than reconcile has zero hashes. Not an error per se.
                // That said, we verify that an empty event data matches when deserialized.
                return(left.ContentHashes.Count == right.ContentHashes.Count);
            }

            if (left.ContentHashes[leftIndex] != right.ContentHashes[rightIndex])
            {
                return(false);
            }

            switch (left.Kind)
            {
            case EventKind.AddLocation:
                var leftAdd  = (AddContentLocationEventData)left;
                var rightAdd = (AddContentLocationEventData)right;
                if (leftAdd.ContentSizes[leftIndex] != rightAdd.ContentSizes[rightIndex])
                {
                    return(false);
                }
                break;
            }

            return(true);
        }
        /// <inheritdoc />
        public override bool Equals(ContentLocationEventData other)
        {
            var otherTouch = (TouchContentLocationEventData)other;

            return(base.Equals(other) && AccessTime == otherTouch.AccessTime);
        }
        /// <inheritdoc />
        public override bool Equals(ContentLocationEventData other)
        {
            var rhs = (AddContentLocationEventData)other;

            return(base.Equals(other) && (Touch == rhs.Touch) && ContentSizes.SequenceEqual(rhs.ContentSizes));
        }
예제 #10
0
 private static IEnumerable <int> GetIndices(ContentLocationEventData data)
 {
     // Always have at least one index to ensure that events with no hashes like Reconcile are not skipped
     return(Enumerable.Range(0, Math.Max(data.ContentHashes.Count, 1)));
 }