public bool EnterBlockMode(EnterBlockModeMsg msg, NetworkChannel channel, int maxConsumerQDepth) { lock (this.m_workerLock) { Exception ex = null; try { if (msg.FirstGenerationToExpect != this.Copier.NextGenExpected) { string text = string.Format("EnterBlockMode({0}) received gen 0x{1:X} but was expecting 0x{2:X}", this.DatabaseName, msg.FirstGenerationToExpect, this.Copier.NextGenExpected); PassiveBlockMode.Tracer.TraceError((long)this.GetHashCode(), text); throw new NetworkUnexpectedMessageException(this.Configuration.SourceMachine, text); } PassiveBlockMode.Tracer.TraceDebug <string, long>((long)this.GetHashCode(), "EnterBlockMode({0}) starts at gen 0x{1:X}", this.DatabaseName, msg.FirstGenerationToExpect); this.m_oldestMessage = null; this.m_newestMessage = null; this.m_maxConsumerDepthInBytes = maxConsumerQDepth; this.m_maxBuffersInUse = PassiveBlockMode.GetMaxBuffersPerDatabase(this.m_maxConsumerDepthInBytes); this.m_consumer.Initialize(); channel.KeepAlive = true; channel.NetworkChannelManagesAsyncReads = false; this.m_netChannel = channel; this.IsBlockModeActive = true; this.Copier.PerfmonCounters.GranularReplication = 1L; this.Copier.PerfmonCounters.EncryptionEnabled = (channel.IsEncryptionEnabled ? 1L : 0L); this.StartRead(); msg.Send(); this.ScheduleTimer(); return(true); } catch (NetworkTransportException ex2) { ex = ex2; } catch (GranularReplicationTerminatedException ex3) { ex = ex3; } catch (GranularReplicationInitFailedException ex4) { ex = ex4; } finally { if (ex != null) { PassiveBlockMode.Tracer.TraceError <Exception>((long)this.GetHashCode(), "EnterBlockMode failed: {0}", ex); this.Terminate(); } else { PassiveBlockMode.Tracer.TraceDebug <string>((long)this.GetHashCode(), "EnterBlockMode({0}) succeeded", this.DatabaseName); } } } return(false); }
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); }