internal AvgBytesPerFlushCounterWriter(FabricPerformanceCounterSetInstance instance) : base( instance, TransactionalReplicatorPerformanceCounters.AvgBytesPerFlush, TransactionalReplicatorPerformanceCounters.AvgBytesPerFlushBase) { }
public TransactionManager( RecoveredOrCopiedCheckpointLsn recoveredOrCopiedCheckpointLsn, TransactionMap transactionMap, FabricPerformanceCounterSetInstance instance, CheckpointManager checkpointManager, ReplicatedLogManager replicatedLogManager, OperationProcessor unlockCallbackManager, ITracer tracer, long flushAtBufferedBytes) { this.recoveredOrCopiedCheckpointLsn = recoveredOrCopiedCheckpointLsn; this.transactionMap = transactionMap; this.checkpointManager = checkpointManager; this.replicatedLogManager = replicatedLogManager; this.unlockCallbackManager = unlockCallbackManager; this.tracer = tracer; this.flushAtBufferedBytes = flushAtBufferedBytes; this.beginTransactionOperationRatePerformanceCounterWriter = new BeginTransactionOperationRatePerformanceCounterWriter(instance); this.addOperationRatePerformanceCounterWriter = new AddOperationRatePerformanceCounterWriter(instance); this.transactionCommitRatePerformanceCounterWriter = new TransactionCommitRatePerformanceCounterWriter(instance); this.transactionAbortRatePerformanceCounterWriter = new TransactionAbortRatePerformanceCounterWriter(instance); this.addAtomicOperationRatePerformanceCounterWriter = new AddAtomicOperationRatePerformanceCounterWriter(instance); }
internal AvgTransactionCommitLatencyCounterWriter(FabricPerformanceCounterSetInstance instance) : base( instance, TransactionalReplicatorPerformanceCounters.AvgTransactionCommitTimeMs, TransactionalReplicatorPerformanceCounters.AvgTransactionCommitTimeMsBase) { }
internal AvgSerializationLatencyCounterWriter(FabricPerformanceCounterSetInstance instance) : base( instance, TransactionalReplicatorPerformanceCounters.AvgSerializationLatency, TransactionalReplicatorPerformanceCounters.AvgSerializationLatencyBase) { }
internal ActorSaveStateTimeCounterWriter(FabricPerformanceCounterSetInstance counterSetInstance) : base( counterSetInstance, ActorPerformanceCounters.ActorSaveStateTimeMillisecCounterName, ActorPerformanceCounters.ActorSaveStateTimeMillisecBaseCounterName) { }
public ServicePerformanceCounterProvider(Guid partitionId, long replicaOrInstanceId, ServiceTypeInformation serviceTypeInformation) { this.partitionId = partitionId; this.serviceTypeInformation = serviceTypeInformation; var ticks = (long)((DateTime.UtcNow.Ticks) % Math.Pow(10, MaxDigits)); this.counterInstanceDifferentiator = String.Concat(replicaOrInstanceId, "_", ticks.ToString("D")); var serviceCounterInstanceName = String.Concat(this.partitionId.ToString("D"), "_", this.counterInstanceDifferentiator); try { //Create ServiceCounterSetInstance this.serviceCounterSetInstance = ServiceCounterSet.CreateCounterSetInstance(serviceCounterInstanceName); } catch (Exception ex) { //Instance creation failed, Be done. ServiceTrace.Source.WriteWarning(TraceType, "Data for performance counter instance {0} of categoryName {1} will not be provided because an exception occurred during its initialization. Exception info: {2}", serviceCounterInstanceName, ServiceRemotingPerformanceCounters.ServiceCategoryName, ex); return; } this.CreateserviceCounterWriters(serviceCounterInstanceName); this.InitializeServiceMethodInfo(); }
/// <summary> /// Initializes a new instance of the <see cref="TStoreCopyStream"/> class. /// </summary> /// <param name="copyProvider">The store copy provider.</param> /// <param name="traceType">Used for tracing.</param> /// <param name="perfCounters">Store performance counters instance.</param> public TStoreCopyStream(IStoreCopyProvider copyProvider, string traceType, FabricPerformanceCounterSetInstance perfCounters) { Diagnostics.Assert(copyProvider != null, traceType, "copyProvider CannotUnloadAppDomainException be null"); this.copyProvider = copyProvider; this.traceType = traceType; this.perfCounterWriter = new TStoreCopyRateCounterWriter(perfCounters); }
internal FabricNumberOfItems64PerformanceCounterWriter( FabricPerformanceCounterSetInstance instance, string counterName ) : base( instance, counterName) { }
protected FabricPerformanceCounterWriter( FabricPerformanceCounterSetInstance instance, string counterName, string baseCounterName ) : base( instance, counterName) { this.CounterBase = instance.GetPerformanceCounter(baseCounterName); }
internal FabricAverageCount64PerformanceCounterWriter( FabricPerformanceCounterSetInstance instance, string counterName, string baseCounterName ) : base( instance, counterName, baseCounterName) { }
internal PerformanceCounterProvider(Guid partitionId, ActorTypeInformation actorTypeInformation) { // The counter instance names end with "_<TickCount>", where <TickCount> is the tick count when // the current object is created. // // If we didn't include the <TickCount> portion, the following problem could arise. Just after // a reconfiguration, a new primary creates a performance counter instance with the same name // as the one created by the old primary. If the old primary has not yet finished cleaning up // the old counter instance before the new primary creates its counter instance, then both // the old and the new primary will be referencing the same counter instance. Eventually, the // old primary will clean up the counter instance, while the new primary could still be using // it. By appending the <TickCount> portion, we ensure that the old and new primaries do not // reference the same counter instance. Therefore, when the old primary cleans up its counter // instance, the new primary is not affected by it. this.counterInstanceDifferentiator = DateTime.UtcNow.Ticks.ToString("D"); this.partitionId = partitionId; this.actorTypeInformation = actorTypeInformation; // Create counter writers for partition-wide counters var actorCounterInstanceName = String.Concat(this.partitionId.ToString("D"), "_", this.counterInstanceDifferentiator); if (AvaiableFabricCounterSet.TryGetValue(ActorPerformanceCounters.ActorCategoryName, out ActorCounterSet)) { try { //Create ActorCounterSetInstance this.actorCounterSetInstance = ActorCounterSet.CreateCounterSetInstance(actorCounterInstanceName); } catch (Exception ex) { //Instance creation failed, Be done. ActorTrace.Source.WriteWarning( TraceType, "Data for performance counter instance {0} of category {1} will not be provided because an exception occurred during its initialization. Exception info: {2}", actorCounterInstanceName, ActorPerformanceCounters.ActorCategoryName, ex); return; } } this.CreateActorCounterWriters(actorCounterInstanceName); }
private T CreateMethodCounterWriter <T>(string instanceName, Type counterWriterType, FabricPerformanceCounterSetInstance instance, Func <FabricPerformanceCounterSetInstance, T> counterWriterCreationCallback) { var retVal = default(T); try { retVal = counterWriterCreationCallback(instance); } catch (Exception ex) { this.LogCounterInstanceCreationResult( counterWriterType, instanceName, ex); } return(retVal); }
/// <summary> /// Helper class to build files. /// </summary> /// <param name="traceType">Tracing information.</param> /// <param name="perfCounters">Store performance counters instance.</param> public CopyManager(string traceType, FabricPerformanceCounterSetInstance perfCounters) { this.traceType = traceType; this.perfCounterWriter = new TStoreCopyRateCounterWriter(perfCounters); }
internal LogRecoveryPerfomanceCounterWriter(FabricPerformanceCounterSetInstance instance) : base(instance, TransactionalReplicatorPerformanceCounters.LogRecoveryCounterName) { this.watch = new Stopwatch(); }
/// <summary> /// Create a new <see cref="CheckpointFile"/> from the given file, serializing the given key-values into the file. /// </summary> /// <param name="fileId">File identifier.</param> /// <param name="filename">File to create and write to.</param> /// <param name="sortedItemData">Sorted key-value pairs to include in the table.</param> /// <param name="keySerializer"></param> /// <param name="valueSerializer"></param> /// <param name="timeStamp"></param> /// <param name="traceType">Tracing information.</param> /// <param name="perfCounters">Store performance counters instance.</param> /// <param name="isValueAReferenceType">Indicated if the value type is reference type.</param> /// <returns>The new <see cref="CheckpointFile"/>.</returns> public static async Task <CheckpointFile> CreateAsync <TKey, TValue>( uint fileId, string filename, IEnumerable <KeyValuePair <TKey, TVersionedItem <TValue> > > sortedItemData, IStateSerializer <TKey> keySerializer, IStateSerializer <TValue> valueSerializer, long timeStamp, string traceType, FabricPerformanceCounterSetInstance perfCounters, bool isValueAReferenceType) { var keyFileName = filename + KeyCheckpointFile.FileExtension; var valueFileName = filename + ValueCheckpointFile.FileExtension; var keyFile = new KeyCheckpointFile(keyFileName, fileId, isValueAReferenceType); var valueFile = new ValueCheckpointFile(valueFileName, fileId, traceType); var checkpointFile = new CheckpointFile(filename, keyFile, valueFile, traceType); var perfCounterWriter = new TStoreCheckpointRateCounterWriter(perfCounters); // Create the key checkpoint file and memory buffer. // MCoskun: Creation of checkpoint file's IO priority is not set. // Reason: Checkpointing is a life-cycle operation for State Provider that can cause throttling of backup, copy and (extreme cases) write operations. using (var keyFileStream = FabricFile.Open(keyFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.Asynchronous)) using (var keyMemoryBuffer = new InMemoryBinaryWriter(new MemoryStream(capacity: 64 * 1024))) { // Create the value checkpoint file and memory buffer. // MCoskun: Creation of checkpoint file's IO priority is not set. // Reason: Checkpointing is a life-cycle operation for State Provider that can cause throttling of backup, copy and (extreme cases) write operations. using (var valueFileStream = FabricFile.Open(valueFileName, FileMode.Create, FileAccess.ReadWrite, FileShare.None, 4096, FileOptions.Asynchronous)) using (var valueMemoryBuffer = new InMemoryBinaryWriter(new MemoryStream(capacity: 64 * 1024))) { var blockAlignedWriter = new BlockAlignedWriter <TKey, TValue>( valueFileStream, keyFileStream, valueFile, keyFile, valueMemoryBuffer, keyMemoryBuffer, valueSerializer, keySerializer, timeStamp, traceType); perfCounterWriter.StartMeasurement(); foreach (var item in sortedItemData) { await blockAlignedWriter.BlockAlignedWriteItemAsync(item, null, true).ConfigureAwait(false); } // Flush both key and value checkpoints to disk. await blockAlignedWriter.FlushAsync().ConfigureAwait(false); perfCounterWriter.StopMeasurement(); } } long writeBytes = checkpointFile.GetFileSize(); long writeBytesPerSec = perfCounterWriter.UpdatePerformanceCounter(writeBytes); #if !DotNetCoreClr FabricEvents.Events.CheckpointFileWriteBytesPerSec(traceType, writeBytesPerSec); #endif return(checkpointFile); }
internal ActorMethodExceptionFrequencyCounterWriter(FabricPerformanceCounterSetInstance counterSetInstance) : base( counterSetInstance, ActorPerformanceCounters.ActorMethodExceptionsPerSecCounterName) { }
internal TStoreItemCountCounterWriter(FabricPerformanceCounterSetInstance instance) : base(instance, DifferentialStoreConstants.PerformanceCounters.ItemCountName) { }
internal LogFlushBytesRateCounterWriter(FabricPerformanceCounterSetInstance instance) : base(instance, TransactionalReplicatorPerformanceCounters.LogFlushBytesPerSecondCounterName) { }
internal CheckpointCountCounterWriter(FabricPerformanceCounterSetInstance instance) : base(instance, TransactionalReplicatorPerformanceCounters.CheckpointCountCounterName) { }
internal ActorLockContentionCounterWriter(FabricPerformanceCounterSetInstance counterSetInstance) : base( counterSetInstance, ActorPerformanceCounters.ActorCallsWaitingForLockCounterName) { }
internal TransactionAbortRatePerformanceCounterWriter(FabricPerformanceCounterSetInstance instance) : base(instance, TransactionalReplicatorPerformanceCounters.AbortTransactionRateCounterName) { }
internal TStoreCheckpointRateCounterWriter(FabricPerformanceCounterSetInstance instance) : base(instance, DifferentialStoreConstants.PerformanceCounters.CheckpointFileWriteBytesPerSecName) { }
internal TStoreDiskSizeCounterWriter(FabricPerformanceCounterSetInstance instance) : base(instance, DifferentialStoreConstants.PerformanceCounters.DiskSizeName) { }
internal ThrottleRateCounterWriter(FabricPerformanceCounterSetInstance instance) : base(instance, TransactionalReplicatorPerformanceCounters.ThrottledOperationsPerSecondCounterName) { }
internal AddAtomicOperationRatePerformanceCounterWriter(FabricPerformanceCounterSetInstance instance) : base(instance, TransactionalReplicatorPerformanceCounters.AddAtomicOperationRateCounterName) { }
protected FabricBaselessPerformanceCounterWriter(FabricPerformanceCounterSetInstance instance, string counterName) { Counter = instance.GetPerformanceCounter(counterName); }
internal InflightVisibilitySequenceNumberCountCounterWriter(FabricPerformanceCounterSetInstance instance) : base( instance, TransactionalReplicatorPerformanceCounters.InflightVisibilitySequenceNumbersCountCounterName) { }
internal async Task <PhysicalLogReader> OpenWithRestoreFileAsync( ReplicaOpenMode openMode, FabricPerformanceCounterSetInstance perfCounterInstance, IList <string> backupLogFilePathList, int flushEveryNKB) { this.LogicalLog = await this.CreateLogFileAsync(openMode == ReplicaOpenMode.New, CancellationToken.None).ConfigureAwait(false); // No usable content in the log if (this.LogicalLog.WritePosition > 0) { await this.LogicalLog.TruncateTail(0, CancellationToken.None).ConfigureAwait(false); // Remove all contents and reset write cursor back to 0 Utility.Assert( this.LogicalLog.Length == 0 && this.LogicalLog.WritePosition == 0, "{0}: this.logicalLog.Length: {1} this.logicalLog.WritePosition: {2}", this.tracer.Type, this.LogicalLog.Length, this.LogicalLog.WritePosition); } using (PhysicalLogWriter logWriter = new PhysicalLogWriter( this.LogicalLog, this.emptyCallbackManager, this.Tracer, this.MaxWriteCacheSizeInMB, this.IncomingBytesRateCounterWriter, this.LogFlushBytesRateCounterWriter, this.BytesPerFlushCounterWriter, this.AvgFlushLatencyCounterWriter, this.AvgSerializationLatencyCounterWriter, true)) { LogRecord record = null; LogRecordsMap logRecordsMap = null; long bufferedRecordsSizeBytes = -1; long backupRecordIndex = 0; foreach (string backupLogFilePath in backupLogFilePathList) { BackupLogFile backupLogFile = await BackupLogFile.OpenAsync( backupLogFilePath, CancellationToken.None).ConfigureAwait(false); using (var backupLogEnumerator = backupLogFile.GetAsyncEnumerator()) { if (logRecordsMap == null) { bool hasFirstRecord = await backupLogEnumerator.MoveNextAsync(CancellationToken.None).ConfigureAwait(false); Utility.Assert(hasFirstRecord, "{0}: Backup must include at least six records.", this.tracer.Type); // If the log is being restored. // First record must be a indexing log record. Flush it. LogRecord firstRecordFromBackupLog = backupLogEnumerator.Current; Utility.Assert( null != firstRecordFromBackupLog, "{0}: BackupLogEnumerator will never return null", this.tracer.Type); Utility.Assert( false == LogRecord.IsInvalidRecord(firstRecordFromBackupLog), "{0}: First record read from the backup log cannot be invalid", this.tracer.Type); IndexingLogRecord logHead = firstRecordFromBackupLog as IndexingLogRecord; Utility.Assert( null != logHead, "{0}: First record read from the backup log must be indexing log record: Type: {1} LSN: {2} PSN: {3} Position: {4}", this.tracer.Type, firstRecordFromBackupLog.RecordType, firstRecordFromBackupLog.Lsn.LSN, firstRecordFromBackupLog.Psn.PSN, firstRecordFromBackupLog.RecordPosition); logRecordsMap = new LogRecordsMap(logHead, this.Tracer); logRecordsMap.ProcessLogRecord(logHead); bufferedRecordsSizeBytes = logWriter.InsertBufferedRecord(logHead); // Note that logHead.PreviousPhysicalRecord is an InvalidLogRecord. backupRecordIndex++; FabricEvents.Events.RestoreOperationAsync( this.Tracer.Type, logHead.RecordType.ToString(), backupRecordIndex, logHead.Lsn.LSN, logHead.Psn.PSN, long.MaxValue); } while (await backupLogEnumerator.MoveNextAsync(CancellationToken.None).ConfigureAwait(false)) { record = backupLogEnumerator.Current; logRecordsMap.ProcessLogRecord(record); // Note: Function inserts a record to the buffer where it waits to be flushed and return // the new size of the whole buffer. bufferedRecordsSizeBytes = logWriter.InsertBufferedRecord(record); backupRecordIndex++; FabricEvents.Events.RestoreOperationAsync( this.Tracer.Type, record.RecordType.ToString(), backupRecordIndex, record.Lsn.LSN, record.Psn.PSN, record.PreviousPhysicalRecord.Psn.PSN); // TODO: Use a backup config for this flush size determination if (bufferedRecordsSizeBytes > flushEveryNKB * 1024) { string intermediateFlushMessage = string.Format( CultureInfo.InvariantCulture, "LogManager: OpenWithRestoreFile (Restore) Intermediate Flush Size: {0} bytes, Index: {1}", bufferedRecordsSizeBytes, backupRecordIndex); await logWriter.FlushAsync(intermediateFlushMessage).ConfigureAwait(false); // This additional await is required to ensure the log record was indeed flushed. // Without this, the flushasync could succeed, but the log record flush could have failed due to a write error await record.AwaitFlush().ConfigureAwait(false); bufferedRecordsSizeBytes = 0; } } } } // Note: Move the last flush for remaining items out of the loop to avoid unnecessary flush in the // case of each iteration has a small number of un-flushed log records. if (bufferedRecordsSizeBytes > 0) { string flushMessage = string.Format( CultureInfo.InvariantCulture, "LogManager: OpenWithRestoreFile (Restore)"); await logWriter.FlushAsync(flushMessage).ConfigureAwait(false); // This additional await is required to ensure the log record was indeed flushed. // Without this, the flushasync could succeed, but the log record flush could have failed due to a write error await record.AwaitFlush().ConfigureAwait(false); } } return(new PhysicalLogReader(this)); }