Beispiel #1
0
        private void ProcessInput(QueuedBlockMsg dataMsg)
        {
            dataMsg.GetMessageSize();
            if (this.m_newestMessage != null)
            {
                this.m_newestMessage.NextMsg = dataMsg;
                this.m_newestMessage         = dataMsg;
            }
            else
            {
                this.m_newestMessage = dataMsg;
                this.m_oldestMessage = dataMsg;
            }
            bool flag = BitMasker.IsOn((int)dataMsg.EmitContext.grbitOperationalFlags, 16);

            if (PassiveBlockMode.IsDebugTraceEnabled)
            {
                long num = StopwatchStamp.TicksToMicroSeconds(dataMsg.ReadDurationInTics);
                PassiveBlockMode.Tracer.TraceDebug((long)this.GetHashCode(), "MessageArrived({0}) Gen=0x{1:X} Sector=0x{2:X} JBits=0x{3:X} EmitSeq=0x{4:X} LogDataLen=0x{5:X} ReadUSec={6}", new object[]
                {
                    this.DatabaseName,
                    dataMsg.EmitContext.lgposLogData.lGeneration,
                    dataMsg.EmitContext.lgposLogData.isec,
                    (int)dataMsg.EmitContext.grbitOperationalFlags,
                    dataMsg.EmitContext.qwSequenceNum,
                    dataMsg.LogDataLength,
                    num
                });
            }
            this.Copier.PerfmonCounters.RecordGranularBytesReceived((long)dataMsg.LogDataLength, flag);
            ExchangeNetworkPerfmonCounters perfCounters = this.m_netChannel.PerfCounters;

            if (perfCounters != null)
            {
                perfCounters.RecordLogCopyThruputReceived((long)dataMsg.LogDataLength);
                if (dataMsg.CompressedLogDataLength > 0)
                {
                    perfCounters.RecordCompressedDataReceived(dataMsg.CompressedLogDataLength, dataMsg.LogDataLength, NetworkPath.ConnectionPurpose.LogCopy);
                }
            }
            this.TriggerConsumer();
            if (flag || DateTime.UtcNow >= this.m_nextPingDue)
            {
                uint lGeneration = (uint)dataMsg.EmitContext.lgposLogData.lGeneration;
                if (flag)
                {
                    this.Copier.TrackKnownEndOfLog((long)((ulong)lGeneration), dataMsg.EmitContext.logtimeEmit);
                }
                NetworkTransportException ex;
                bool flag2;
                this.TrySendStatusMessageToActive(flag ? PassiveStatusMsg.Flags.AckEndOfGeneration : PassiveStatusMsg.Flags.None, dataMsg.RequestAckCounter, out ex, out flag2);
                if (ex != null)
                {
                    throw ex;
                }
            }
        }
Beispiel #2
0
        private TimeSpan DetermineMountTimeout(AmBcsSkipFlags skipFlags)
        {
            int mountTimeoutInSec = RegistryParameters.MountTimeoutInSec;

            if (mountTimeoutInSec == 0 || BitMasker.IsOn((int)skipFlags, 8))
            {
                return(InvokeWithTimeout.InfiniteTimeSpan);
            }
            return(TimeSpan.FromSeconds((double)mountTimeoutInSec));
        }
Beispiel #3
0
        internal static bool IsDirectoryMountPoint(string path, out Exception exception)
        {
            exception = null;
            DirectoryInfo di = null;

            exception = MountPointUtil.HandleIOExceptions(delegate
            {
                di = new DirectoryInfo(path);
            });
            if (exception != null)
            {
                return(false);
            }
            if (!di.Exists)
            {
                return(false);
            }
            if (!BitMasker.IsOn((int)di.Attributes, 1024))
            {
                return(false);
            }
            if (di.Parent == null)
            {
                return(false);
            }
            using (DirectoryEnumerator dirEnum = new DirectoryEnumerator(di.Parent, false, false))
            {
                NativeMethods.WIN32_FIND_DATA findData = default(NativeMethods.WIN32_FIND_DATA);
                bool   foundNext = false;
                string dirName;
                exception = MountPointUtil.HandleIOExceptions(delegate
                {
                    foundNext = dirEnum.GetNextDirectoryExtendedInfo(di.Name, out dirName, out findData);
                });
                if (exception != null)
                {
                    return(false);
                }
                if (!foundNext)
                {
                    return(false);
                }
                if (findData.Reserved0 == 2684354563U)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #4
0
 private void ProcessReadCallback(PassiveReadRequest ioReq, int bytesAvailable, bool completionIsSynchronous, Exception readEx)
 {
     PassiveBlockMode.Tracer.TraceFunction <string>((long)this.GetHashCode(), "ProcessReadCallback({0}) entered", this.DatabaseName);
     lock (this.m_workerLock)
     {
         this.DisableTimer();
         Exception ex    = null;
         bool      flag2 = false;
         try
         {
             this.m_recursionDepth++;
             DiagCore.RetailAssert(this.m_recursionDepth == 1 || completionIsSynchronous, "recursive async completion", new object[0]);
             ioReq.CompletionWasProcessed = true;
             if (completionIsSynchronous)
             {
                 ioReq.CompletedSynchronously = completionIsSynchronous;
             }
             if (readEx != null)
             {
                 PassiveBlockMode.Tracer.TraceError <string, Exception>((long)this.GetHashCode(), "ProcessReadCallback({0}) read failed: ex={1}", this.DatabaseName, readEx);
                 ex = new NetworkCommunicationException(this.Configuration.SourceMachine, readEx.Message, readEx);
             }
             else if (bytesAvailable == 0)
             {
                 PassiveBlockMode.Tracer.TraceError <string>((long)this.GetHashCode(), "ProcessReadCallback({0}) active closed connection", this.DatabaseName);
                 ex = new NetworkEndOfDataException(this.Configuration.SourceMachine, ReplayStrings.NetworkReadEOF);
             }
             else if (ioReq.Channel != this.m_netChannel)
             {
                 ex    = new NetworkEndOfDataException(this.Configuration.SourceMachine, ReplayStrings.NetworkReadEOF);
                 flag2 = true;
                 ioReq.Channel.Close();
             }
             else if (!this.IsBlockModeActive)
             {
                 PassiveBlockMode.Tracer.TraceError <string>((long)this.GetHashCode(), "Discarding read since BM was already terminated", this.DatabaseName);
             }
             else
             {
                 QueuedBlockMsg queuedBlockMsg = this.ReadInputMessage(ioReq.Channel);
                 if (queuedBlockMsg != null)
                 {
                     this.ProcessInput(queuedBlockMsg);
                     if (BitMasker.IsOn((int)queuedBlockMsg.EmitContext.grbitOperationalFlags, 2))
                     {
                         this.HandleActiveDismount();
                         return;
                     }
                     if (BitMasker.IsOn((int)queuedBlockMsg.EmitContext.grbitOperationalFlags, 16))
                     {
                         this.Copier.TrackLastContactTime(queuedBlockMsg.MessageUtc);
                     }
                 }
                 if (this.m_recursionDepth == 1)
                 {
                     while (this.IsBlockModeActive)
                     {
                         PassiveReadRequest passiveReadRequest = this.StartRead();
                         if (!passiveReadRequest.CompletionWasProcessed)
                         {
                             if (!this.m_runningAcll)
                             {
                                 this.ScheduleTimer();
                                 break;
                             }
                             break;
                         }
                     }
                 }
                 else
                 {
                     PassiveBlockMode.Tracer.TraceDebug <int>((long)this.GetHashCode(), "Recursive read avoided. Depth={0}", this.m_recursionDepth);
                 }
             }
         }
         catch (NetworkTransportException ex2)
         {
             ex = ex2;
         }
         catch (NetworkRemoteException ex3)
         {
             ex = ex3;
         }
         catch (GranularReplicationOverflowException ex4)
         {
             ex = ex4;
         }
         finally
         {
             this.m_recursionDepth--;
             if (ex != null && !flag2)
             {
                 this.Terminate();
             }
             PassiveBlockMode.Tracer.TraceFunction <string>((long)this.GetHashCode(), "ProcessReadCallback({0}) exits", this.DatabaseName);
         }
     }
 }
Beispiel #5
0
        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);
        }
Beispiel #6
0
 public void Write(JET_EMITDATACTX emitCtx, byte[] databuf, int startOffset)
 {
     if (!this.m_jetConsumerInitialized)
     {
         throw new GranularReplicationTerminatedException("Already terminated");
     }
     try
     {
         StopwatchStamp stamp = StopwatchStamp.GetStamp();
         long           num   = (long)emitCtx.lgposLogData.lGeneration;
         int            grbitOperationalFlags = (int)emitCtx.grbitOperationalFlags;
         bool           flag = false;
         if (BitMasker.IsOn(grbitOperationalFlags, 16))
         {
             flag = true;
         }
         UnpublishedApi.JetConsumeLogData(this.m_jetConsumer, emitCtx, databuf, startOffset, (int)emitCtx.cbLogData, ShadowLogConsumeGrbit.FlushData);
         if (flag)
         {
             GranularWriter.Tracer.TraceDebug <string, long>((long)this.GetHashCode(), "WriteGranular({0}): 0x{1:X} is complete", this.DatabaseName, num);
             if (this.m_lowestClosedGeneration == 0L)
             {
                 this.m_lowestClosedGeneration = num;
             }
             string   text     = this.FormFullGranuleName(num);
             FileInfo fileInfo = new FileInfo(text);
             fileInfo.LastWriteTimeUtc = emitCtx.logtimeEmit;
             if (this.m_granularCompletionsDisabled)
             {
                 string destFileName = this.FormInspectorLogfileName(num);
                 File.Move(text, destFileName);
                 this.TrackInspectorGeneration(num, emitCtx.logtimeEmit);
                 this.m_lowestClosedGeneration = num + 1L;
             }
             this.m_currentGenerationState = GranularWriter.GranularLogState.Expected;
             this.m_currentGeneration      = num + 1L;
         }
         else if (BitMasker.IsOn(grbitOperationalFlags, 8))
         {
             this.m_currentGenerationState = GranularWriter.GranularLogState.Open;
             this.m_currentGeneration      = num;
             this.m_lastTimeFromServer     = new DateTime?(emitCtx.logtimeEmit);
         }
         long elapsedTicks = stamp.ElapsedTicks;
         this.m_perfmonCounters.RecordBlockModeConsumerWriteLatency(elapsedTicks);
         GranularWriter.Tracer.TracePerformance((long)this.GetHashCode(), "WriteGranular({0},0x{1:X}.0x{2:X}) EmitSeq=0x{3:X} took {4} uSec", new object[]
         {
             this.DatabaseName,
             emitCtx.lgposLogData.lGeneration,
             emitCtx.lgposLogData.isec,
             emitCtx.qwSequenceNum,
             StopwatchStamp.TicksToMicroSeconds(elapsedTicks)
         });
     }
     catch (EsentErrorException ex)
     {
         GranularWriter.Tracer.TraceError <EsentErrorException>((long)this.GetHashCode(), "JetConsumeLogData threw {0}", ex);
         this.m_jetConsumerHealthy = false;
         throw new GranularReplicationTerminatedException(ex.Message, ex);
     }
     catch (IOException ex2)
     {
         GranularWriter.Tracer.TraceError <IOException>((long)this.GetHashCode(), "IOException: {0}", ex2);
         this.m_jetConsumerHealthy = false;
         throw new GranularReplicationTerminatedException(ex2.Message, ex2);
     }
 }