Esempio n. 1
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);
        }
        private bool ShouldCheckpoint(TransactionMap txManager, out List <BeginTransactionOperationLogRecord> abortTxList)
        {
            abortTxList = null;

            // There is a checkpoint in progres. So return false
            if (this.logManager.LastInProgressCheckpointRecord != null)
            {
                return(false);
            }

            if (ShouldInitiatePeriodicCheckpoint())
            {
                return(true);
            }

            var bytesUsedFromLastCheckpoint = this.GetBytesUsed(this.logManager.LastCompletedBeginCheckpointRecord);

            // If there is enough data to checkpoint, we should try to look for 'bad' transactions that are preventing
            // enough data from being checkpointed
            if (bytesUsedFromLastCheckpoint <= this.checkpointIntervalBytes)
            {
                return(false);
            }

            var earliestPendingTx = txManager.GetEarliestPendingTransaction();

            // If there is no pending tx, we should checkpoint now
            if (earliestPendingTx == null)
            {
                return(true);
            }

            // The earliest pending tx is very new and it has not yet been flushed. So it is fine to checkpoint
            // This could ALSO imply that we have a really old Tx that has not been flushed and has been lying around in the buffers
            // However, the latter case is taken care of by throttling the incoming operations based on "pending bytes" that are unflushed
            if (earliestPendingTx.RecordPosition == LogRecord.InvalidRecordPosition)
            {
                return(true);
            }

            var oldTxOffset = this.GetCurrentTailPosition() - this.txnAbortThresholdInBytes - 1;

            // The transaction is new enough. We can checkpoint
            if (earliestPendingTx.RecordPosition > oldTxOffset)
            {
                return(true);
            }

            // Get all 'bad' transactions that are preventing us from checkpointing enough state
            // We will return 'false' now and the next group commit should successfully checkpoint since the earliest pending should be newer
            abortTxList = txManager.GetPendingTransactionsOlderThanPosition(oldTxOffset);
            return(false);
        }
        public bool ShouldCheckpointOnSecondary(TransactionMap txMap)
        {
            // The first checkpoint is always initiated by copy
            if (this.logManager.LastCompletedBeginCheckpointRecord == null)
            {
                return(false);
            }

            List <BeginTransactionOperationLogRecord> tempList;

            return(this.ShouldCheckpoint(txMap, out tempList));
        }
        public List <BeginTransactionOperationLogRecord> GetOldTransactions(TransactionMap txManager)
        {
            var tail = this.GetCurrentTailPosition();

            // The tail is smaller than truncate interval
            if (tail <= this.txnAbortThresholdInBytes)
            {
                return(null);
            }

            var oldTxOffset = this.GetCurrentTailPosition() - this.txnAbortThresholdInBytes - 1;

            // Get all 'bad' transactions that are preventing us from checkpointing enough state
            return(txManager.GetPendingTransactionsOlderThanPosition(oldTxOffset));
        }
Esempio n. 5
0
        public TruncateTailManager(
            ReplicatedLogManager replicatedLogManager,
            TransactionMap transactionsMap,
            IStateManager stateManager,
            IBackupManager backupManager,
            LogicalSequenceNumber tailLsn,
            ApplyContext falseProgressApplyContext,
            PhysicalLogReader recoveryLogsReader,
            ITracer tracer)
        {
            Utility.Assert(tracer != null, "{0} TruncateTailManager: Input tracer cannot be null");
            Utility.Assert(backupManager != null, "{0} TruncateTailManager: Input backupManager cannot be null", tracer.Type);

            this.replicatedLogManager = replicatedLogManager;
            this.recoveryLogsReader   = recoveryLogsReader;
            this.transactionsMap      = transactionsMap;
            this.stateManager         = stateManager;
            this.backupManager        = backupManager;
            this.tracer  = tracer;
            this.tailLsn = tailLsn;
            this.falseProgressApplyContext = falseProgressApplyContext;
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the LogRecordsMap class for recovery.
        /// </summary>
        /// <param name="startingLogicalSequenceNumber"></param>
        /// <param name="transactionsMap"></param>
        /// <param name="currentLogTailEpoch"></param>
        /// <param name="lastStableLsn"></param>
        /// <param name="progressVector"></param>
        /// <param name="recoveredLastCompletedBeginCheckpointRecord"></param>
        /// <param name="tracer"></param>
        /// <param name="recoveredLastEndCheckpointRecord"></param>
        public LogRecordsMap(
            LogicalSequenceNumber startingLogicalSequenceNumber,
            TransactionMap transactionsMap,
            Epoch currentLogTailEpoch,
            LogicalSequenceNumber lastStableLsn,
            ProgressVector progressVector,
            BeginCheckpointLogRecord recoveredLastCompletedBeginCheckpointRecord,
            ITracer tracer,
            EndCheckpointLogRecord recoveredLastEndCheckpointRecord)
        {
            this.mode = Mode.Recovery;

            this.LastLogicalSequenceNumber = startingLogicalSequenceNumber;
            this.TransactionsMap           = transactionsMap;
            this.CurrentLogTailEpoch       = currentLogTailEpoch;
            this.LastStableLsn             = lastStableLsn;
            this.LastPhysicalRecord        = PhysicalLogRecord.InvalidPhysicalLogRecord;

            this.ProgressVector = progressVector;
            this.recoveredLastCompletedBeginCheckpointRecord = recoveredLastCompletedBeginCheckpointRecord;

            this.tracer = tracer;
            this.recoveredLastEndCheckpointRecord = recoveredLastEndCheckpointRecord;
        }
 public bool ShouldCheckpointOnPrimary(
     TransactionMap txMap,
     out List <BeginTransactionOperationLogRecord> abortTxList)
 {
     return(this.ShouldCheckpoint(txMap, out abortTxList));
 }