Ejemplo n.º 1
0
 internal AvgBytesPerFlushCounterWriter(FabricPerformanceCounterSetInstance instance)
     : base(
         instance,
         TransactionalReplicatorPerformanceCounters.AvgBytesPerFlush,
         TransactionalReplicatorPerformanceCounters.AvgBytesPerFlushBase)
 {
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
 internal AvgTransactionCommitLatencyCounterWriter(FabricPerformanceCounterSetInstance instance)
     : base(
         instance,
         TransactionalReplicatorPerformanceCounters.AvgTransactionCommitTimeMs,
         TransactionalReplicatorPerformanceCounters.AvgTransactionCommitTimeMsBase)
 {
 }
Ejemplo n.º 4
0
 internal AvgSerializationLatencyCounterWriter(FabricPerformanceCounterSetInstance instance)
     : base(
         instance,
         TransactionalReplicatorPerformanceCounters.AvgSerializationLatency,
         TransactionalReplicatorPerformanceCounters.AvgSerializationLatencyBase)
 {
 }
Ejemplo n.º 5
0
 internal ActorSaveStateTimeCounterWriter(FabricPerformanceCounterSetInstance counterSetInstance)
     : base(
         counterSetInstance,
         ActorPerformanceCounters.ActorSaveStateTimeMillisecCounterName,
         ActorPerformanceCounters.ActorSaveStateTimeMillisecBaseCounterName)
 {
 }
Ejemplo n.º 6
0
        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();
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
 internal FabricNumberOfItems64PerformanceCounterWriter(
     FabricPerformanceCounterSetInstance instance,
     string counterName
     )
     : base(
         instance,
         counterName)
 {
 }
Ejemplo n.º 9
0
 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)
 {
 }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
 /// <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);
 }
Ejemplo n.º 14
0
 internal LogRecoveryPerfomanceCounterWriter(FabricPerformanceCounterSetInstance instance)
     : base(instance, TransactionalReplicatorPerformanceCounters.LogRecoveryCounterName)
 {
     this.watch = new Stopwatch();
 }
Ejemplo n.º 15
0
        /// <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);
        }
Ejemplo n.º 16
0
 internal ActorMethodExceptionFrequencyCounterWriter(FabricPerformanceCounterSetInstance counterSetInstance)
     : base(
         counterSetInstance,
         ActorPerformanceCounters.ActorMethodExceptionsPerSecCounterName)
 {
 }
 internal TStoreItemCountCounterWriter(FabricPerformanceCounterSetInstance instance)
     : base(instance, DifferentialStoreConstants.PerformanceCounters.ItemCountName)
 {
 }
Ejemplo n.º 18
0
 internal LogFlushBytesRateCounterWriter(FabricPerformanceCounterSetInstance instance)
     : base(instance, TransactionalReplicatorPerformanceCounters.LogFlushBytesPerSecondCounterName)
 {
 }
Ejemplo n.º 19
0
 internal CheckpointCountCounterWriter(FabricPerformanceCounterSetInstance instance)
     : base(instance, TransactionalReplicatorPerformanceCounters.CheckpointCountCounterName)
 {
 }
Ejemplo n.º 20
0
 internal ActorLockContentionCounterWriter(FabricPerformanceCounterSetInstance counterSetInstance)
     : base(
         counterSetInstance,
         ActorPerformanceCounters.ActorCallsWaitingForLockCounterName)
 {
 }
Ejemplo n.º 21
0
 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)
 {
 }
Ejemplo n.º 24
0
 internal ThrottleRateCounterWriter(FabricPerformanceCounterSetInstance instance)
     : base(instance, TransactionalReplicatorPerformanceCounters.ThrottledOperationsPerSecondCounterName)
 {
 }
Ejemplo n.º 25
0
 internal AddAtomicOperationRatePerformanceCounterWriter(FabricPerformanceCounterSetInstance instance)
     : base(instance, TransactionalReplicatorPerformanceCounters.AddAtomicOperationRateCounterName)
 {
 }
Ejemplo n.º 26
0
 protected FabricBaselessPerformanceCounterWriter(FabricPerformanceCounterSetInstance instance, string counterName)
 {
     Counter = instance.GetPerformanceCounter(counterName);
 }
Ejemplo n.º 27
0
 internal InflightVisibilitySequenceNumberCountCounterWriter(FabricPerformanceCounterSetInstance instance)
     : base(
         instance,
         TransactionalReplicatorPerformanceCounters.InflightVisibilitySequenceNumbersCountCounterName)
 {
 }
Ejemplo n.º 28
0
        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));
        }