示例#1
0
        static public int Compare(IMessage m1, IMessage m2, bool ignoreConnectionIds = false)
        {
            int sign = MessageTimestamp.Compare(m1.Time, m2.Time);

            if (sign == 0)
            {
                sign = ignoreConnectionIds ? 0 : CompareLogSourceConnectionIds(m1.GetConnectionId(), m2.GetConnectionId());
                if (sign == 0)
                {
                    sign = Math.Sign(m1.Position - m2.Position);
                }
            }
            return(sign);
        }
示例#2
0
 void MoveRangeToTime(MessageTimestamp time)
 {
     begin = end;
     while (begin < items.Count && items[begin].Time < time)
     {
         ++begin;
     }
     current = begin < items.Count ? items[begin].Time : MessageTimestamp.MaxValue;
     end     = begin;
     while (end < items.Count && MessageTimestamp.Compare(items[end].Time, current) == 0)
     {
         ++end;
     }
 }
示例#3
0
        static public int Compare(IBookmark b1, IBookmark b2, bool ignoreConnectionIds = false)
        {
            int sign = MessageTimestamp.Compare(b1.Time, b2.Time);

            if (sign == 0)
            {
                sign = ignoreConnectionIds ? 0 : CompareLogSourceConnectionIds(b1.LogSourceConnectionId, b2.LogSourceConnectionId);
                if (sign == 0)
                {
                    sign = Math.Sign(b1.Position - b2.Position);
                    if (sign == 0)
                    {
                        sign = Math.Sign(b1.LineIndex - b2.LineIndex);
                    }
                }
            }
            return(sign);
        }
示例#4
0
            public int Compare(LogPart x, LogPart y)
            {
                int tmp;

                tmp = MessageTimestamp.Compare(x.FirstMessageTime, y.FirstMessageTime);
                if (tmp != 0)
                {
                    return(tmp);
                }

                tmp = string.Compare(x.FileName, y.FileName, true);
                if (tmp != 0)
                {
                    return(tmp);
                }

                return(tmp);
            }
示例#5
0
            int IComparer <Entry> .Compare(Entry e1, Entry e2)
            {
                int cmpResult;

                long idxDiff = e1.index - e2.index;

                if (Math.Abs(idxDiff) > bufferSize)
                {
                    return(Math.Sign(idxDiff));
                }

                var x = e1.data;
                var y = e2.data;

                cmpResult = inversionFlag * MessageTimestamp.Compare(x.Message.Time, y.Message.Time);
                if (cmpResult != 0)
                {
                    return(cmpResult);
                }

                cmpResult = inversionFlag * Math.Sign(x.Message.Position - y.Message.Position);
                return(cmpResult);
            }
示例#6
0
        bool UpdateAvailableTime(bool incrementalMode)
        {
            bool itIsFirstUpdate = firstUpdateFlag;

            firstUpdateFlag = false;

            UpdateBoundsStatus status = reader.UpdateAvailableBounds(incrementalMode);

            if (status == UpdateBoundsStatus.NothingUpdated && incrementalMode)
            {
                return(false);
            }

            if (status == UpdateBoundsStatus.OldMessagesAreInvalid)
            {
                incrementalMode = false;
            }

            // Get new boundary values into temporary variables
            IMessage newFirst, newLast;

            PositionedMessagesUtils.GetBoundaryMessages(reader, null, out newFirst, out newLast);

            if (firstMessage != null)
            {
                if (newFirst == null || MessageTimestamp.Compare(newFirst.Time, firstMessage.Time) != 0)
                {
                    // The first message we've just read differs from the cached one.
                    // This means that the log was overwritten. Fall to non-incremental mode.
                    incrementalMode = false;
                }
            }

            if (!incrementalMode)
            {
                if (!itIsFirstUpdate)
                {
                    // Reset everything that has been loaded so far
                    InvalidateEverythingThatHasBeenLoaded();
                }
                firstMessage = null;
            }

            // Try to get the dates range for new bounday messages
            DateRange newAvailTime = GetAvailableDateRangeHelper(newFirst, newLast);

            firstMessage = newFirst;

            // Getting here means that the boundaries changed.
            // Fire the notfication.

            var positionsRange = new FileRange.Range(reader.BeginPosition, reader.EndPosition);

            if (!incrementalMode)
            {
                readerContentsEtag = reader.GetContentsEtag();
            }

            int contentsEtag =
                readerContentsEtag
                ^ positionsRange.Begin.GetHashCode()
                ^ positionsRange.End.GetHashCode();

            StatsTransaction(stats =>
            {
                stats.AvailableTime    = newAvailTime;
                LogProviderStatsFlag f = LogProviderStatsFlag.AvailableTime;
                if (incrementalMode)
                {
                    f |= LogProviderStatsFlag.AvailableTimeUpdatedIncrementallyFlag;
                }
                stats.TotalBytes = reader.SizeInBytes;
                f |= LogProviderStatsFlag.BytesCount;
                stats.PositionsRange = positionsRange;
                f |= LogProviderStatsFlag.PositionsRange;
                stats.PositionsRangeUpdatesCount++;
                if (stats.ContentsEtag == null || contentsEtag != stats.ContentsEtag.Value)
                {
                    stats.ContentsEtag = contentsEtag;
                    f |= LogProviderStatsFlag.ContentsEtag;
                }
                return(f);
            });

            return(true);
        }
示例#7
0
        async Task <ResultCode> FindGaps(DateRange range, TimeSpan threshold, int?maxGapsCount, List <TimeGap> ret)
        {
            using (trace.NewFrame)
            {
                trace.Info("threshold={0}", threshold.ToString());

                if (threshold.Ticks == 0)
                {
                    trace.Warning("threshold is empty");
                    return(ResultCode.None);
                }

                ResultCode resultCode = ResultCode.None;

                Helper helper = new Helper(this);

                // Below is the actual algorithm of finding the gaps:
                // - we start from the begin of the range (d = range.Begin).
                //   On the first iteration we find the positions of the messages
                //   that have the date less than d.
                // - on the next iterations we are finding out if there are messages
                //   with the date less than (d + threshold) with position different from
                //   the current positions. If yes, then there is no gap on
                //   interval (d, d + threshold).
                // - If no messages are found on the interval then we encountered with
                //   a time gap. The end of the gap is located by searching for the
                //   first message that is greater than d.
                TimeSpan cumulativeGapsLen = new TimeSpan();
                for (DateTime d = range.Begin; d < range.End;)
                {
                    trace.Info("moving to the lower bound of {0}", d);

                    if (IsStopOrInvalidate(resultCode = await helper.MoveToDateBound(d, reversedMode: true)))
                    {
                        return(resultCode);
                    }
                    if (resultCode == ResultCode.Ok)
                    {
                        trace.Info("moved successfully. The lower bound is {0}.", helper.CurrentDate);
                        d = helper.CurrentDate.Advance(threshold).ToLocalDateTime();
                    }
                    else
                    {
                        var gapBegin = helper.CurrentDate.ToLocalDateTime();
                        // A tick is needed here because CurrentDate is a date of an existing message.
                        // The gap begins right after this date. This tick matters when
                        // we are comparing gap's date range with a date range of messages.
                        // Do not forget: date ranges use the idea that DateRange.End doesn't belong
                        // to the range.
                        gapBegin = gapBegin.AddTicks(1);
                        trace.Info("no readers advanced. It's time gap starting at {0}", gapBegin);

                        trace.Info("moving to the date greater than {0}", d);
                        if (IsStopOrInvalidate(resultCode = await helper.MoveToDateBound(d, reversedMode: false)))
                        {
                            return(resultCode);
                        }

                        DateTime gapEnd = helper.CurrentDate.ToLocalDateTime();
                        trace.Info("the end of the gap: {0}", gapEnd);

                        if (MessageTimestamp.Compare(helper.CurrentDate, MessageTimestamp.MaxValue) != 0)
                        {
                            d = helper.CurrentDate.Advance(threshold).ToLocalDateTime();
                        }
                        else
                        {
                            d = DateTime.MaxValue;
                        }

                        var gap = new TimeGap(new DateRange(gapBegin, gapEnd));
                        trace.Info("creating new gap {0}", gap);

                        ret.Add(gap);

                        if (maxGapsCount.HasValue && ret.Count > maxGapsCount.Value)
                        {
                            throw new TooManyGapsException();
                        }

                        cumulativeGapsLen += gap.Range.Length;
                    }
                }

                trace.Info("returning {0} gaps", ret.Count);

                return(ResultCode.None);
            }
        }