Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid enable DLQ on Key_Shared subscription. #9163

Merged
merged 10 commits into from
Feb 2, 2021

Conversation

MarvinCai
Copy link
Contributor

Fixes #9156

Motivation

In Pulsar, DLQ only supports non-ordered subscriptions, But now the Key_Shared subscription also allowed enable DLQ.
Should avoid enable DLQ on the Key_Shared subscription tpye.

Modifications

Only send message to DLQ if not Key_Shared subscription type.

Verifying this change

This change added tests and can be verified as follows:

  • Added unit test.

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): no
  • The public API: no
  • The schema: no
  • The default values of configurations: no
  • The wire protocol: no
  • The rest endpoints: no
  • The admin cli options: no
  • Anything that affects deployment: no

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? not documented

Copy link
Contributor

@codelipenghui codelipenghui left a comment

Choose a reason for hiding this comment

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

@MarvinCai We also need to add verification in the ConsumerBuilder. With the ConsumerBuilder, users should get a PulsarClient exception if they want to enable DLQ on a Key_Shared subscription.

Copy link
Contributor

@315157973 315157973 left a comment

Choose a reason for hiding this comment

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

The same logic exists in the void messageReceived method. Is it better for us to prohibit setting this kind of policy in the builder ?

if (deadLetterPolicy != null && possibleSendToDeadLetterTopicMessages != null && redeliveryCount >= deadLetterPolicy.getMaxRedeliverCount()) {
    possibleSendToDeadLetterTopicMessages.put((MessageIdImpl)message.getMessageId(), Collections.singletonList(message));
}

There is retry logic in deadLetterPolicy. If the number of retries is exceeded, how to deal with these messages? But the retryLetterProducer in consumerImpl doesn't seem to do any processing.

@MarvinCai
Copy link
Contributor Author

@MarvinCai We also need to add verification in the ConsumerBuilder. With the ConsumerBuilder, users should get a PulsarClient exception if they want to enable DLQ on a Key_Shared subscription.

Added check in ConsumerBuilder to throw InvalidConfigurationException if set DeadLetterTopic name for KeyShared subType.

The same logic exists in the void messageReceived method. Is it better for us to prohibit setting this kind of policy in the builder ?

if (deadLetterPolicy != null && possibleSendToDeadLetterTopicMessages != null && redeliveryCount >= deadLetterPolicy.getMaxRedeliverCount()) {
    possibleSendToDeadLetterTopicMessages.put((MessageIdImpl)message.getMessageId(), Collections.singletonList(message));
}

There is retry logic in deadLetterPolicy. If the number of retries is exceeded, how to deal with these messages? But the retryLetterProducer in consumerImpl doesn't seem to do any processing.

For first point, there's a check possibleSendToDeadLetterTopicMessages != null and I've make possibleSendToDeadLetterTopicMessages = null if it's KeyShared subType which is the behavior if DeadLetterPolicy is not provided. (It's safe as we are already doing null check every time we want to use possibleSendToDeadLetterTopicMessages)
For second point, actually we need both check. The check in ConsumerBuilder will prevent user from setting DeadLetterTopic.
However, even if we don't set DeadLetterTopic(e in DeadLetterPolicy, in ConsumerImpl wether to put message in DLQ is currently decided by if reconsumetimes > this.deadLetterPolicy.getMaxRedeliverCount() so additional check will still be needed here as we want retry but not DLQ for Key_Shared subType.
Either by checking if subType == Key_Shared or if StringUtils.isBlank(deadLetterPolicy.getDeadLetterTopic()). I just pick the former cause it make our purpose more clear.

@sijie
Copy link
Member

sijie commented Jan 18, 2021

@315157973 @codelipenghui Can you review the PR again?

@MarvinCai
Copy link
Contributor Author

Now ConsumerImpl constructor will throw exception when client try to directly construct a Consumer with Key_Shared subscription type and DeadLetterTopic. Same to all subclass like ZeroQueueCosumer, RawReader...., this shouldn't affect existing logic using ConsumerBuilder to create consumer as builder will check and make sure there's no DLQ set for Key_Shared sub type.

@MarvinCai
Copy link
Contributor Author

/pulsarbot run-failure-checks

3 similar comments
@MarvinCai
Copy link
Contributor Author

/pulsarbot run-failure-checks

@MarvinCai
Copy link
Contributor Author

/pulsarbot run-failure-checks

@MarvinCai
Copy link
Contributor Author

/pulsarbot run-failure-checks

@MarvinCai
Copy link
Contributor Author

/pulsarbot run-failure-checks

@MarvinCai
Copy link
Contributor Author

/pulsarbot run-failure-checks

2 similar comments
@MarvinCai
Copy link
Contributor Author

/pulsarbot run-failure-checks

@MarvinCai
Copy link
Contributor Author

/pulsarbot run-failure-checks

@MarvinCai
Copy link
Contributor Author

/pulsarbot run-failure-checks

@sijie sijie added the doc-required Your PR changes impact docs and you will update later. label Feb 2, 2021
@sijie sijie merged commit 9af8577 into apache:master Feb 2, 2021
MarvinCai added a commit to MarvinCai/pulsar that referenced this pull request Feb 23, 2021
sijie pushed a commit that referenced this pull request Feb 24, 2021
@Anonymitaet Anonymitaet removed the doc-required Your PR changes impact docs and you will update later. label Apr 9, 2021
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.

Avoid enable DLQ on Key_Shared subscription
5 participants