public void Handle(ReplicationMessage.RawChunkBulk message) { if (_subscriptionId != message.SubscriptionId) { return; } if (_activeChunk == null) { ReplicationFail( "Physical chunk bulk received, but we do not have active chunk.", "Physical chunk bulk received, but we do not have active chunk."); } if (_activeChunk.ChunkHeader.ChunkStartNumber != message.ChunkStartNumber || _activeChunk.ChunkHeader.ChunkEndNumber != message.ChunkEndNumber) { Log.Error( "Received RawChunkBulk for TFChunk {chunkStartNumber}-{chunkEndNumber}, but active chunk is {activeChunk}.", message.ChunkStartNumber, message.ChunkEndNumber, _activeChunk); return; } if (_activeChunk.RawWriterPosition != message.RawPosition) { Log.Error( "Received RawChunkBulk at raw pos {rawPosition} (0x{rawPosition:X}) while current writer raw pos is {rawWriterPosition} (0x{rawWriterPosition:X}).", message.RawPosition, message.RawPosition, _activeChunk.RawWriterPosition, _activeChunk.RawWriterPosition); return; } if (!_activeChunk.TryAppendRawData(message.RawBytes)) { ReplicationFail( "Could not append raw bytes to chunk {0}-{1}, raw pos: {2} (0x{3:X}), bytes length: {4} (0x{5:X}). Chunk file size: {6} (0x{7:X}).", "Could not append raw bytes to chunk {chunkStartNumber}-{chunkEndNumber}, raw pos: {rawPosition} (0x{rawPosition:X}), bytes length: {rawBytesLength} (0x{rawBytesLength:X}). Chunk file size: {chunkFileSize} (0x{chunkFileSize:X}).", message.ChunkStartNumber, message.ChunkEndNumber, message.RawPosition, message.RawPosition, message.RawBytes.Length, message.RawBytes.Length, _activeChunk.FileSize, _activeChunk.FileSize); } _subscriptionPos += message.RawBytes.Length; if (message.CompleteChunk) { Log.Trace("Completing raw chunk {chunkStartNumber}-{chunkEndNumber}...", message.ChunkStartNumber, message.ChunkEndNumber); Writer.CompleteReplicatedRawChunk(_activeChunk); _subscriptionPos = _activeChunk.ChunkHeader.ChunkEndPosition; _framer.Reset(); _activeChunk = null; } if (message.CompleteChunk || _subscriptionPos - _ackedSubscriptionPos >= MasterReplicationService.ReplicaAckWindow) { _ackedSubscriptionPos = _subscriptionPos; Bus.Publish(new ReplicationMessage.AckLogPosition(_subscriptionId, _ackedSubscriptionPos)); } }