-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-9726 IdentityReplicationPolicy #10652
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
447b38f
WIP LegacyReplicationPolicy and tests
ryannedolan 8a1eec1
Merge branch 'trunk' of github.com:ryannedolan/kafka into trunk
ryannedolan 697d212
WIP fix integration tests -- two FIXMEs
9af883e
steal mdedetrich's tests and IdentityReplicationPolicy, but without A…
53a2e2c
dropped LegacyReplicationPolicy
aaa10b2
WIP LegacyReplicationPolicy and tests
ryannedolan 29a95e6
WIP fix integration tests -- two FIXMEs
a3d7cc8
steal mdedetrich's tests and IdentityReplicationPolicy, but without A…
7f621cf
dropped LegacyReplicationPolicy
2a03f8c
Merge branch 'KAFKA-9726' of github.com:ryannedolan/kafka into KAFKA-…
ryannedolan 5050370
Merge branch 'apache:trunk' into KAFKA-9726
ryannedolan 10ebae2
Merge branch 'apache:trunk' into KAFKA-9726
ryannedolan a9cf4e4
drop unnecessary change to mirror-client api
bf85481
improve tests for IdentityReplicationPolicy h/t @mimaison
627e099
drop unnecessary constructor from IdentityReplicationPolicy
b6628c4
Merge branch 'apache:trunk' into KAFKA-9726
ryannedolan 5a5da9b
Merge branch 'KAFKA-9726' of github.com:ryannedolan/kafka into KAFKA-…
ada302c
mention IdentityReplicationPolicy in upgrade notes
5c99348
Merge branch 'apache:trunk' into KAFKA-9726
ryannedolan f9edd32
fix testOffsetSyncsTopicsOnTarget integration test to work with ident…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
.../mirror-client/src/main/java/org/apache/kafka/connect/mirror/LegacyReplicationPolicy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.connect.mirror; | ||
|
|
||
| import org.apache.kafka.common.Configurable; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| /** LegacyReplicationPolicy attempts to mimic MirrorMaker v1, and thus by default does not | ||
| * rename topics. In order to support active/active replication with careful configuration, | ||
| * topics can be renamed with an optional suffix, e.g. "topic1.replica". | ||
| * | ||
| * LegacyReplicationPolicy cannot, in general, detect whether a topic is remote or not, nor | ||
| * which cluster a topic may have been replicated from. If a `remote.topic.suffix` is | ||
| * provided, we use that to distinguish remote topics. Otherwise we consider all topics as | ||
| * remote topics. If a `source.cluster.alias` is provided, we use that as the source of | ||
| * any remote topics. Otherwise we return null for `topicSource()`. | ||
| * | ||
| * Paradoxically, then, the default behavior of LegacyReplicationPolicy is to consider all | ||
| * topics to be remote but with no known source. | ||
| * | ||
| * N.B. MirrorMaker is not able to prevent cycles when using this class, so take care that | ||
| * your replication topology is acyclic. If migrating from MirrorMaker v1, this will likely | ||
| * already be the case. | ||
| */ | ||
| public class LegacyReplicationPolicy implements ReplicationPolicy, Configurable { | ||
|
|
||
| public static final String REMOTE_TOPIC_SUFFIX_CONFIG = "remote.topic.suffix"; | ||
| public static final String SOURCE_CLUSTER_ALIAS_CONFIG = "source.cluster.alias"; | ||
|
|
||
| private String remoteTopicSuffix = ""; | ||
| private String sourceClusterAlias = null; | ||
|
|
||
| public LegacyReplicationPolicy() { | ||
| } | ||
|
|
||
| // Visible for testing | ||
| LegacyReplicationPolicy(String remoteTopicSuffix, String sourceClusterAlias) { | ||
| this.remoteTopicSuffix = remoteTopicSuffix; | ||
| this.sourceClusterAlias = sourceClusterAlias; | ||
| } | ||
|
|
||
| @Override | ||
| public void configure(Map<String, ?> props) { | ||
| if (props.containsKey(REMOTE_TOPIC_SUFFIX_CONFIG)) { | ||
| remoteTopicSuffix = (String) props.get(REMOTE_TOPIC_SUFFIX_CONFIG); | ||
| } | ||
| if (props.containsKey(SOURCE_CLUSTER_ALIAS_CONFIG)) { | ||
| sourceClusterAlias = (String) props.get(SOURCE_CLUSTER_ALIAS_CONFIG); | ||
| } | ||
| } | ||
|
|
||
| /** Unlike DefaultReplicationPolicy, LegacyReplicationPolicy does not include the source | ||
| * cluster alias in the remote topic name. By default, topic names are unchanged. If | ||
| * a `remote.topic.suffix` is provided, topic are renamed accordingly. | ||
| */ | ||
| @Override | ||
| public String formatRemoteTopic(String sourceClusterAlias, String topic) { | ||
| return topic + remoteTopicSuffix; | ||
| } | ||
|
|
||
| /** Unlike DefaultReplicationPolicy, LegacyReplicationPolicy cannot know the source of | ||
| * a remote topic based on its name alone. If `source.cluster.alias` is provided, | ||
| * `topicSource` will return that for anything that looks like a remote topic. By default, | ||
| * all topics look like remote topics. | ||
| */ | ||
| @Override | ||
| public String topicSource(String topic) { | ||
| if (topic.endsWith(remoteTopicSuffix)) { | ||
| return sourceClusterAlias; | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /** Unlike DefaultReplicationPolicy, LegacyReplicationPolicy cannot distinguish remote | ||
| * topics from regular topics by default. If `remote.topic.suffix` is provided, this | ||
| * method will strip that and return the original topic. By default, `topic` is returned. | ||
| */ | ||
| @Override | ||
| public String upstreamTopic(String topic) { | ||
| if (topic.endsWith(remoteTopicSuffix)) { | ||
| return topic.substring(0, topic.length() - remoteTopicSuffix.length()); | ||
| } else { | ||
| return topic; | ||
| } | ||
| } | ||
|
|
||
| /** If remote.topic.suffix is provided, treat suffixed topics as internal topics. | ||
| * This prevents replicated topics from being further replicated when using | ||
| * LegacyReplicationPolicy. | ||
| */ | ||
| @Override | ||
| public boolean isInternalTopic(String topic) { | ||
| return ReplicationPolicy.super.isInternalTopic(topic) | ||
| || (!remoteTopicSuffix.isEmpty() && topic.endsWith(remoteTopicSuffix)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.