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

PIP 92: part-2 Topic policy across multiple clusters #12517

Merged
merged 27 commits into from
Dec 15, 2021

Conversation

315157973
Copy link
Contributor

@315157973 315157973 commented Oct 28, 2021

Motivation

When setting the topic policy for a geo-replicated cluster, some policies want to affect the whole geo-replicated cluster but some only want to affect the local cluster. So the proposal is to support global topic policy and local topic policy.

Modifications

  1. Topic policies support cross-cluster replication. For local topic policies, set the replicateTo property of the message to avoid being replicated to the remote
  2. Retention supports setting global parameters
  3. Add global topic policies for SystemTopicBasedTopicPoliciesService

Verifying this change

Verify the addition, deletion, modification, and inspection of the interface is normal
Verify whether the policies can be replicate normally in the multi-Broker scenario

Documentation

  • doc-required

# Conflicts:
#	pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java
#	pulsar-common/src/main/java/org/apache/pulsar/common/events/EventsTopicNames.java
# Conflicts:
#	pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java
#	pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/TopicPoliciesTest.java
@315157973 315157973 self-assigned this Oct 28, 2021
@github-actions
Copy link

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

Comment on lines +63 to 66
if (EventsTopicNames.isTopicPoliciesSystemTopic(topic)) {
return super.checkReplication();
}
return CompletableFuture.completedFuture(null);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SystemTopic was previously used for Topic Policies and transaction. Only Topic Policies need to be replicate remotely, so I created a new class TopicPoliciesSystemTopic.

return producer.newMessage().key(getEventKey(event)).value(event).send();
return producer.newMessage()
.key(getEventKey(event))
.properties(event.getProperties() == null ? Collections.emptyMap() : event.getProperties())
Copy link
Contributor Author

@315157973 315157973 Oct 28, 2021

Choose a reason for hiding this comment

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

isGlobal is field of the TopicPolicies object. In order to avoid deserializing the entire message, I put the isGlobal tag in Properties so that only the header of the Entry need to be deserialized

@Anonymitaet Anonymitaet added doc-required Your PR changes impact docs and you will update later. and removed doc-label-missing labels Nov 1, 2021
@315157973 315157973 force-pushed the topic-policy-multiple-cluster branch from 661ab90 to 5786ed6 Compare November 2, 2021 07:20
@315157973 315157973 force-pushed the topic-policy-multiple-cluster branch from 93a0ff1 to 0e70b0d Compare November 3, 2021 07:44
@codelipenghui codelipenghui added this to the 2.10.0 milestone Nov 3, 2021
# Conflicts:
#	pulsar-common/src/main/java/org/apache/pulsar/common/policies/data/TopicPolicies.java
@315157973
Copy link
Contributor Author

/pulsarbot run-failure-checks

@315157973 315157973 force-pushed the topic-policy-multiple-cluster branch from e1d6829 to e4ec371 Compare November 8, 2021 04:02
@315157973 315157973 force-pushed the topic-policy-multiple-cluster branch from cebb328 to 8e1bee1 Compare November 8, 2021 08:48
# Conflicts:
#	pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/SystemTopic.java
#	pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ReplicatorTest.java
# Conflicts:
#	pulsar-broker/src/main/java/org/apache/pulsar/broker/service/SystemTopicBasedTopicPoliciesService.java
# Conflicts:
#	pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java
#	pulsar-broker/src/main/java/org/apache/pulsar/broker/service/TopicPoliciesService.java
@315157973
Copy link
Contributor Author

@codelipenghui PTAL, thanks, I have resolved the conflicts so many times....Is it ready to merge ?

* The incoming parameter is the original message, the output is whether the message should be filtered.
* @param filterFunction
*/
default void setFilterFunction(Function<MessageImpl, Boolean> filterFunction) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can leverage the selective replication

if (msg.hasReplicateTo() && !msg.getReplicateTo().contains(remoteCluster)) {
to avoid introduce the filter function for the replicator.

@codelipenghui
Copy link
Contributor

ping @eolivelli Could you please help take a final look? There are lots of changes since your last review.

@315157973
Copy link
Contributor Author

Hello, is this PR ready to merge or somewhere to change?

@codelipenghui codelipenghui merged commit c6beb35 into apache:master Dec 15, 2021
fxbing pushed a commit to fxbing/pulsar that referenced this pull request Dec 19, 2021
### Motivation
When setting the topic policy for a geo-replicated cluster, some policies want to affect the whole geo-replicated cluster but some only want to affect the local cluster. So the proposal is to support global topic policy and local topic policy.

### Modifications
1. Topic policies support cross-cluster replication. For local topic policies, set the `replicateTo` property of the message to avoid being replicated to the remote
2. Retention supports setting global parameters
3. Add global topic policies for `SystemTopicBasedTopicPoliciesService`

### Verifying this change
Verify the addition, deletion, modification, and inspection of the interface is normal
Verify whether the policies can be replicate normally in the multi-Broker scenario
@Anonymitaet Anonymitaet added doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. and removed doc-required Your PR changes impact docs and you will update later. labels Jan 5, 2022
codelipenghui pushed a commit that referenced this pull request Mar 10, 2022
### Motivation
PIP 92 has introduced topic policies across clusters. But after #12517, if the policy is not global, it set the replicate cluster to an empty set.
```
PulsarEvent.PulsarEventBuilder builder = PulsarEvent.builder();
 if (policies == null || !policies.isGlobalPolicies()) {
     // we don't need to replicate local policies to remote cluster, so set `replicateTo` to empty.
     builder.replicateTo(new HashSet<>());
}
```
It should set the `replicateTo` with the local cluster, not an empty set.

Otherwise,  it will cause the system event to be replicated. Details are here :
https://github.com/apache/pulsar/blob/d4c2e613d305f8f785b5ef357b7cbe2ccc271043/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentReplicator.java#L319-L328
codelipenghui pushed a commit that referenced this pull request Mar 12, 2022
### Motivation
PIP 92 has introduced topic policies across clusters. But after #12517, if the policy is not global, it set the replicate cluster to an empty set.
```
PulsarEvent.PulsarEventBuilder builder = PulsarEvent.builder();
 if (policies == null || !policies.isGlobalPolicies()) {
     // we don't need to replicate local policies to remote cluster, so set `replicateTo` to empty.
     builder.replicateTo(new HashSet<>());
}
```
It should set the `replicateTo` with the local cluster, not an empty set.

Otherwise,  it will cause the system event to be replicated. Details are here :
https://github.com/apache/pulsar/blob/d4c2e613d305f8f785b5ef357b7cbe2ccc271043/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentReplicator.java#L319-L328

(cherry picked from commit e470de5)
Nicklee007 pushed a commit to Nicklee007/pulsar that referenced this pull request Apr 20, 2022
### Motivation
PIP 92 has introduced topic policies across clusters. But after apache#12517, if the policy is not global, it set the replicate cluster to an empty set.
```
PulsarEvent.PulsarEventBuilder builder = PulsarEvent.builder();
 if (policies == null || !policies.isGlobalPolicies()) {
     // we don't need to replicate local policies to remote cluster, so set `replicateTo` to empty.
     builder.replicateTo(new HashSet<>());
}
```
It should set the `replicateTo` with the local cluster, not an empty set.

Otherwise,  it will cause the system event to be replicated. Details are here :
https://github.com/apache/pulsar/blob/d4c2e613d305f8f785b5ef357b7cbe2ccc271043/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentReplicator.java#L319-L328
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.

None yet

4 participants