public void Handle(ReplicationMessage.SubscribeToMaster message) { if (_state != VNodeState.PreReplica) { throw new Exception(string.Format("_state is {0}, but is expected to be {1}", _state, VNodeState.PreReplica)); } var logPosition = _db.Config.WriterCheckpoint.ReadNonFlushed(); var epochs = _epochManager.GetLastEpochs(ClusterConsts.SubscriptionLastEpochCount).ToArray(); Log.Info("Subscribing at LogPosition: {logPosition} (0x{logPosition:X}) to MASTER [{remoteEndPoint}, {masterId:B}] as replica with SubscriptionId: {subscriptionId:B}, " + "ConnectionId: {connectionId:B}, LocalEndPoint: [{localEndPoint}], Epochs:\n{epochs}...\n.", logPosition, logPosition, _connection.RemoteEndPoint, message.MasterId, message.SubscriptionId, _connection.ConnectionId, _connection.LocalEndPoint, string.Join("\n", epochs.Select(x => x.AsString()))); var chunk = _db.Manager.GetChunkFor(logPosition); if (chunk == null) { throw new Exception(string.Format("Chunk was null during subscribing at {0} (0x{0:X}).", logPosition)); } SendTcpMessage(_connection, new ReplicationMessage.SubscribeReplica( logPosition, chunk.ChunkHeader.ChunkId, epochs, _nodeInfo.InternalTcp, message.MasterId, message.SubscriptionId, isPromotable: true)); }