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

[pulsar-admin] Add remove-subscription-types-enabled command for topic #12983

Merged
merged 1 commit into from
Dec 2, 2021
Merged

[pulsar-admin] Add remove-subscription-types-enabled command for topic #12983

merged 1 commit into from
Dec 2, 2021

Conversation

yuruguo
Copy link
Contributor

@yuruguo yuruguo commented Nov 25, 2021

Motivation

CLI bin/pulsar-admin topics supports set-subscription-types-enabled and get-subscription-types-enabled command, but lacks corresponding remove-subscription-types-enabled commands, the purpose of this PR is to add this command for topic.

Documentation

Automatically generate doc through code

  • doc

@github-actions
Copy link

@yuruguo:Thanks for your contribution. For this PR, do we need to update docs?
(The PR template contains info about doc, which helps others know more about the changes. Can you provide doc-related info in this and future PR descriptions? Thanks)

@github-actions
Copy link

@yuruguo:Thanks for providing doc info!

@github-actions github-actions bot added the doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. label Nov 25, 2021
@codelipenghui codelipenghui added this to the 2.10.0 milestone Nov 26, 2021
if (!op.isPresent()) {
return CompletableFuture.completedFuture(null);
}
op.get().setSubscriptionTypesEnabled(Lists.newArrayList());
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not modify a object that could be the result of a read from a cache

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I don't fully understand what you mean. I'm still a little confused about it. Can you give me more information?
I understand that this is the process of making TopicPolicies.subscriptionTypesEnabled as empty list(default initial value), right?
Maybe according to your meaning, how should I modify it?

Copy link
Contributor

Choose a reason for hiding this comment

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

you are using the returned object from getTopicPoliciesAsyncWithRetry using op.get()
if pulsar().getTopicPoliciesService().updateTopicPoliciesAsync fails then the local copy of the variable in memory is update but the value is not write to persistent metadata storage.

We should copy/clone the object and not mutate it.
It would be better to have "immutable" objects, but that would be another story

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Many topic policy set&remove operations are implemented in this way, so they all need to be adjusted, as below:

protected CompletableFuture<Void> internalSetPersistence(PersistencePolicies persistencePolicies) {
validatePersistencePolicies(persistencePolicies);
return getTopicPoliciesAsyncWithRetry(topicName)
.thenCompose(op -> {
TopicPolicies topicPolicies = op.orElseGet(TopicPolicies::new);
topicPolicies.setPersistence(persistencePolicies);
return pulsar().getTopicPoliciesService().updateTopicPoliciesAsync(topicName, topicPolicies);
});
}

protected CompletableFuture<Void> internalRemovePersistence() {
return getTopicPoliciesAsyncWithRetry(topicName)
.thenCompose(op -> {
if (!op.isPresent()) {
return CompletableFuture.completedFuture(null);
}
op.get().setPersistence(null);
return pulsar().getTopicPoliciesService().updateTopicPoliciesAsync(topicName, op.get());
});
}

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

I am approving this patch.

thank you @yuruguo for checking about my comments.

I believe we have to follow up and fix potential local cache consistency problems.

would you like to follow up ?

cc @merlimat

@yuruguo
Copy link
Contributor Author

yuruguo commented Nov 30, 2021

I am approving this patch.

thank you @yuruguo for checking about my comments.

I believe we have to follow up and fix potential local cache consistency problems.

would you like to follow up ?

cc @merlimat

Thanks for your guidance, I will create an issue to track this problem and try to submit a PR to solve it :)

@codelipenghui codelipenghui merged commit 5d06dae into apache:master Dec 2, 2021
fxbing pushed a commit to fxbing/pulsar that referenced this pull request Dec 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Your PR contains doc changes, no matter whether the changes are in markdown or code files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants