Пример #1
0
        public static EntryPartition?FindLastMessagePartitionKey(IAzureDiagnosticLogsTable wadTable, DateTime utcNow, CancellationToken cancellation)
        {
            if (utcNow.Kind != DateTimeKind.Utc)
            {
                throw new ArgumentException("time must be of UTC kind", "utcNow");
            }
            var rangeForBinarySearch = GetRangeForLastMessageBinarySearch(wadTable, utcNow, cancellation);

            if (rangeForBinarySearch == null)
            {
                return(null);
            }

            EntryPartition begin = rangeForBinarySearch.Item1;
            EntryPartition end   = rangeForBinarySearch.Item2;

            int searchRangeDuration = EntryPartition.Distance(begin, end);
            int pos = ListUtils.BinarySearch(
                new ListUtils.VirtualList <int>(searchRangeDuration, i => i), 0, searchRangeDuration,
                i => {
                cancellation.ThrowIfCancellationRequested();
                return(wadTable.GetFirstEntryOlderThan(begin.Advance(i).ToString()) != null);
            });

            if (pos == searchRangeDuration)
            {
                return(null);
            }

            return(begin.Advance(pos));
        }
Пример #2
0
        static IndexedAzureDiagnosticLogEntry?FindLowerReversedDateBound(
            IAzureDiagnosticLogsTable wadTable,
            DateTime date,
            EntryPartition searchRangeBegin,
            CancellationToken cancellationToken)
        {
            EntryTimestamp dateTimestamp = new EntryTimestamp(date);
            var            ret           = FindLowerReversedDateBoundInPartition(wadTable, dateTimestamp.Partition, dateTimestamp.Ticks, cancellationToken);

            if (ret.Entry != null)
            {
                return(ret);
            }

            var rangeForBinarySearch = GetRangeForLowerReversedDateBoundBinarySearch(wadTable, dateTimestamp.Ticks,
                                                                                     searchRangeBegin, cancellationToken);

            if (rangeForBinarySearch == null)
            {
                return(null);
            }

            EntryPartition begin = rangeForBinarySearch.Item1;
            EntryPartition end   = rangeForBinarySearch.Item2;

            int searchRangeDuration = (int)EntryPartition.Distance(begin, end);
            int pos = ListUtils.BinarySearch(
                new ListUtils.VirtualList <int>(searchRangeDuration, i => i), 0, searchRangeDuration,
                timeBeingTested =>
            {
                cancellationToken.ThrowIfCancellationRequested();
                var firstEntryFollowingTimeBeingTested = wadTable.GetFirstEntryOlderThan(begin.Advance(timeBeingTested).ToString());
                bool lessThanBoundaryBeingSearched;
                if (firstEntryFollowingTimeBeingTested == null)
                {
                    lessThanBoundaryBeingSearched = false;
                }
                else
                {
                    lessThanBoundaryBeingSearched = firstEntryFollowingTimeBeingTested.EventTickCount < dateTimestamp.Ticks;
                }
                return(lessThanBoundaryBeingSearched);
            });

            if (pos == searchRangeDuration)
            {
                return(null);
            }

            ret = FindLowerReversedDateBoundInPartition(wadTable, begin.Advance(pos), dateTimestamp.Ticks, cancellationToken);
            if (ret.Entry != null)
            {
                return(ret);
            }

            return(null);
        }