Example #1
0
        internal static void WaitUntilDatabaseIsNotMounted(IADDatabase database, int seconds)
        {
            bool flag = true;

            DatabaseTasks.Trace("Waiting for database {0} to reach dismounted/dismounting state for {1} seconds", new object[]
            {
                database.Name,
                seconds
            });
            for (int i = 0; i < seconds; i++)
            {
                if (!AmStoreHelper.IsMounted(null, database.Guid))
                {
                    flag = false;
                    break;
                }
                Thread.Sleep(1000);
            }
            if (flag)
            {
                DatabaseTasks.Trace("Database is still mounted {0} after {1} seconds", new object[]
                {
                    database.Name,
                    seconds
                });
            }
        }
        private Exception TryToDismountClean()
        {
            Exception result = null;

            try
            {
                AmStoreHelper.RemoteDismount(null, this.DatabaseGuid, UnmountFlags.None, true);
            }
            catch (AmServerException ex)
            {
                result = ex;
            }
            catch (AmServerTransientException ex2)
            {
                result = ex2;
            }
            catch (MapiPermanentException ex3)
            {
                result = ex3;
            }
            catch (MapiRetryableException ex4)
            {
                result = ex4;
            }
            return(result);
        }
Example #3
0
 // Token: 0x0600107A RID: 4218 RVA: 0x00045C69 File Offset: 0x00043E69
 internal override void ActiveRecoveryActionInternal()
 {
     if (!AmStoreHelper.IsMountedLocally(base.Database.Guid))
     {
         DatabaseTasks.Move(base.Database, Environment.MachineName);
         return;
     }
     this.m_moveWasSkipped = true;
     base.Trace("Skipping failover since the database is already mounted", new object[0]);
 }
        private Exception DismountDatabaseOrKillStore()
        {
            LogCopyServerContext.Tracer.TraceDebug((long)this.GetHashCode(), "DismountDatabaseOrKillStore() called.");
            Exception ex = AmStoreHelper.Dismount(this.Database.DatabaseGuid, UnmountFlags.SkipCacheFlush);

            if (ex != null)
            {
                ex = new DatabaseDismountOrKillStoreException(this.Database.DatabaseName, Environment.MachineName, ex.Message, ex);
                LogCopyServerContext.Tracer.TraceError <string, Exception>((long)this.GetHashCode(), "DismountDatabaseOrKillStore() for DB '{0}' failed: {1}", this.Database.DatabaseName, ex);
            }
            return(ex);
        }
Example #5
0
        protected override void InternalProcessRecord()
        {
            TaskLogger.LogEnter(new object[]
            {
                this.DataObject
            });
            bool       flag   = false;
            bool       flag2  = false;
            bool       flag3  = true;
            bool       flag4  = false;
            bool       flag5  = false;
            Server     server = this.OwnerServer;
            ADObjectId id     = new ADObjectId(this.OwnerServer.Guid);

            if (server == null)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorDBOwningServerNotFound(this.DataObject.Identity.ToString())), ErrorCategory.InvalidOperation, this.DataObject.Identity);
            }
            try
            {
                if ((!this.IsEdbFilePathChanged && !this.isLogFolderPathChanged) || (base.ConfigurationOnly && !this.shouldContinueToDoConfigurationOnly))
                {
                    TaskLogger.LogExit();
                }
                else
                {
                    if (this.needReportProgress)
                    {
                        base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressCheckingReplayState, 10);
                    }
                    base.WriteVerbose(Strings.VerboseConnectionAdminRpcInterface(this.OwnerServer.Fqdn));
                    MdbStatus mdbStatus = AmStoreHelper.GetMdbStatus(this.OwnerServer.Fqdn, this.DataObject.Guid);
                    if (mdbStatus == null)
                    {
                        base.WriteError(new InvalidOperationException(Strings.ErrorFailedToGetDatabaseStatus(this.Identity.ToString())), ErrorCategory.InvalidOperation, this.Identity);
                    }
                    if ((mdbStatus.Status & MdbStatusFlags.Backup) != MdbStatusFlags.Offline)
                    {
                        base.WriteError(new InvalidOperationException(Strings.ErrorBackupInProgress(this.Identity.ToString())), ErrorCategory.InvalidOperation, this.Identity);
                    }
                    else if ((mdbStatus.Status & MdbStatusFlags.Online) != MdbStatusFlags.Offline)
                    {
                        if (!this.Force && !base.ShouldContinue(base.ConfigurationOnly ? Strings.WarningDismountDatabaseToDoConfigurationOnly(this.Identity.ToString()) : Strings.WarningDismountDatabaseToContinue(this.Identity.ToString())))
                        {
                            TaskLogger.LogExit();
                            return;
                        }
                        if (this.needReportProgress)
                        {
                            base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressDismountingDatabase(this.Identity.ToString()), 20);
                        }
                        base.WriteVerbose(TaskVerboseStringHelper.GetReadObjectVerboseString(id, base.DataSession, typeof(Server)));
                        try
                        {
                            base.WriteVerbose(Strings.VerboseUnmountDatabase(this.DataObject.Identity.ToString()));
                            AmRpcClientHelper.DismountDatabase(ADObjectWrapperFactory.CreateWrapper(this.DataObject), 0);
                        }
                        catch (AmServerException ex)
                        {
                            Exception ex2;
                            if (ex.TryGetInnerExceptionOfType(out ex2))
                            {
                                TaskLogger.Trace("MoveDatabasePath.InternalProcessRecord raises exception while unmounting database: {0}", new object[]
                                {
                                    ex2.Message
                                });
                            }
                            else if (ex.TryGetInnerExceptionOfType(out ex2))
                            {
                                TaskLogger.Trace("MoveDatabasePath.InternalProcessRecord raises exception while unmounting database: {0}", new object[]
                                {
                                    ex2.Message
                                });
                            }
                            else if (ex is AmDatabaseNeverMountedException)
                            {
                                TaskLogger.Trace("MoveDatabasePath.InternalProcessRecord raises exception while unmounting database: {0}", new object[]
                                {
                                    ex.Message
                                });
                            }
                            else
                            {
                                TaskLogger.Trace("MoveDatabasePath.InternalProcessRecord raises exception while unmounting database: {0}", new object[]
                                {
                                    ex.Message
                                });
                                base.WriteError(ex, ErrorCategory.InvalidOperation, this.DataObject.Identity);
                            }
                        }
                        catch (AmServerTransientException ex3)
                        {
                            TaskLogger.Trace("MoveDatabasePath.InternalProcessRecord raises exception while dismounting database: {0}", new object[]
                            {
                                ex3.Message
                            });
                            base.WriteError(ex3, ErrorCategory.InvalidOperation, this.DataObject.Identity);
                        }
                        flag = true;
                    }
                    if (!base.ConfigurationOnly)
                    {
                        if (this.IsDatabaseFilesCreated && this.IsEdbFilePathChanged)
                        {
                            if (this.needReportProgress)
                            {
                                base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressCopyingEdbFile, 25);
                            }
                            if (!this.TryCopyFile(this.OriginalEdbFilePath.PathName, this.TargetEdbFilePath.PathName))
                            {
                                base.WriteError(new InvalidOperationException(Strings.ErrorFailedToMoveEdbFile(this.OriginalEdbFilePath.PathName, this.TargetEdbFilePath.PathName)), ErrorCategory.InvalidOperation, this.Identity);
                            }
                            flag2 = true;
                        }
                        if (this.isLogFolderPathChanged)
                        {
                            if (this.needReportProgress)
                            {
                                base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressCopyingLogFiles, 45);
                            }
                            base.WriteVerbose(Strings.VerboseCopyDatabaseLogFiles(base.OwnerServerName, this.OldLogFolderPath.PathName, this.LogFolderPath.PathName));
                            if (!this.TryCopyPath(this.OldLogFolderPath.PathName, this.LogFolderPath.PathName, new WmiWrapper.FileFilter(this.LogFileFilter)))
                            {
                                base.WriteError(new InvalidOperationException(Strings.ErrorFailedToMoveDatabaseLogFiles(this.OldLogFolderPath.PathName, this.LogFolderPath.PathName)), ErrorCategory.InvalidOperation, this.DataObject.Identity);
                            }
                            flag4 = true;
                        }
                    }
                    if (this.needReportProgress)
                    {
                        base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressSavingADObject, 69);
                    }
                    base.InternalProcessRecord();
                    flag3 = false;
                    if (flag2)
                    {
                        if (this.needReportProgress)
                        {
                            base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressDeletingEdbFile, 72);
                        }
                        if (!this.TryDeleteFile(this.OriginalEdbFilePath.PathName))
                        {
                            this.WriteWarning(Strings.FailedToDeleteOldEdbFile(this.OriginalEdbFilePath.PathName));
                            TaskLogger.Trace("MoveDatabasePath: delete edb \"{0}\" file failed", new object[]
                            {
                                this.OriginalEdbFilePath.PathName
                            });
                        }
                    }
                    if (flag4)
                    {
                        if (this.needReportProgress)
                        {
                            base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressDeletingLogFiles, 81);
                        }
                        base.WriteVerbose(Strings.VerboseDeleteDatabaseLogFiles(this.OwnerServer.Fqdn, this.OldLogFolderPath.PathName));
                        if (!WmiWrapper.DeleteFilesInDirectory(this.OwnerServer.Fqdn, this.OldLogFolderPath.PathName, new WmiWrapper.FileFilter(this.LogPathFilter)))
                        {
                            this.WriteWarning(Strings.FailedDeleteOldDatabaseLogFiles(this.OwnerServer.Fqdn, this.OldLogFolderPath.PathName));
                            TaskLogger.Trace("Failed to delete some of the orignal log files.", new object[0]);
                        }
                    }
                    if (this.moveCatalogs && SystemConfigurationTasksHelper.TryCreateDirectory(this.OwnerServer.Fqdn, this.targetCatalogsPath, null, new Task.TaskVerboseLoggingDelegate(base.WriteVerbose), new Task.TaskWarningLoggingDelegate(this.WriteWarning)))
                    {
                        if (this.needReportProgress)
                        {
                            base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressCopyingCatalog, 87);
                        }
                        try
                        {
                            base.WriteVerbose(Strings.VerboseCopyDatabaseCatalogFiles(this.OwnerServer.Fqdn, this.originalCatalogsPath, this.targetCatalogsPath));
                            if (WmiWrapper.CopyFilesInDirectory(this.OwnerServer.Fqdn, this.originalCatalogsPath, this.targetCatalogsPath, new WmiWrapper.FileFilter(MoveDatabasePath.ReturnAllFiles)))
                            {
                                if (this.needReportProgress)
                                {
                                    base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressDeletingCatalog, 92);
                                }
                                base.WriteVerbose(Strings.VerboseDeleteDatabaseCatalogFiles(this.OwnerServer.Fqdn, this.originalCatalogsPath));
                                WmiWrapper.DeleteFilesInDirectory(this.OwnerServer.Fqdn, this.originalCatalogsPath, new WmiWrapper.FileFilter(MoveDatabasePath.ReturnAllFiles));
                                base.WriteVerbose(Strings.VerboseDeleteDirectory(this.OwnerServer.Fqdn, this.originalCatalogsPath));
                                WmiWrapper.RemoveDirectory(this.OwnerServer.Fqdn, this.originalCatalogsPath);
                            }
                        }
                        catch (ManagementException ex4)
                        {
                            TaskLogger.Trace("MoveDatabasePath raised exception {0} while moving catalog files", new object[]
                            {
                                ex4.ToString()
                            });
                            this.WriteWarning(Strings.ErrorMovingCatalogs(this.Identity.ToString(), ex4.Message));
                        }
                        catch (ArgumentException ex5)
                        {
                            TaskLogger.Trace("MoveDatabasePath raised exception {0} while moving catalog files", new object[]
                            {
                                ex5.ToString()
                            });
                            this.WriteWarning(Strings.ErrorMovingCatalogs(this.Identity.ToString(), ex5.Message));
                        }
                    }
                    this.SendNotificationRpcToReplayService();
                    flag5 = true;
                }
            }
            catch (WmiException ex6)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorFailedToConnectToServer(base.OwnerServerName, ex6.Message)), ErrorCategory.InvalidOperation, this.Identity);
            }
            catch (UnauthorizedAccessException ex7)
            {
                base.WriteError(new InvalidOperationException(Strings.ErrorFailedToConnectToServer(base.OwnerServerName, ex7.Message)), ErrorCategory.InvalidOperation, this.Identity);
            }
            finally
            {
                if (flag3)
                {
                    if (flag2 && !this.TryDeleteFile(this.TargetEdbFilePath.PathName))
                    {
                        this.WriteWarning(Strings.FailedToDeleteTempEdbFile(this.TargetEdbFilePath.PathName));
                        TaskLogger.Trace("MoveDatabasePath: delete edb \"{0}\" file failed", new object[]
                        {
                            this.TargetEdbFilePath.PathName
                        });
                    }
                    if (flag4)
                    {
                        TaskLogger.Trace("Error occurs when Copying path. delete copied log files", new object[0]);
                        base.WriteVerbose(Strings.VerboseDeleteDatabaseLogFiles(this.OwnerServer.Fqdn, this.LogFolderPath.PathName));
                        if (!WmiWrapper.DeleteFilesInDirectory(this.OwnerServer.Fqdn, this.LogFolderPath.PathName, new WmiWrapper.FileFilter(this.LogFileFilter)))
                        {
                            this.WriteWarning(Strings.FailedDeleteTempDatabaseLogFiles(base.OwnerServerName, this.LogFolderPath.PathName));
                            TaskLogger.Trace("Failed to delete some of the copied log files.", new object[0]);
                        }
                    }
                }
                if (!base.ConfigurationOnly && flag)
                {
                    if (this.needReportProgress)
                    {
                        base.WriteProgress(Strings.ProgressMoveDatabasePath(this.Identity.ToString()), Strings.ProgressRestoringDatabaseStatus, 95);
                    }
                    base.WriteVerbose(TaskVerboseStringHelper.GetReadObjectVerboseString(id, base.DataSession, typeof(Server)));
                    try
                    {
                        if (!flag5)
                        {
                            this.SendNotificationRpcToReplayService();
                            flag5 = true;
                        }
                        base.WriteVerbose(Strings.VerboseMountDatabase(this.Identity.ToString()));
                        AmRpcClientHelper.MountDatabase(ADObjectWrapperFactory.CreateWrapper(this.DataObject), 0, 0, 0);
                    }
                    catch (AmServerException ex8)
                    {
                        string message = ex8.Message;
                        TaskLogger.Trace("MoveDatabasePath.InternalProcessRecord raises exception while re-mounting Mdb status: {0}", new object[]
                        {
                            message
                        });
                        this.WriteWarning(Strings.ErrorFailedToRestoreDatabaseStatus(this.Identity.ToString(), message));
                    }
                    catch (AmServerTransientException ex9)
                    {
                        string message2 = ex9.Message;
                        TaskLogger.Trace("MoveDatabasePath.InternalProcessRecord raises exception while re-mounting Mdb status: {0}", new object[]
                        {
                            message2
                        });
                        this.WriteWarning(Strings.ErrorFailedToRestoreDatabaseStatus(this.Identity.ToString(), message2));
                    }
                }
                TaskLogger.LogExit();
            }
        }
        private bool EnterBlockMode()
        {
            TimeSpan  timeout = TimeSpan.FromSeconds(5.0);
            bool      flag;
            Exception ex = AmStoreHelper.IsDatabaseMounted(this.Database.DatabaseGuid, this.LocalNodeName, timeout, out flag);

            if (ex != null)
            {
                LogCopyServerContext.Tracer.TraceError <Exception>((long)this.GetHashCode(), "Store may not be running. Mount check failed: {0}", ex);
                return(false);
            }
            if (!flag)
            {
                LogCopyServerContext.Tracer.TraceDebug <string>((long)this.GetHashCode(), "Db {0} not mounted. BlockMode is not possible", this.Database.DatabaseName);
                return(false);
            }
            EnterBlockModeMsg enterBlockModeMsg = new EnterBlockModeMsg(this.Channel, EnterBlockModeMsg.Flags.PrepareToEnter, this.Database.DatabaseGuid, this.m_currentLogGeneration);
            bool flag2 = false;
            bool result;

            lock (this.m_networkReadLock)
            {
                if (this.m_markedForTermination)
                {
                    result = false;
                }
                else
                {
                    int readTimeoutInMs  = this.Channel.TcpChannel.ReadTimeoutInMs;
                    int writeTimeoutInMs = this.Channel.TcpChannel.WriteTimeoutInMs;
                    try
                    {
                        this.Channel.TcpChannel.ReadTimeoutInMs  = RegistryParameters.LogShipACLLTimeoutInMsec;
                        this.Channel.TcpChannel.WriteTimeoutInMs = RegistryParameters.LogShipACLLTimeoutInMsec;
                        LogCopyServerContext.Tracer.TraceDebug <string>((long)this.GetHashCode(), "EnterBlockMode requesting PrepareToEnter for {0}", this.PassiveCopyName);
                        enterBlockModeMsg.Send();
                        EnterBlockModeMsg enterBlockModeMsg2;
                        string            text;
                        for (;;)
                        {
                            NetworkChannelMessage message     = this.Channel.GetMessage();
                            PingMessage           pingMessage = message as PingMessage;
                            if (pingMessage != null)
                            {
                                LogCopyServerContext.Tracer.TraceDebug((long)this.GetHashCode(), "PingMessage ignored");
                            }
                            else
                            {
                                ContinuousLogCopyRequest2 continuousLogCopyRequest = message as ContinuousLogCopyRequest2;
                                if (continuousLogCopyRequest != null)
                                {
                                    this.m_nextLogCopyRequest = continuousLogCopyRequest;
                                    LogCopyServerContext.Tracer.TraceDebug <long, long, ContinuousLogCopyRequest2.Flags>((long)this.GetHashCode(), "ContinuousLogCopyRequest2: First=0x{0:X} Max=0x{1:X} Flags=0x{2:X}", continuousLogCopyRequest.FirstGeneration, continuousLogCopyRequest.LastGeneration, continuousLogCopyRequest.FlagsUsed);
                                }
                                else
                                {
                                    enterBlockModeMsg2 = (message as EnterBlockModeMsg);
                                    text = null;
                                    if (enterBlockModeMsg2 == null)
                                    {
                                        text = string.Format("Passive({0}) sent unexpected msg: {1}", this.PassiveCopyName, message.GetType());
                                    }
                                    else if (enterBlockModeMsg2.AckCounter != enterBlockModeMsg.AckCounter)
                                    {
                                        text = string.Format("Passive({0}) is out of sync. BlockModeEntry Aborted", this.PassiveCopyName);
                                    }
                                    if (text != null)
                                    {
                                        break;
                                    }
                                    if (enterBlockModeMsg2.FlagsUsed != EnterBlockModeMsg.Flags.PassiveIsReady)
                                    {
                                        goto Block_13;
                                    }
                                    if (!this.RequestBlockModeInStore())
                                    {
                                        goto Block_15;
                                    }
                                }
                            }
                        }
                        LogCopyServerContext.Tracer.TraceError((long)this.GetHashCode(), text);
                        throw new NetworkUnexpectedMessageException(this.m_clientNodeName, text);
Block_13:
                        if (enterBlockModeMsg2.FlagsUsed == EnterBlockModeMsg.Flags.PassiveReject)
                        {
                            LogCopyServerContext.Tracer.TraceError <string>((long)this.GetHashCode(), "BlockMode rejected by passive {0}", this.PassiveCopyName);
                            flag2 = true;
                            return(false);
                        }
                        text = string.Format("Passive({0}) passed unexpected flags 0x{1X}", this.PassiveCopyName, enterBlockModeMsg2.FlagsUsed);
                        throw new NetworkUnexpectedMessageException(this.m_clientNodeName, text);
Block_15:
                        flag2  = true;
                        result = false;
                    }
                    finally
                    {
                        if (flag2)
                        {
                            this.Channel.TcpChannel.ReadTimeoutInMs  = readTimeoutInMs;
                            this.Channel.TcpChannel.WriteTimeoutInMs = writeTimeoutInMs;
                            this.StartNetworkRead();
                        }
                    }
                }
            }
            return(result);
        }