private void CheckActionResultsAndUpdateAdProperties(AmServerName initialSourceServer, AmServerName targetServer, IBestCopySelector bcs, Exception lastException, int countServersTried, int natSkippedServersCount) { Exception lastException2 = bcs.LastException; if (countServersTried == 0) { lastException = lastException2; } else if (lastException == null && natSkippedServersCount == countServersTried) { AmTrace.Diagnostic("{0} for database {1} was not attempted in any of the servers in the DAG since all the servers in the DAG recently unsuccessful in performing the failover action.", new object[] { base.ActionCode, base.DatabaseName }); lastException = new AmDbOperationAttempedTooSoonException(base.DatabaseName); } else if (bcs.BestCopySelectionType == AmBcsType.BestCopySelection && lastException != null && lastException2 != null) { lastException = lastException2; } this.UpdateAdProperties(lastException == null, initialSourceServer); AmHelper.ThrowDbActionWrapperExceptionIfNecessary(lastException); }
protected override void MountInternal(MountFlags storeMountFlags, AmMountFlags amMountFlags, DatabaseMountDialOverride mountDialOverride, ref AmDbOperationDetailedStatus mountStatus) { Exception ex = null; int natSkippedServersCount = 0; int num = 0; bool flag = true; if (ThirdPartyManager.IsThirdPartyReplicationEnabled) { flag = false; } if (base.ActionCode.IsAdminOperation) { if (base.State.IsActiveServerValid) { flag = false; } else { AmTrace.Debug("Mount issued for the first time on this database. We will try all the available servers. (db={0})", new object[] { base.DatabaseName }); } } AmServerName amServerName = base.State.ActiveServer; if (AmServerName.IsNullOrEmpty(amServerName)) { amServerName = new AmServerName(base.Database.Server.Name); } AmBcsSkipFlags skipValidationChecks = AmBcsSkipFlags.SkipAll; if (flag) { skipValidationChecks = AmBcsSkipFlags.None; } IBestCopySelector bestCopySelector = this.ConstructBestCopySelector(flag, skipValidationChecks, null, amServerName, amServerName, mountDialOverride, null); AmDbNodeAttemptTable dbNodeAttemptTable = AmSystemManager.Instance.DbNodeAttemptTable; if (base.ActionCode.IsAdminOperation) { dbNodeAttemptTable.ClearFailedTime(base.DatabaseGuid); } AmServerName sourceServer = amServerName; AmAcllReturnStatus amAcllReturnStatus = null; AmServerName amServerName2 = bestCopySelector.FindNextBestCopy(); while (amServerName2 != null) { num++; base.DbTrace.Debug("Attempting mount on server {0}", new object[] { amServerName2 }); this.AttemptMountOnServer(amServerName2, sourceServer, storeMountFlags, amMountFlags, UnmountFlags.SkipCacheFlush, mountDialOverride, AmBcsSkipFlags.None, flag, ref natSkippedServersCount, ref amAcllReturnStatus, out ex); base.DbTrace.Debug("AttemptMountOnServer returned AcllStatus: {0}", new object[] { amAcllReturnStatus }); sourceServer = base.State.ActiveServer; if (ex == null) { break; } bestCopySelector.ErrorLogger.ReportServerFailure(amServerName2, "CopyHasBeenTriedCheck", ex.Message); if (ex is AmRoleChangedWhileOperationIsInProgressException || ex is AmMountTimeoutException) { break; } amServerName2 = bestCopySelector.FindNextBestCopy(); base.CurrentAttemptNumber++; } this.CheckActionResultsAndUpdateAdProperties(amServerName, null, bestCopySelector, ex, num, natSkippedServersCount); }
protected override void MoveInternal(MountFlags storeMountFlags, UnmountFlags dismountFlags, DatabaseMountDialOverride mountDialoverride, AmServerName fromServer, AmServerName targetServer, bool tryOtherHealthyServers, AmBcsSkipFlags skipValidationChecks, string componentName, ref AmDbOperationDetailedStatus moveStatus) { AmDbNodeAttemptTable dbNodeAttemptTable = AmSystemManager.Instance.DbNodeAttemptTable; IBestCopySelector bestCopySelector = null; Exception ex = null; bool flag = false; int num = 0; int natSkippedServersCount = 0; if (!base.State.IsEntryExist) { base.DbTrace.Error("Database was never mounted. Move is applicable only if it was mounted at least once", new object[0]); throw new AmDatabaseNeverMountedException(); } if (base.State.IsAdminDismounted) { AmTrace.Diagnostic("Moving a dismounted database {0}. The database will be moved, but won't be mounted", new object[] { base.DatabaseName }); } moveStatus.InitialDbState = base.State.Copy(); AmServerName activeServer = base.State.ActiveServer; AmAcllReturnStatus amAcllReturnStatus = null; bool flag2 = true; try { this.CheckIfMoveApplicableForDatabase(base.State.ActiveServer, fromServer, base.ActionCode); bestCopySelector = this.ConstructBestCopySelector(tryOtherHealthyServers, skipValidationChecks, null, activeServer, targetServer, mountDialoverride, componentName); if (base.ActionCode.IsAutomaticShutdownSwitchover) { base.AttemptDismount(base.State.ActiveServer, dismountFlags, true, out ex); flag = true; } AmServerName amServerName = bestCopySelector.FindNextBestCopy(); while (amServerName != null) { num++; if (!flag) { base.AttemptDismount(activeServer, dismountFlags, true, out ex); flag = true; } AmMountFlags amMountFlags = AmMountFlags.None; if (BitMasker.IsOn((int)skipValidationChecks, 4)) { amMountFlags = AmMountFlags.MoveWithSkipHealth; } this.AttemptMountOnServer(amServerName, base.State.ActiveServer, storeMountFlags, amMountFlags, dismountFlags, mountDialoverride, skipValidationChecks, tryOtherHealthyServers, ref natSkippedServersCount, ref amAcllReturnStatus, out ex); base.DbTrace.Debug("AttemptMountOnServer returned AcllStatus: {0}", new object[] { amAcllReturnStatus }); moveStatus.AddSubstatus(new AmDbOperationSubStatus(amServerName, amAcllReturnStatus, ex)); if (ex == null) { flag2 = false; break; } bestCopySelector.ErrorLogger.ReportServerFailure(amServerName, "CopyHasBeenTriedCheck", ex.Message); if (ex is AmRoleChangedWhileOperationIsInProgressException) { flag2 = false; break; } if (ex is AmMountTimeoutException) { flag2 = false; break; } amServerName = bestCopySelector.FindNextBestCopy(); base.CurrentAttemptNumber++; } } finally { moveStatus.FinalDbState = base.State.Copy(); } if (flag2) { MountStatus storeDatabaseMountStatus = AmStoreHelper.GetStoreDatabaseMountStatus(base.State.ActiveServer, base.Database.Guid); if (storeDatabaseMountStatus != base.State.MountStatus) { ReplayCrimsonEvents.MismatchErrorAfterMove.Log <string, Guid, AmServerName, MountStatus, MountStatus>(base.Database.Name, base.Database.Guid, base.State.ActiveServer, base.State.MountStatus, storeDatabaseMountStatus); if (storeDatabaseMountStatus == MountStatus.Dismounted) { base.State.MountStatus = MountStatus.Dismounted; base.WriteState(); } } } this.CheckActionResultsAndUpdateAdProperties(activeServer, targetServer, bestCopySelector, ex, num, natSkippedServersCount); }