[Bug] Applying Pulsar Topic Policies fails when multiple policies are updated in a short period of time
Search before reporting
- [x] I searched in the issues and found nothing similar.
Read release policy
- [x] I understand that unsupported versions don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.
User environment
Pulsar Version = 4.0.3 OS = Linux Java Version = 21 Client Library Version = 4.0.3 (Pulsar-Admin) Client OS = Darwin (Mac) Client Java Version = 21
Issue Description
I have a function to create topics and apply policies on that topic.
admin.topicPolicies().setInactiveTopicPolicies(pulsarTopic, policies.inactive_topic_policies);
admin.topics().setReplicationClusters(pulsarTopic, List.of("cluster-a", "cluster-b"));
admin.topicPolicies().setSubscriptionTypesEnabledAsync(pulsarTopic, Set.of(SubscriptionType.Shared));
admin.topics().updateProperties(pulsarTopic, policies.properties);
However, after applying these, when I verify the results I get mismatching results:
- replication clusters is null (if I do with "applied"=true, I only get 1 cluster name)
- subscriptionTypesEnabled = [].
If I introduce a 1 second delay between each of the commands using Thread.sleep(1000), then I don't get these errors.
Also the following order of commands works as well :
admin.topics().setReplicationClusters(pulsarTopic, List.of("cluster-a", "cluster-b"));
admin.topicPolicies().setInactiveTopicPolicies(pulsarTopic, policies.inactive_topic_policies);
admin.topics().updateProperties(pulsarTopic, policies.properties);
admin.topicPolicies().setSubscriptionTypesEnabledAsync(pulsarTopic, Set.of(SubscriptionType.Shared));
I believe this might be a result of Async policy application on the broker.
Error messages
No error messages are observed. Each POST call succeeds with a 204.
Reproducing the issue
You can run the two method call orderings and verify the results.
Additional information
No response
Are you willing to submit a PR?
- [ ] I'm willing to submit a PR!
Possibly related to #21303.
Seems to be related, must have missed that issue during my search. Any plans on fixing this? I was also wondering, why topic policies are not updated in a similar fashion to namespaces. It seems all policies on topics are almost the same as namespaces, If we were to consolidate the update into one call, the changes could be better managed. What do you think?
Seems to be related, must have missed that issue during my search. Any plans on fixing this? I was also wondering, why topic policies are not updated in a similar fashion to namespaces. It seems all policies on topics are almost the same as namespaces, If we were to consolidate the update into one call, the changes could be better managed. What do you think?
I hope this gets more attention and gets fixed soon. Topic policies aren't stored in the Metadata store and perhaps that's one of the reasons why exactly the same solution as there was for namespaces cannot be directly applied to topic policies.
WIP fix in #24427