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

Fix messages in TopicPolicies will never be cleaned up #11928

Merged
merged 4 commits into from
Sep 20, 2021

Conversation

315157973
Copy link
Contributor

Motivation

The current Topic Policies use compaction topic.
When a compaction topic deletes a message, the body of the message must be null.
Now, even if policies are being deleted, the body of the message is not null.
This will cause some messages in compaction topic never be cleaned up.

Modifications

1)When deleting policies, set the message body to null
2)Add a delete API instead of modifying write API

@315157973
Copy link
Contributor Author

@gaoran10 PTAL, it seems that the transaction also has this problem

Copy link
Contributor

@gaoran10 gaoran10 left a comment

Choose a reason for hiding this comment

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

LGTM, left a trivial comment.

Thanks for the suggestion, I'll open a PR to clear the transaction buffer snapshot when deleting the topic.

@@ -330,9 +343,6 @@ private void refreshTopicPoliciesCache(Message<PulsarEvent> msg) {
case UPDATE:
policiesCache.put(topicName, event.getPolicies());
break;
case DELETE:
Copy link
Contributor

Choose a reason for hiding this comment

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

what about old data present in existing clusters ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch, maybe we could call the delete method to publish a message with a null value in branch DELETE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, for the compatibility, this code cannot be deleted now, I will add a comment here.
But Topic's existing old data seems to need to provide additional tools to delete it.

Copy link
Contributor

Choose a reason for hiding this comment

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

When recovering the topic policies, the reader will read messages from the earliest position, it could read the DELETE type Pulsar event, does it handle the DELETE event messages at this time?

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 added a compatibility adaptation

Copy link
Contributor

@gaoran10 gaoran10 left a comment

Choose a reason for hiding this comment

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

LGTM

SystemTopicClient<PulsarEvent> systemTopicClient = namespaceEventsSystemTopicFactory
.createTopicPoliciesSystemTopicClient(topicName.getNamespaceObject());
systemTopicClient.newWriterAsync().thenAccept(writer
-> writer.deleteAsync(getPulsarEvent(topicName, ActionType.DELETE, null)));
Copy link
Contributor

Choose a reason for hiding this comment

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

The writer should be closed and for replay the historical policies, we should use one writer instead create writer for each policy data?

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 closed the Writer.
Now all Writers in SystemTopicBasedTopicPoliciesService seem to be created every time.
I think this is reasonable, after all, Topic Policies are not high-frequency operations.

@Anonymitaet
Copy link
Member

@315157973 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)

@codelipenghui codelipenghui added the doc-not-needed Your PR changes do not impact docs label Sep 7, 2021
@gaoran10
Copy link
Contributor

gaoran10 commented Sep 7, 2021

Hi, @Anonymitaet, I think this doesn't need a doc, because this is a bug fix.

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.

+1

@eolivelli eolivelli merged commit 93e2db0 into apache:master Sep 20, 2021
codelipenghui pushed a commit that referenced this pull request Sep 24, 2021
@codelipenghui codelipenghui added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked/branch-2.8 Archived: 2.8 is end of life doc-not-needed Your PR changes do not impact docs release/2.8.2 release/2.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants