Exemple #1
0
        private static bool IsMaxActivesUnderThreshold(AmServerName serverName, Func <IADServer, int?> getMaxActiveDbsLimit, out int?maxActiveDatabases)
        {
            bool      result    = true;
            int?      num       = null;
            IADServer iadserver = Dependencies.ReplayAdObjectLookup.ServerLookup.FindServerByFqdn(serverName.Fqdn);

            if (iadserver != null)
            {
                num = getMaxActiveDbsLimit(iadserver);
                AmDatabaseStateTracker databaseStateTracker = AmSystemManager.Instance.DatabaseStateTracker;
                if (databaseStateTracker != null && databaseStateTracker.IsMaxActivesExceeded(serverName, num))
                {
                    result = false;
                }
            }
            else
            {
                AmTrace.Error("Failed to find server {0}", new object[]
                {
                    serverName
                });
                FailedToFindServerException ex = new FailedToFindServerException(serverName.Fqdn);
                ReplayCrimsonEvents.ADObjectLookupError.LogPeriodic <string, FailedToFindServerException>(serverName.NetbiosName, DiagCore.DefaultEventSuppressionInterval, ex.Message, ex);
            }
            maxActiveDatabases = num;
            return(result);
        }
Exemple #2
0
        internal static bool WriteStateSyncMountStatus(AmConfig amConfig, AmDbStateInfo stateInfo, Guid databaseGuid, AmServerName activeServer, MountStatus mountStatus)
        {
            bool flag = false;

            if (mountStatus == MountStatus.Mounted)
            {
                stateInfo.UpdateActiveServerAndIncrementFailoverSequenceNumber(activeServer);
                stateInfo.LastMountedServer         = activeServer;
                stateInfo.IsAdminDismounted         = false;
                stateInfo.MountStatus               = mountStatus;
                stateInfo.IsAutomaticActionsAllowed = true;
                stateInfo.LastMountedTime           = DateTime.UtcNow;
                flag = true;
            }
            else if (stateInfo.IsEntryExist)
            {
                stateInfo.MountStatus = mountStatus;
                if (stateInfo.IsMountSucceededAtleastOnce)
                {
                    stateInfo.UpdateActiveServerAndIncrementFailoverSequenceNumber(activeServer);
                    stateInfo.LastMountedServer = activeServer;
                }
                flag = true;
            }
            if (flag && AmDbAction.WriteState(amConfig, stateInfo, false))
            {
                AmDatabaseStateTracker databaseStateTracker = AmSystemManager.Instance.DatabaseStateTracker;
                if (databaseStateTracker != null)
                {
                    databaseStateTracker.UpdateActive(databaseGuid, activeServer);
                }
            }
            return(flag);
        }
Exemple #3
0
        private bool UpdateMaster(AmServerName newMasterServer, bool isMountSkipped)
        {
            bool         flag         = false;
            AmServerName activeServer = base.State.ActiveServer;

            if (!AmServerName.IsEqual(activeServer, newMasterServer))
            {
                AmTrace.Debug("Active server changed. (previous={0}, current={1})", new object[]
                {
                    activeServer,
                    newMasterServer
                });
                flag = true;
            }
            base.ReportStatus(AmDbActionStatus.UpdateMasterServerInitiated);
            bool flag2 = isMountSkipped ? base.WriteStateMountSkipped(newMasterServer) : base.WriteStateMountStart(newMasterServer);

            if (flag2)
            {
                AmDatabaseStateTracker databaseStateTracker = AmSystemManager.Instance.DatabaseStateTracker;
                if (databaseStateTracker != null)
                {
                    databaseStateTracker.UpdateActive(base.DatabaseGuid, newMasterServer);
                }
            }
            if (flag)
            {
                if (!activeServer.IsEmpty)
                {
                    ReplayCrimsonEvents.ActiveServerChanged.LogGeneric(base.PrepareSubactionArgs(new object[]
                    {
                        activeServer,
                        newMasterServer
                    }));
                }
                else
                {
                    ReplayCrimsonEvents.ActiveServerChanged.LogGeneric(base.PrepareSubactionArgs(new object[]
                    {
                        "<none>",
                        newMasterServer
                    }));
                }
            }
            base.ReportStatus(AmDbActionStatus.UpdateMasterServerFinished);
            return(flag);
        }
Exemple #4
0
        private bool AttemptMountOnServer(AmServerName serverToMount, AmServerName sourceServer, MountFlags storeMountFlags, AmMountFlags amMountFlags, UnmountFlags dismountFlags, DatabaseMountDialOverride mountDialoverride, AmBcsSkipFlags skipValidationChecks, bool tryOtherHealthyServers, ref int natSkippedServersCount, ref AmAcllReturnStatus acllStatus, out Exception lastException)
        {
            bool flag = true;
            bool fLossyMountEnabled    = false;
            bool isSuccess             = false;
            bool isAcllSuccess         = false;
            bool isMasterServerChanged = false;

            lastException = null;
            bool isSuccess2;

            try
            {
                acllStatus = new AmAcllReturnStatus();
                AmDbNodeAttemptTable dbNodeAttemptTable = AmSystemManager.Instance.DbNodeAttemptTable;
                if (!base.ActionCode.IsAdminOperation && base.Config.IsIgnoreServerDebugOptionEnabled(serverToMount))
                {
                    ReplayCrimsonEvents.OperationNotPerformedDueToDebugOption.Log <string, string, string>(serverToMount.Fqdn, AmDebugOptions.IgnoreServerFromAutomaticActions.ToString(), "Mount database");
                    throw new AmDbOperationException("Mount not applicable for a server when debug options are enabled");
                }
                bool flag2 = this.IsAcllRequired(serverToMount, sourceServer);
                if (dbNodeAttemptTable.IsOkayForAction(base.Database, serverToMount, base.ActionCode))
                {
                    if (!flag2)
                    {
                        acllStatus.NoLoss       = true;
                        acllStatus.MountAllowed = true;
                    }
                    else
                    {
                        Stopwatch stopwatch = new Stopwatch();
                        stopwatch.Start();
                        try
                        {
                            ReplayCrimsonEvents.AcllInitiated.LogGeneric(base.PrepareSubactionArgs(new object[]
                            {
                                serverToMount,
                                sourceServer
                            }));
                            AmAcllReturnStatus tempAcllStatus = null;
                            lastException = AmHelper.HandleKnownExceptions(delegate(object param0, EventArgs param1)
                            {
                                this.RunAttemptCopyLastLogsOnServer(serverToMount, sourceServer, mountDialoverride, skipValidationChecks, 1, 15000, 15000, 15000, out fLossyMountEnabled, ref tempAcllStatus);
                                isAcllSuccess = true;
                            });
                            acllStatus = tempAcllStatus;
                        }
                        finally
                        {
                            stopwatch.Stop();
                            if (isAcllSuccess)
                            {
                                ReplayCrimsonEvents.AcllSuccess2.LogGeneric(base.PrepareSubactionArgs(new object[]
                                {
                                    serverToMount,
                                    fLossyMountEnabled,
                                    stopwatch.Elapsed
                                }));
                            }
                            else
                            {
                                ReplayCrimsonEvents.AcllFailed.LogGeneric(base.PrepareSubactionArgs(new object[]
                                {
                                    serverToMount,
                                    stopwatch.Elapsed,
                                    (lastException != null) ? lastException.Message : ReplayStrings.UnknownError
                                }));
                            }
                        }
                        if (lastException == null)
                        {
                            if (base.State.IsAdminDismounted && !base.ActionCode.IsAdminMountOperation)
                            {
                                AmTrace.Debug("Skipping mount for database '{0}' on server '{1}' since it was admin dismounted.", new object[]
                                {
                                    base.DatabaseName,
                                    serverToMount
                                });
                                if (this.UpdateMaster(serverToMount, true))
                                {
                                    this.SendReplicaNotifications();
                                    isMasterServerChanged = true;
                                }
                                isSuccess = true;
                                flag      = false;
                            }
                        }
                        else
                        {
                            flag = false;
                        }
                    }
                    if (!flag)
                    {
                        goto IL_45C;
                    }
                    isSuccess     = false;
                    lastException = null;
                    Stopwatch stopwatch2 = new Stopwatch();
                    stopwatch2.Start();
                    try
                    {
                        ReplayCrimsonEvents.DirectMountInitiated.LogGeneric(base.PrepareSubactionArgs(new object[]
                        {
                            serverToMount,
                            storeMountFlags,
                            fLossyMountEnabled,
                            amMountFlags
                        }));
                        lastException = AmHelper.HandleKnownExceptions(delegate(object param0, EventArgs param1)
                        {
                            TimeSpan mountTimeout = this.DetermineMountTimeout(skipValidationChecks);
                            this.RunMountDatabaseDirect(serverToMount, storeMountFlags, amMountFlags, fLossyMountEnabled, mountTimeout, ref isMasterServerChanged);
                            isSuccess = true;
                        });
                        goto IL_45C;
                    }
                    finally
                    {
                        stopwatch2.Stop();
                        if (isSuccess)
                        {
                            ReplayCrimsonEvents.DirectMountSuccess.LogGeneric(base.PrepareSubactionArgs(new object[]
                            {
                                serverToMount,
                                stopwatch2.Elapsed
                            }));
                        }
                        else
                        {
                            string text = (lastException != null) ? lastException.Message : ReplayStrings.UnknownError;
                            ReplayCrimsonEvents.DirectMountFailed.LogGeneric(base.PrepareSubactionArgs(new object[]
                            {
                                serverToMount,
                                stopwatch2.Elapsed,
                                text
                            }));
                        }
                    }
                }
                natSkippedServersCount++;
                AmTrace.Debug("Mount for database '{0}' skipped server '{1}' since a recent mount operation on this node failed.", new object[]
                {
                    base.DatabaseName,
                    serverToMount
                });
                lastException = new AmDbOperationAttempedTooSoonException(base.DatabaseName);
                ReplayCrimsonEvents.MountServerSkipped.LogGeneric(base.PrepareSubactionArgs(new object[]
                {
                    serverToMount,
                    lastException.Message
                }));
                isSuccess = false;
IL_45C:
                isSuccess2 = isSuccess;
            }
            finally
            {
                if (!isMasterServerChanged)
                {
                    AmTrace.Error("The active server for database '{0}' has not been changed, so we need to rollback the database state tracker information.", new object[]
                    {
                        base.DatabaseName
                    });
                    AmDatabaseStateTracker databaseStateTracker = AmSystemManager.Instance.DatabaseStateTracker;
                    if (databaseStateTracker != null)
                    {
                        databaseStateTracker.UpdateActive(base.DatabaseGuid, sourceServer);
                    }
                }
            }
            return(isSuccess2);
        }