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

[broker] Fix topic policy listener deleted by mistake. #12904

Merged
merged 3 commits into from
Nov 22, 2021

Conversation

Jason918
Copy link
Contributor

@Jason918 Jason918 commented Nov 20, 2021

Motivation

Here is the current way of dealing topic policy listeners in PersistentTopic, for example topic name is "A", with 3 partitions.

  • Register: call TopicPoliciesService.registerListener("A", listener), for all 3 partitions of topic "A".
  • Clean: call TopicPoliciesService.clean("A-partition-x"), here is the problem it will delete all listeners of all partitions of topic "A", if any partition is closed.

This means, if we calls admin.topics().unload("A-partition-0"), "A-partition-1" and "A-partition-2" will not be able to receive topic policy update callbacks any more.

A detailed case is designed in the new unit test testListenerCleanupByPartition.

Modifications

With previous optimization of #12654 , now we can use org.apache.pulsar.broker.service.TopicPoliciesService#unregisterListener to do the clean up.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • testListenerCleanupByPartition

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

Check the box below and label this PR (if you have committer privilege).

Need to update docs?

  • no-need-doc

Bug fix.

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Nov 20, 2021
@codelipenghui codelipenghui added this to the 2.10.0 milestone Nov 21, 2021
@codelipenghui codelipenghui added release/2.8.3 release/2.9.1 type/bug The PR fixed a bug or issue reported a bug labels Nov 21, 2021
if (brokerService.pulsar().getConfig().isSystemTopicEnabled()
&& brokerService.pulsar().getConfig().isTopicLevelPoliciesEnabled()) {
brokerService.getPulsar().getTopicPoliciesService()
.unregisterListener(TopicName.getPartitionedTopicName(topic), this);
Copy link
Contributor

Choose a reason for hiding this comment

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

In current unregisterListener implementation, it will make listeners key keep growing even thought the listener unregister called.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have optimized the unregister implementation in #12654. See the last line of the unit test,
listMap.get(topicName) returns null instead of empty map.

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.

LGTM

good catch

Copy link
Contributor

@hangc0276 hangc0276 left a comment

Choose a reason for hiding this comment

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

Good job.

@codelipenghui codelipenghui merged commit a0c96a0 into apache:master Nov 22, 2021
dlg99 pushed a commit to dlg99/pulsar that referenced this pull request Nov 23, 2021
### Motivation

Here is the current way of dealing topic policy listeners in PersistentTopic, for example topic name is "A", with 3 partitions.
- Register: call TopicPoliciesService.registerListener("A", listener), for all 3 partitions of topic "A".
- Clean: call TopicPoliciesService.clean("A-partition-x"), here is the problem it will delete all listeners of all partitions of topic "A", if any partition is closed.

This means, if we calls `admin.topics().unload("A-partition-0")`,  "A-partition-1" and "A-partition-2" will not be able to receive topic policy update callbacks any more.

A detailed case is designed in the new unit test `testListenerCleanupByPartition`.

### Modifications

With previous optimization of apache#12654 , now we can use `org.apache.pulsar.broker.service.TopicPoliciesService#unregisterListener` to do the clean up.
codelipenghui pushed a commit that referenced this pull request Nov 25, 2021
### Motivation

`TopicPoliciesService#clean` was introduced to solve listener leaking problem in #10466.
And this is already addressed in #12904 using `unregisterListener`.
So this method is no use any more, and I don't see any situations that we may use this again.

### Modifications

Delete TopicPoliciesService#clean
codelipenghui pushed a commit that referenced this pull request Nov 26, 2021
### Motivation

Here is the current way of dealing topic policy listeners in PersistentTopic, for example topic name is "A", with 3 partitions.
- Register: call TopicPoliciesService.registerListener("A", listener), for all 3 partitions of topic "A".
- Clean: call TopicPoliciesService.clean("A-partition-x"), here is the problem it will delete all listeners of all partitions of topic "A", if any partition is closed.

This means, if we calls `admin.topics().unload("A-partition-0")`,  "A-partition-1" and "A-partition-2" will not be able to receive topic policy update callbacks any more.

A detailed case is designed in the new unit test `testListenerCleanupByPartition`.

### Modifications

With previous optimization of #12654 , now we can use `org.apache.pulsar.broker.service.TopicPoliciesService#unregisterListener` to do the clean up.

(cherry picked from commit a0c96a0)
@codelipenghui codelipenghui added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Nov 26, 2021
eolivelli pushed a commit to eolivelli/pulsar that referenced this pull request Nov 29, 2021
### Motivation

Here is the current way of dealing topic policy listeners in PersistentTopic, for example topic name is "A", with 3 partitions.
- Register: call TopicPoliciesService.registerListener("A", listener), for all 3 partitions of topic "A".
- Clean: call TopicPoliciesService.clean("A-partition-x"), here is the problem it will delete all listeners of all partitions of topic "A", if any partition is closed.

This means, if we calls `admin.topics().unload("A-partition-0")`,  "A-partition-1" and "A-partition-2" will not be able to receive topic policy update callbacks any more.

A detailed case is designed in the new unit test `testListenerCleanupByPartition`.

### Modifications

With previous optimization of apache#12654 , now we can use `org.apache.pulsar.broker.service.TopicPoliciesService#unregisterListener` to do the clean up.
eolivelli pushed a commit to eolivelli/pulsar that referenced this pull request Nov 29, 2021
…#12913)

### Motivation

`TopicPoliciesService#clean` was introduced to solve listener leaking problem in apache#10466.
And this is already addressed in apache#12904 using `unregisterListener`.
So this method is no use any more, and I don't see any situations that we may use this again.

### Modifications

Delete TopicPoliciesService#clean
fxbing pushed a commit to fxbing/pulsar that referenced this pull request Dec 19, 2021
### Motivation

Here is the current way of dealing topic policy listeners in PersistentTopic, for example topic name is "A", with 3 partitions.
- Register: call TopicPoliciesService.registerListener("A", listener), for all 3 partitions of topic "A".
- Clean: call TopicPoliciesService.clean("A-partition-x"), here is the problem it will delete all listeners of all partitions of topic "A", if any partition is closed.

This means, if we calls `admin.topics().unload("A-partition-0")`,  "A-partition-1" and "A-partition-2" will not be able to receive topic policy update callbacks any more.

A detailed case is designed in the new unit test `testListenerCleanupByPartition`.

### Modifications

With previous optimization of apache#12654 , now we can use `org.apache.pulsar.broker.service.TopicPoliciesService#unregisterListener` to do the clean up.
fxbing pushed a commit to fxbing/pulsar that referenced this pull request Dec 19, 2021
…#12913)

### Motivation

`TopicPoliciesService#clean` was introduced to solve listener leaking problem in apache#10466.
And this is already addressed in apache#12904 using `unregisterListener`.
So this method is no use any more, and I don't see any situations that we may use this again.

### Modifications

Delete TopicPoliciesService#clean
codelipenghui pushed a commit that referenced this pull request Dec 21, 2021
### Motivation

Here is the current way of dealing topic policy listeners in PersistentTopic, for example topic name is "A", with 3 partitions.
- Register: call TopicPoliciesService.registerListener("A", listener), for all 3 partitions of topic "A".
- Clean: call TopicPoliciesService.clean("A-partition-x"), here is the problem it will delete all listeners of all partitions of topic "A", if any partition is closed.

This means, if we calls `admin.topics().unload("A-partition-0")`,  "A-partition-1" and "A-partition-2" will not be able to receive topic policy update callbacks any more.

A detailed case is designed in the new unit test `testListenerCleanupByPartition`.

### Modifications

With previous optimization of #12654 , now we can use `org.apache.pulsar.broker.service.TopicPoliciesService#unregisterListener` to do the clean up.

(cherry picked from commit a0c96a0)
@codelipenghui codelipenghui added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Dec 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/broker cherry-picked/branch-2.8 Archived: 2.8 is end of life cherry-picked/branch-2.9 Archived: 2.9 is end of life doc-not-needed Your PR changes do not impact docs release/2.8.3 release/2.9.2 type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants