Esempio n. 1
0
        private QueuedBlockMsg ReadInputMessage(NetworkChannel netChan)
        {
            this.m_timeoutPending = false;
            byte[]         networkReadWorkingBuf = this.m_networkReadWorkingBuf;
            StopwatchStamp stamp = StopwatchStamp.GetStamp();
            NetworkChannelMessageHeader msgHdr = NetworkChannelMessage.ReadHeaderFromNet(netChan, networkReadWorkingBuf, 0);

            NetworkChannelMessage.MessageType messageType = msgHdr.MessageType;
            QueuedBlockMsg queuedBlockMsg;

            if (messageType != NetworkChannelMessage.MessageType.BlockModeCompressedData)
            {
                if (messageType == NetworkChannelMessage.MessageType.Ping)
                {
                    PingMessage pingMessage = PingMessage.ReadFromNet(netChan, networkReadWorkingBuf, 0);
                    long        systemPerformanceCounter = Win32StopWatch.GetSystemPerformanceCounter();
                    long        arg = Win32StopWatch.ComputeElapsedTimeInUSec(systemPerformanceCounter, pingMessage.ReplyAckCounter) / 1000L;
                    this.Copier.TrackLastContactTime(msgHdr.MessageUtc);
                    PassiveBlockMode.Tracer.TraceDebug <string, long>((long)this.GetHashCode(), "ProcessReadCallback({0}) received a ping after {1}ms, so channel is healthy", this.DatabaseName, arg);
                    return(null);
                }
                if (messageType != NetworkChannelMessage.MessageType.GranularLogData)
                {
                    throw new NetworkUnexpectedMessageException(netChan.PartnerNodeName, string.Format("Unknown Type {0}", msgHdr.MessageType));
                }
                queuedBlockMsg = this.ReadUncompressedMsg(netChan);
                this.Copier.PerfmonCounters.CompressionEnabled = 0L;
            }
            else
            {
                queuedBlockMsg = this.ReadCompressedMsg(netChan, msgHdr);
                this.Copier.PerfmonCounters.CompressionEnabled = 1L;
            }
            queuedBlockMsg.ReadDurationInTics = stamp.ElapsedTicks;
            queuedBlockMsg.MessageUtc         = msgHdr.MessageUtc;
            this.Copier.PerfmonCounters.RecordLogCopierNetworkReadLatency(queuedBlockMsg.ReadDurationInTics);
            return(queuedBlockMsg);
        }
Esempio n. 2
0
        private QueuedBlockMsg ReadCompressedMsg(NetworkChannel netChan, NetworkChannelMessageHeader msgHdr)
        {
            byte[] networkReadWorkingBuf = this.m_networkReadWorkingBuf;
            BlockModeCompressedDataMsg blockModeCompressedDataMsg = BlockModeCompressedDataMsg.ReadFromNet(netChan, networkReadWorkingBuf, 0);

            byte[] array = null;
            int    num   = 0;
            int    num2  = 0;

            if (blockModeCompressedDataMsg.LogDataLength > 0)
            {
                this.GetAppendSpace(blockModeCompressedDataMsg.LogDataLength);
                array = this.m_currentBuffer.Buffer;
                num   = this.m_currentBuffer.AppendOffset;
                int num3 = blockModeCompressedDataMsg.LogDataLength;
                int num4 = num;
                foreach (int num5 in blockModeCompressedDataMsg.CompressedLengths)
                {
                    num2 += num5;
                    netChan.Read(networkReadWorkingBuf, 0, num5);
                    int num6 = Math.Min(num3, 65536);
                    if (!Xpress.Decompress(networkReadWorkingBuf, 0, num5, array, num4, num6))
                    {
                        throw new NetworkCorruptDataException(this.m_netChannel.PartnerNodeName);
                    }
                    num3 -= num6;
                    num4 += num6;
                }
                this.m_currentBuffer.AppendOffset = num + blockModeCompressedDataMsg.LogDataLength;
            }
            return(new QueuedBlockMsg(blockModeCompressedDataMsg.EmitContext, array, num, num2)
            {
                RequestAckCounter = blockModeCompressedDataMsg.RequestAckCounter,
                IOBuffer = this.m_currentBuffer
            });
        }