public void Handle(ReplicationMessage.ReplicaSubscriptionRequest message) { _publisher.Publish(new SystemMessage.VNodeConnectionEstablished(message.ReplicaEndPoint, message.Connection.ConnectionId)); if (!CanAcceptSubscription(message)) { message.Envelope.ReplyWith( new ReplicationMessage.ReplicaSubscriptionRetry(_instanceId, message.SubscriptionId)); return; } var subscription = new ReplicaSubscription(_tcpSendPublisher, message.Connection, message.SubscriptionId, message.ReplicaEndPoint, message.IsPromotable); foreach (var subscr in _subscriptions.Values) { if (subscr != subscription && subscr.ConnectionId == subscription.ConnectionId) { subscr.ShouldDispose = true; } } if (SubscribeReplica(subscription, message.LastEpochs, message.CorrelationId, message.LogPosition, message.ChunkId)) { _newSubscriptions = true; if (!_subscriptions.TryAdd(subscription.SubscriptionId, subscription)) { ReplicaSubscription existingSubscr; _subscriptions.TryGetValue(subscription.SubscriptionId, out existingSubscr); Log.Error( "There is already a subscription with SubscriptionID {subscriptionId:B}: {existingSubscription}.", subscription.SubscriptionId, existingSubscr); Log.Error("Subscription we tried to add: {existingSubscription}.", existingSubscr); subscription.SendBadRequestAndClose(message.CorrelationId, string.Format( "There is already a subscription with SubscriptionID {0:B}: {1}.\nSubscription we tried to add: {2}", subscription.SubscriptionId, existingSubscr, subscription)); subscription.Dispose(); } else { var replicationCheckpoint = _db.Config.ReplicationCheckpoint.Read(); subscription.SendMessage(new ReplicationTrackingMessage.ReplicatedTo(replicationCheckpoint)); } } }
public void Handle(ReplicationMessage.ReplicaSubscriptionRequest message) { _publisher.Publish(new SystemMessage.VNodeConnectionEstablished(message.ReplicaEndPoint, message.Connection.ConnectionId)); if (_state != VNodeState.Master || message.MasterId != _instanceId) { message.Envelope.ReplyWith(new ReplicationMessage.ReplicaSubscriptionRetry(_instanceId, message.SubscriptionId)); return; } var subscription = new ReplicaSubscription(_tcpSendPublisher, message.Connection, message.SubscriptionId, message.ReplicaEndPoint, message.IsPromotable); foreach (var subscr in _subscriptions.Values) { if (subscr != subscription && subscr.ConnectionId == subscription.ConnectionId) { subscr.ShouldDispose = true; } } if (SubscribeReplica(subscription, message.LastEpochs, message.CorrelationId, message.LogPosition, message.ChunkId)) { _newSubscriptions = true; if (!_subscriptions.TryAdd(subscription.SubscriptionId, subscription)) { ReplicaSubscription existingSubscr; _subscriptions.TryGetValue(subscription.SubscriptionId, out existingSubscr); var msg = string.Format("There is already subscription with SubscriptionID {0:B}: {1}.\nSubscription we tried to add: {2}", subscription.SubscriptionId, existingSubscr, subscription); Log.Error(msg); subscription.SendBadRequestAndClose(message.CorrelationId, msg); subscription.Dispose(); } } }