Example #1
0
        internal void RemoveLogReader(ulong startingRecordPosition)
        {
            FabricEvents.Events.LogManager(
                this.Tracer.Type,
                "RemoveLogReader: Removing Log Reader with StartingRecordPosition: " + startingRecordPosition);

            lock (this.readersLock)
            {
                LogReaderRange readerRange;
                for (var i = 0; i < this.logReaderRanges.Count; i++)
                {
                    readerRange = this.logReaderRanges[i];
                    if (readerRange.StartingRecordPosition == startingRecordPosition)
                    {
                        if (readerRange.Release() > 0)
                        {
                            return;
                        }

                        this.logReaderRanges.RemoveAt(i);
                        if (i == 0)
                        {
                            this.earliestLogReader = (this.logReaderRanges.Count > 0)
                                ? this.logReaderRanges[0]
                                : LogReaderRange.DefaultLogReaderRange;
                        }

                        // check if removing this reader could help in completing the pending log head truncation
                        if (this.pendingLogHeadTruncationContext != null &&
                            this.earliestLogReader.StartingRecordPosition
                            >= this.pendingLogHeadTruncationContext.ProposedPosition)
                        {
                            this.LogHeadRecordPosition = this.pendingLogHeadTruncationContext.ProposedPosition;
                            FabricEvents.Events.LogManager(
                                this.Tracer.Type,
                                "RemoveLogReader: Initiating PerformLogHeadTruncation head position: " + this.LogHeadRecordPosition);

                            var localpendingLogHeadTruncationContext = this.pendingLogHeadTruncationContext;
                            Task.Factory.StartNew(this.PerformLogHeadTruncation, localpendingLogHeadTruncationContext)
                            .IgnoreExceptionVoid();
                            this.pendingLogHeadTruncationContext = null;
                        }

                        return;
                    }
                }
            }

            Utility.CodingError("Code should never have come here: RemoveLogReader");
        }
Example #2
0
 protected LogManager(
     string baseLogFileAlias,
     IncomingBytesRateCounterWriter incomingBytesRateCounter,
     LogFlushBytesRateCounterWriter logFlushBytesRateCounter,
     AvgBytesPerFlushCounterWriter bytesPerFlushCounterWriter,
     AvgFlushLatencyCounterWriter avgFlushLatencyCounterWriter,
     AvgSerializationLatencyCounterWriter avgSerializationLatencyCounterWriter)
 {
     this.BaseLogFileAlias                     = baseLogFileAlias;
     this.CurrentLogFileAlias                  = this.BaseLogFileAlias;
     this.LogicalLog                           = null;
     this.IsDisposed                           = false;
     this.LogHeadRecordPosition                = 0;
     this.PhysicalLogWriter                    = null;
     this.logReaderRanges                      = new List <LogReaderRange>();
     this.earliestLogReader                    = LogReaderRange.DefaultLogReaderRange;
     this.pendingLogHeadTruncationContext      = null;
     this.IncomingBytesRateCounterWriter       = incomingBytesRateCounter;
     this.LogFlushBytesRateCounterWriter       = logFlushBytesRateCounter;
     this.AvgFlushLatencyCounterWriter         = avgFlushLatencyCounterWriter;
     this.AvgSerializationLatencyCounterWriter = avgSerializationLatencyCounterWriter;
     this.BytesPerFlushCounterWriter           = bytesPerFlushCounterWriter;
 }
Example #3
0
        internal bool AddLogReader(
            long startingLsn,
            ulong startingRecordPosition,
            ulong endingRecordPosition,
            string readerName,
            LogReaderType readerType)
        {
            Utility.Assert(
                (startingRecordPosition == 0) || (this.LogHeadRecordPosition <= startingRecordPosition),
                "(startingRecordPosition == 0) || (this.CurrentLogHeadPosition <= startingRecordPosition), start record position :{0}. LogHeadRecordPosition: {1}",
                startingRecordPosition, this.LogHeadRecordPosition);

            FabricEvents.Events.LogManager(
                this.Tracer.Type,
                "AddLogReader: Adding Log Reader with StartingRecordPosition: " + startingRecordPosition + " EndingRecordPosition: " + endingRecordPosition +
                " ReaderName: " + readerName);

            lock (this.readersLock)
            {
                if (this.LogHeadRecordPosition > startingRecordPosition)
                {
                    return(false);
                }

                int            i;
                LogReaderRange readerRange;
                for (i = 0; i < this.logReaderRanges.Count; i++)
                {
                    readerRange = this.logReaderRanges[i];
                    if (startingRecordPosition < readerRange.StartingRecordPosition)
                    {
                        break;
                    }

                    if (readerRange.StartingRecordPosition == startingRecordPosition)
                    {
                        readerRange.AddRef();

                        // If a fullcopy reader comes in at the same position of a non-full copy reader, over-write the type as full-copy reader
                        // have significance when determining safe LSN to delete state providers
                        if (readerType == LogReaderType.FullCopy)
                        {
                            readerRange.ReaderType = LogReaderType.FullCopy;
                        }

                        return(true);
                    }
                }

                readerRange = new LogReaderRange(startingLsn, startingRecordPosition, readerName, readerType);
                this.logReaderRanges.Insert(i, readerRange);
                if (i == 0)
                {
                    this.earliestLogReader = this.logReaderRanges[0];
                }
            }

            Utility.Assert(
                (endingRecordPosition == long.MaxValue) || (this.CurrentLogTailPosition >= endingRecordPosition),
                @"(endingRecordPosition == Int64.MaxValue) || (this.CurrentLogTailPosition >= endingRecordPosition), EndingRecordPosition: {0}",
                endingRecordPosition);

            return(true);
        }