Skip to content

Conversation

@massakam
Copy link
Contributor

This is a further modification of the previously closed PR #6592.

Fixes #6437

Motivation

In a replicated subscription with no consumers connected, the number of marker messages in the backlog will continue to increase. If at least one active consumer is connected, the marker messages will be acknowledged and deleted by the dispatcher.

if (msgMetadata == null || Markers.isServerOnlyMarker(msgMetadata)) {
PositionImpl pos = (PositionImpl) entry.getPosition();
// Message metadata was corrupted or the messages was a server-only marker
if (Markers.isReplicatedSubscriptionSnapshotMarker(msgMetadata)) {
processReplicatedSubscriptionSnapshot(pos, metadataAndPayload);
}
entries.set(i, null);
entry.release();
subscription.acknowledgeMessage(Collections.singletonList(pos), AckType.Individual,
Collections.emptyMap());
continue;

On the other hand, if no consumers are connected, or if they are connected but cannot receive any messages, the dispatcher does not exist or has stopped reading entries. As a result, the marker messages accumulate in the backlog without being acknoledged by anyone.

Modifications

There are four types of marker messages:

  • ReplicatedSubscriptionsSnapshotRequest
  • ReplicatedSubscriptionsSnapshotResponse
  • ReplicatedSubscriptionsSnapshot
  • ReplicatedSubscriptionsUpdate

Of these, three messages, except ReplicatedSubscriptionsSnapshot, are not used in the local cluster. They are published to local topics for sending to remote clusters. So, modified the ReplicatedSubscriptionsController class to acknowledge these marker messages on all subscriptions immediately after publishing the messages to a local topic.

On the other hand, ReplicatedSubscriptionsSnapshot is only used by dispatchers in the local cluster and does not need to be sent to remote clusters. So, ReplicatedSubscriptionsController only acknowledges those messages on behalf of dispatcher if dispatcher has not been initialized or if there are no available consumers.

In addition, marker messages sent from remote clusters are now acknowledged by the replicator on all subscriptions.

With these changes, marker messages no longer continue to accumulate in the replicated subscription backlog.

@massakam massakam added this to the 2.7.0 milestone Jun 18, 2020
@massakam massakam self-assigned this Jun 18, 2020
Comment on lines +117 to +120
if (dispatcher == null || !dispatcher.isAtleastOneConsumerAvailable()) {
sub.acknowledgeMessage(Collections.singletonList(position), AckType.Individual,
Collections.emptyMap());
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit worried here. If the producer continues to produce messages but does not have consumers to consume messages, the individual ack the snapshot message will introduce more discontinuous acknowledge ranges. If that is true, the individualAcks in the cursor will get bigger and bigger.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if all consumers of the subscription are disconnected. The subscription also removes from this topic. So maybe can't ack the snapshot message at this moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codelipenghui

I'm a bit worried here. If the producer continues to produce messages but does not have consumers to consume messages, the individual ack the snapshot message will introduce more discontinuous acknowledge ranges. If that is true, the individualAcks in the cursor will get bigger and bigger.

I see. Uhm...
Is there any other solution to this issue?

And if all consumers of the subscription are disconnected. The subscription also removes from this topic. So maybe can't ack the snapshot message at this moment.

If there are no subscriptions on the topic, we don't need to ack since the messages will not accumulate in the backlog, do we?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any other solution to this issue?

I also don’t have a very good way, it looks okay, just an extreme case

If there are no subscriptions on the topic, we don't need to ack since the messages will not accumulate in the backlog, do we?

make sense

@codelipenghui
Copy link
Contributor

@massakam Could you please rebase to the apache/master branch? Thanks.
@merlimat @sijie @jiazhai Could you please also help review this PR?

@codelipenghui
Copy link
Contributor

move to milestone 2.8.0 first

@codelipenghui codelipenghui modified the milestones: 2.7.0, 2.8.0 Nov 17, 2020
codelipenghui pushed a commit that referenced this pull request Apr 22, 2021
…affic (#10292)

### Motivation

Fixes #6437

This is a different approach to fix the issue, alternative to #7299. 

Instead of automatically acking the marker messages when the consumers are not connected, we should instead stop taking the snapshot when there's no traffic. There's no point in continuing storing these snapshots all the time if there's no traffic.

### Modifications

 1. When we detect that there has been no new messages since the last snapshot was take, skip the new snapshot.
 2. When there are no local producers, skip 1 snapshot creation. This is done in order to create a quiet period and give more time to not have any remote markers since our last snapshot was created.
@massakam massakam closed this Apr 22, 2021
@massakam massakam deleted the repl-sub-backlog branch April 22, 2021 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backlog messages increase if no consumer is connected to replicated subscription

2 participants