Exemplo n.º 1
0
        static Tuple <EntryPartition, EntryPartition> GetRangeForLowerReversedDateBoundBinarySearch(
            IAzureDiagnosticLogsTable wadTable,
            long dateTicks,
            EntryPartition searchRangeBegin,
            CancellationToken cancellationToken)
        {
            EntryPartition datePartition     = new EntryPartition(new EntryTimestamp(dateTicks));
            EntryPartition lastStepPartition = datePartition;

            for (int step = 1; ; step *= 2)
            {
                EntryPartition p = EntryPartition.Max(searchRangeBegin, datePartition.Advance(step));
                if (EntryPartition.Compare(p, lastStepPartition) == 0)
                {
                    return(null);
                }
                var tmp = wadTable.GetFirstEntryOlderThan(p.ToString());
                if (tmp != null && tmp.EventTickCount < dateTicks)
                {
                    return(new Tuple <EntryPartition, EntryPartition>(
                               new EntryPartition(tmp.PartitionKey),
                               lastStepPartition.Advance()));
                }
                lastStepPartition = p;
                cancellationToken.ThrowIfCancellationRequested();
            }
        }
Exemplo n.º 2
0
        static Tuple <EntryPartition, EntryPartition> GetRangeForLastMessageBinarySearch(IAzureDiagnosticLogsTable wadTable, DateTime utcNow, CancellationToken cancellation)
        {
            EntryPartition initialPartition = new EntryTimestamp(utcNow).Partition;

            bool thereAreEntriesOlderThanNow = wadTable.GetFirstEntryOlderThan(initialPartition.ToString()) != null;
            bool searchingForward            = thereAreEntriesOlderThanNow;

            EntryPartition currentPartition = initialPartition;

            for (long step = searchingForward ? 1 : -1; ; step *= 2)
            {
                cancellation.ThrowIfCancellationRequested();
                EntryPartition t = initialPartition.Advance(step);
                if (EntryPartition.Compare(currentPartition, t) == 0)
                {
                    return(null);
                }
                var tmp = wadTable.GetFirstEntryOlderThan(t.ToString());
                if (searchingForward)
                {
                    if (tmp == null)
                    {
                        return(new Tuple <EntryPartition, EntryPartition>(currentPartition.Advance(), t));
                    }
                }
                else
                {
                    if (tmp != null)
                    {
                        return(new Tuple <EntryPartition, EntryPartition>(new EntryPartition(tmp.EventTickCount), currentPartition.Advance()));
                    }
                }
                currentPartition = t;
            }
        }