internal void FlushMessageBatchBufferToWriter(bool forceFlush) { if (!this.shouldBufferBatches) { return; } if (!LogDataBatchReflectionCache <T> .IsMessageBatch) { return; } List <T> list = this.messageBatchBuffer; Tools.DebugAssert(list.Count <= this.maximumBatchCount, "Verify the buffer size will never goes above the maximumBatchCount"); if (!forceFlush && (DateTime.UtcNow - this.lastFluchCheckTime).TotalMilliseconds < 1000.0 && list.Count < this.maximumBatchCount) { return; } this.lastFluchCheckTime = DateTime.UtcNow; foreach (T t in list) { MessageBatchBase messageBatchBase = t as MessageBatchBase; Tools.DebugAssert(messageBatchBase != null, "Failed cast to MessageBatchBase."); if (forceFlush || messageBatchBase.ReadyToFlush(this.newestLogLineTS)) { ServiceLogger.LogDebug(ServiceLogger.Component.LogReader, LogUploaderEventLogConstants.Message.LogBatchEnqueue, string.Format("FlushMessageBatchBufferToWriter: called : thread={0}, forceFlush={1}, this.shouldBufferBatches={2}, bufferCount={3}, this.maximumBatchCount={4} ?---BufEnqueBatch ", new object[] { Thread.CurrentThread.ManagedThreadId, forceFlush, this.shouldBufferBatches, list.Count, this.maximumBatchCount }), "", ""); this.EnqueueBatch(t); messageBatchBase.Flushed = true; } } list.RemoveAll(delegate(T batch) { MessageBatchBase messageBatchBase3 = batch as MessageBatchBase; Tools.DebugAssert(messageBatchBase3 != null, "Failed cast to MessageBatchBase."); return(messageBatchBase3.Flushed); }); while (list.Count >= this.maximumBatchCount) { ServiceLogger.LogDebug(ServiceLogger.Component.LogReader, LogUploaderEventLogConstants.Message.LogBatchEnqueue, string.Format("FlushMessageBatchBufferToWriter: called : thread={0}, forceFlush={1}, this.shouldBufferBatches={2}, bufferCount={3}, this.maximumBatchCount={4} ?---BufEnqueBatch2 ", new object[] { Thread.CurrentThread.ManagedThreadId, forceFlush, this.shouldBufferBatches, list.Count, this.maximumBatchCount }), "", ""); this.EnqueueBatch(list[0]); MessageBatchBase messageBatchBase2 = list[0] as MessageBatchBase; Tools.DebugAssert(messageBatchBase2 != null, "Failed cast to MessageBatchBase."); messageBatchBase2.Flushed = true; list.RemoveAt(0); } }
public void FinishAndCreateNewBatch(ReadOnlyRow row) { this.FinishBatch(); this.CreateNewBatch(row.Position); MessageBatchBase messageBatchBase = this.activeBatch as MessageBatchBase; if (messageBatchBase != null) { messageBatchBase.MessageBatchFlushInterval = this.messageBatchFlushInterval; } }
public InputBuffer(int batchSizeInBytes, long beginOffset, ILogFileInfo logFileInfoObj, ThreadSafeQueue <T> logDataBatchQueue, string prefix, ILogMonitorHelper <T> logMonitorHelper, int messageBatchFlushInterval, CancellationContext cancelContext, int maxBatchCount, string instanceName = null) { if (batchSizeInBytes <= 0) { throw new ArgumentOutOfRangeException("batchSizeInByte", "The batch size should be greater than 0."); } if (beginOffset < 0L) { throw new ArgumentOutOfRangeException("beginOffset", "The beginOffset should be equal or greater than 0."); } if (logDataBatchQueue == null) { throw new ArgumentNullException("logDataBatchQueue cannot be null."); } if (messageBatchFlushInterval < 0) { throw new ArgumentOutOfRangeException("messageBatchFlushInterval", "The messageBatchFlushInterval must not be a negative number."); } ArgumentValidator.ThrowIfNull("logFileInfoObj", logFileInfoObj); ArgumentValidator.ThrowIfNull("watermarkFileRef", logFileInfoObj.WatermarkFileObj); if (string.IsNullOrEmpty(logFileInfoObj.FullFileName)) { throw new ArgumentException("fullLogName cannot be null or emtpy."); } ArgumentValidator.ThrowIfNull("cancelContext", cancelContext); this.cancellationContext = cancelContext; this.messageBatchFlushInterval = messageBatchFlushInterval; this.batchSizeInBytes = batchSizeInBytes; this.logDataBatchQueue = logDataBatchQueue; this.watermarkFileRef = logFileInfoObj.WatermarkFileObj; this.maximumBatchCount = ((maxBatchCount <= 0) ? int.MaxValue : maxBatchCount); this.lastFluchCheckTime = DateTime.UtcNow; this.logMonitorHelper = logMonitorHelper; this.fullLogName = logFileInfoObj.FullFileName; this.instance = (string.IsNullOrEmpty(instanceName) ? prefix : instanceName); this.logPrefix = prefix; this.perfCounterInstance = PerfCountersInstanceCache.GetInstance(this.instance); this.shouldBufferBatches = this.ShouldBufferBatches(); this.CreateNewBatch(beginOffset); if (this.shouldBufferBatches) { MessageBatchBase messageBatchBase = this.activeBatch as MessageBatchBase; if (messageBatchBase != null) { messageBatchBase.MessageBatchFlushInterval = this.messageBatchFlushInterval; } } }
private bool TryBackfillBufferedMessage(ParsedReadOnlyRow parsedRow) { if (!this.shouldBufferBatches) { return(false); } ReadOnlyRow unParsedRow = parsedRow.UnParsedRow; foreach (T t in this.messageBatchBuffer) { MessageBatchBase messageBatchBase = t as MessageBatchBase; Tools.DebugAssert(messageBatchBase != null, "Failed cast to MessageBatchBase."); if (!messageBatchBase.ReachedDalOptimizationLimit() && messageBatchBase.ContainsMessage(parsedRow)) { if (messageBatchBase.LineReceived(unParsedRow)) { messageBatchBase.AddRangeToBufferedBatch(unParsedRow.Position, unParsedRow.EndPosition); } this.newBackfilledLogLines += 1L; return(true); } } return(false); }