-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-15119:Support incremental syncTopicAcls in MirrorSourceConnector #13913
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
Closed
Closed
Changes from all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,10 +20,12 @@ | |
| import java.util.Locale; | ||
| import java.util.Map.Entry; | ||
|
|
||
| import java.util.concurrent.Future; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
| import org.apache.kafka.clients.admin.Admin; | ||
| import org.apache.kafka.clients.consumer.ConsumerConfig; | ||
| import org.apache.kafka.common.IsolationLevel; | ||
| import org.apache.kafka.common.KafkaFuture; | ||
| import org.apache.kafka.common.config.ConfigValue; | ||
| import org.apache.kafka.common.errors.SecurityDisabledException; | ||
| import org.apache.kafka.connect.connector.Task; | ||
|
|
@@ -74,6 +76,7 @@ | |
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import static org.apache.kafka.common.utils.Utils.sleep; | ||
| import static org.apache.kafka.connect.mirror.MirrorSourceConfig.SYNC_TOPIC_ACLS_ENABLED; | ||
|
|
||
| /** Replicate data, configuration, and ACLs between clusters. | ||
|
|
@@ -104,6 +107,7 @@ public class MirrorSourceConnector extends SourceConnector { | |
| private Admin offsetSyncsAdminClient; | ||
| private volatile boolean useIncrementalAlterConfigs; | ||
| private AtomicBoolean noAclAuthorizer = new AtomicBoolean(false); | ||
| private Set<AclBinding> knownTopicAclBindings = Collections.emptySet(); | ||
|
|
||
| public MirrorSourceConnector() { | ||
| // nop | ||
|
|
@@ -581,13 +585,30 @@ void incrementalAlterConfigs(Map<String, Config> topicConfigs) { | |
| })); | ||
| } | ||
|
|
||
| private void updateTopicAcls(List<AclBinding> bindings) { | ||
| log.trace("Syncing {} topic ACL bindings.", bindings.size()); | ||
| targetAdminClient.createAcls(bindings).values().forEach((k, v) -> v.whenComplete((x, e) -> { | ||
| if (e != null) { | ||
| log.warn("Could not sync ACL of topic {}.", k.pattern().name(), e); | ||
| // Visible for testing | ||
| int updateTopicAcls(List<AclBinding> bindings) { | ||
| Set<AclBinding> addBindings = new HashSet<>(bindings); | ||
| Set<AclBinding> failedBindings = new HashSet<>(); | ||
| addBindings.removeAll(knownTopicAclBindings); | ||
| int newBindCount = addBindings.size(); | ||
| if (!addBindings.isEmpty()) { | ||
| log.info("Syncing new found {} topic ACL bindings.", newBindCount); | ||
| Map<AclBinding, KafkaFuture<Void>> futureMap = targetAdminClient.createAcls(addBindings).values(); | ||
| futureMap.forEach((k, v) -> v.whenComplete((x, e) -> { | ||
| if (e != null) { | ||
| log.warn("Could not sync ACL of topic {}.", k.pattern().name(), e); | ||
| failedBindings.add(k); | ||
| } | ||
| })); | ||
| while (!futureMap.values().stream().allMatch(Future::isDone)) { | ||
| sleep(1000); | ||
| } | ||
| })); | ||
| knownTopicAclBindings = new HashSet<>(bindings); | ||
|
hudeqi marked this conversation as resolved.
|
||
| knownTopicAclBindings.removeAll(failedBindings); | ||
|
Contributor
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. Isn't |
||
| } else { | ||
| log.debug("Not found new topic Acl info, skip sync!"); | ||
| } | ||
| return newBindCount - failedBindings.size(); | ||
| } | ||
|
|
||
| private static Stream<TopicPartition> expandTopicDescription(TopicDescription description) { | ||
|
|
@@ -672,4 +693,9 @@ boolean isCycle(String topic) { | |
| String formatRemoteTopic(String topic) { | ||
| return replicationPolicy.formatRemoteTopic(sourceAndTarget.source(), topic); | ||
| } | ||
|
|
||
| // Visible for testing | ||
| Set<AclBinding> knownTopicAclBindings() { | ||
| return knownTopicAclBindings; | ||
| } | ||
| } | ||
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
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.