private async Task TruncateTailAsync(LogicalSequenceNumber tailLsn)
        {
            FabricEvents.Events.TruncateTail(this.tracer.Type, tailLsn.LSN);

            Utility.Assert(
                (this.roleContextDrainState.ReplicaRole == ReplicaRole.IdleSecondary) || (this.roleContextDrainState.ReplicaRole == ReplicaRole.ActiveSecondary),
                "(this.Role == ReplicaRole.IdleSecondary) || (this.Role == ReplicaRole.ActiveSecondary)");

            Utility.Assert(
                this.checkpointManager.LastStableLsn <= tailLsn,
                "this.lastStableLsn <= tailLsn. last stable lsn :{0}",
                this.checkpointManager.LastStableLsn.LSN);

            ApplyContext falseProgressApplyContext = ApplyContext.SecondaryFalseProgress;

            var truncateTailMgr = new TruncateTailManager(
                this.replicatedLogManager,
                this.transactionManager.TransactionsMap,
                this.stateManager,
                this.backupManager,
                tailLsn,
                falseProgressApplyContext,
                this.recoveryManager.RecoveryLogsReader,
                this.tracer);

            var currentRecord = await truncateTailMgr.TruncateTailAsync();

            Utility.Assert(
                currentRecord.Lsn == tailLsn,
                "TruncateTail: V1 replicator ensures that lsns are continuous. currentLsn {0} == tailLsn {1}",
                currentRecord.Lsn, tailLsn);

            this.checkpointManager.ResetStableLsn(tailLsn);
            this.recoveryManager.OnTailTruncation(tailLsn);

            // 6450429: Replicator maintains three values for supporting consistent reads and snapshot.
            // These values have to be updated as part of the false progress correction.
            // ReadConsistentAfterLsn is used to ensure that all state providers have applied the highest recovery or copy log operation
            // that they might have seen in their current checkpoint. Reading at a tailLsn below this cause inconsistent reads across state providers.
            // Since this was a FALSE PROGRESS copy, replica is still using the checkpoints it has recovered.
            // We have undone any operation that could have been false progressed in these checkpoints (Fuzzy checkpoint only) and ensured all state providers are applied to the same barrier.
            // Hence readConsistentAfterLsn is set to the new tail of the log.
            this.ReadConsistentAfterLsn = tailLsn;

            // lastAppliedBarrierRecord is used to get the current visibility sequence number.
            // Technically currentRecord (new tail record) may not be a barrier however it has the guarantee of a barrier:
            //      All records before tail, including the tail must have been applied.
            // Hence we the lastAppliedBarrierRecord to the new tail record.
            // Note: No other property but .Lsn can be used.
            this.recordsProcessor.TruncateTail(currentRecord);

            // Last value that is kept in the replicator (Version Manager) is the lastDispatchingBarrier.
            // This is used for read your writes support.
            // In this case it is not necessary to modify it since this replica either has not made any new progress (its own write) or it gets elected primary and before it can do anything else
            // dispatches a new barrier which will become the lastDispatchingBarrier
        }
Esempio n. 2
0
        internal static void Assert(bool condition, string format, ApplyContext param1)
        {
            if (condition == false)
            {
                var failFastMessage = string.Format(System.Globalization.CultureInfo.InvariantCulture, format, param1);
                FailFast(failFastMessage);

                // AMW - Force break into debugger for ease of debugging
                Debugger.Break();
            }
        }
    public ApplyContext apply()
    {
        ApplyContext _localctx = new ApplyContext(Context, State);

        EnterRule(_localctx, 0, RULE_apply);
        try {
            State = 18;
            ErrorHandler.Sync(this);
            switch (TokenStream.LA(1))
            {
            case T__0:
                EnterOuterAlt(_localctx, 1);
                {
                    State = 10; Match(T__0);
                    State = 11; Match(T__1);
                    State = 12; columns();
                    State = 13; Match(T__2);
                    State = 14; aggregates();
                    State = 15; Match(T__3);
                }
                break;

            case T__4:
                EnterOuterAlt(_localctx, 2);
                {
                    State = 17; aggregates();
                }
                break;

            default:
                throw new NoViableAltException(this);
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
Esempio n. 4
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;
        }
 public ApplyController(ApplyContext applyContext, IMemoryCache memoryCache, IHostingEnvironment env)
 {
     _context     = applyContext;
     _memoryCache = memoryCache;
     _hosting     = env;
 }
Esempio n. 6
0
 public MajordomoAudit(ApplyContext context) : base(context)
 {
     //Console.WriteLine($"我是类:{ GetType().ToString()}");
 }
Esempio n. 7
0
 private static bool IsPrimaryOperation(ApplyContext applyContext)
 {
     return(((int)applyContext & (int)ApplyContext.PRIMARY) == (int)ApplyContext.PRIMARY);
 }
Esempio n. 8
0
        /// <summary>
        /// The apply async.
        /// </summary>
        /// <param name="lsn">
        /// The lsn.
        /// </param>
        /// <param name="transactionBase">
        /// The transaction base.
        /// </param>
        /// <param name="data">
        /// The data.
        /// </param>
        /// <param name="applyContext">
        /// The apply context.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        Task <object> IStateProvider2.ApplyAsync(
            long lsn,
            TransactionBase transactionBase,
            OperationData data,
            ApplyContext applyContext)
        {
            // Get the operation.
            var operation = Operation.Deserialize(data[0]);

            // Resume the existing transaction for this operation or start a transaction for this operation.
            bool             applied;
            OperationContext context;
            DatabaseTransaction <TKey, TValue> tx;

            if (IsPrimaryOperation(applyContext) && this.inProgressOperations.TryGetValue(operation.Id, out context))
            {
                applied = true;
                tx      = context.DatabaseTransaction;
                tx.Resume();
            }
            else
            {
                // The operation has not yet been applied and therefore a transaction has not been initiated.
                applied = false;
                tx      = this.tables.CreateTransaction();
            }

            /*var part = this.replicator.StatefulPartition;
             * var operationString = JsonConvert.SerializeObject(operation, SerializationSettings.JsonConfig);
             * Trace.TraceInformation(
             *  $"[{this.partitionId}/{this.replicator.InitializationParameters.ReplicaId} r:{part.ReadStatus} w:{part.WriteStatus}] ApplyAsync(lsn: {lsn}, tx: {transactionBase.Id}, op: {operationString} (length: {data?.Length ?? 0}), context: {applyContext})");
             */
            try
            {
                // If the operation has not yet been applied, apply it.
                if (!applied)
                {
                    //Trace.TraceInformation($"{applyContext} Apply {operationString}");
                    operation.Apply(tx.Table);
                }

                //Trace.TraceInformation($"{applyContext} Commit {operationString}");
                tx.Commit();
            }
            catch (Exception exception)
            {
                tx.Rollback();

                return(Task.FromException <object>(exception));
            }
            finally
            {
                if (IsPrimaryOperation(applyContext))
                {
                    this.inProgressOperations.TryRemove(operation.Id, out context);
                }

                tx.Dispose();
            }

            return(Task.FromResult(default(object)));
        }
Esempio n. 9
0
 public abstract void Audit(ApplyContext context);
Esempio n. 10
0
 protected void AuditNext(ApplyContext context)
 {
     this._nextAuditor?.Audit(context);
 }
Esempio n. 11
0
 public AbstractAudit(ApplyContext context)
 {
     // Console.WriteLine($"我是类:{ GetType().ToString()}");
     this.Context = context;
 }
Esempio n. 12
0
 public DepManagerAudit(ApplyContext context) : base(context)
 {
     //Console.WriteLine($"我是类:{ GetType().ToString()}");
 }