-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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
Changes from all commits
447b38f
8a1eec1
697d212
9af883e
53a2e2c
aaa10b2
29a95e6
a3d7cc8
7f621cf
2a03f8c
5050370
10ebae2
a9cf4e4
bf85481
627e099
b6628c4
5a5da9b
ada302c
5c99348
f9edd32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * 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 java.util.Map; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** IdentityReplicationPolicy does not rename remote topics. This is useful for migrating | ||
| * from legacy MM1, or for any use-case involving one-way replication. | ||
| * | ||
| * 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 IdentityReplicationPolicy extends DefaultReplicationPolicy { | ||
| private static final Logger log = LoggerFactory.getLogger(IdentityReplicationPolicy.class); | ||
|
|
||
| public static final String SOURCE_CLUSTER_ALIAS_CONFIG = "source.cluster.alias"; | ||
|
|
||
| private String sourceClusterAlias = null; | ||
|
|
||
| @Override | ||
| public void configure(Map<String, ?> props) { | ||
| super.configure(props); | ||
| if (props.containsKey(SOURCE_CLUSTER_ALIAS_CONFIG)) { | ||
| sourceClusterAlias = (String) props.get(SOURCE_CLUSTER_ALIAS_CONFIG); | ||
| log.info("Using source cluster alias `{}`.", sourceClusterAlias); | ||
| } | ||
| } | ||
|
|
||
| /** Unlike DefaultReplicationPolicy, IdentityReplicationPolicy does not include the source | ||
| * cluster alias in the remote topic name. Instead, topic names are unchanged. | ||
| * | ||
| * In the special case of heartbeats, we defer to DefaultReplicationPolicy. | ||
| */ | ||
| @Override | ||
| public String formatRemoteTopic(String sourceClusterAlias, String topic) { | ||
| if (looksLikeHeartbeat(topic)) { | ||
| return super.formatRemoteTopic(sourceClusterAlias, topic); | ||
| } else { | ||
| return topic; | ||
| } | ||
| } | ||
|
|
||
| /** Unlike DefaultReplicationPolicy, IdendityReplicationPolicy cannot know the source of | ||
| * a remote topic based on its name alone. If `source.cluster.alias` is provided, | ||
| * `topicSource` will return that. | ||
| * | ||
| * In the special case of heartbeats, we defer to DefaultReplicationPolicy. | ||
| */ | ||
| @Override | ||
| public String topicSource(String topic) { | ||
| if (looksLikeHeartbeat(topic)) { | ||
| return super.topicSource(topic); | ||
| } else { | ||
| return sourceClusterAlias; | ||
| } | ||
| } | ||
|
|
||
| /** Since any topic may be a "remote topic", this just returns `topic`. | ||
| * | ||
| * In the special case of heartbeats, we defer to DefaultReplicationPolicy. | ||
| */ | ||
| @Override | ||
| public String upstreamTopic(String topic) { | ||
| if (looksLikeHeartbeat(topic)) { | ||
| return super.upstreamTopic(topic); | ||
| } else { | ||
| return topic; | ||
| } | ||
| } | ||
|
|
||
| private boolean looksLikeHeartbeat(String topic) { | ||
| return topic != null && topic.endsWith(MirrorClientConfig.HEARTBEATS_TOPIC); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,6 +175,7 @@ public Map<String, String> workerConfig(SourceAndTarget sourceAndTarget) { | |
| props.putAll(stringsWithPrefix("header.converter")); | ||
| props.putAll(stringsWithPrefix("task")); | ||
| props.putAll(stringsWithPrefix("worker")); | ||
| props.putAll(stringsWithPrefix("replication.policy")); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In MirrorClientConfig ,it seems that it's not necessary to add replication.policy into the props. |
||
|
|
||
| // transform any expression like ${provider:path:key}, since the worker doesn't do so | ||
| props = transform(props); | ||
|
|
@@ -203,6 +204,7 @@ public Map<String, String> connectorBaseConfig(SourceAndTarget sourceAndTarget, | |
| props.keySet().retainAll(MirrorConnectorConfig.CONNECTOR_CONFIG_DEF.names()); | ||
|
|
||
| props.putAll(stringsWithPrefix(CONFIG_PROVIDERS_CONFIG)); | ||
| props.putAll(stringsWithPrefix("replication.policy")); | ||
|
|
||
| Map<String, String> sourceClusterProps = clusterProps(sourceAndTarget.source()); | ||
| // attrs non prefixed with producer|consumer|admin | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.