You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2022/07/15 06:02:37 UTC

[GitHub] [kafka] C0urante commented on a diff in pull request #11781: KAFKA-10000: Per-connector offsets topics (KIP-618)

C0urante commented on code in PR #11781:
URL: https://github.com/apache/kafka/pull/11781#discussion_r921839879


##########
connect/runtime/src/main/java/org/apache/kafka/connect/runtime/Worker.java:
##########
@@ -1327,30 +1334,39 @@ public WorkerTask doBuild(Task task,
                     connectorClientConfigOverridePolicy, kafkaClusterId);
             KafkaProducer<byte[], byte[]> producer = new KafkaProducer<>(producerProps);
 
-            TopicAdmin topicAdmin;
+            // Prepare to create a topic admin if the task requires one, but do not actually create an instance
+            // until/unless one is needed
+            final AtomicReference<TopicAdmin> topicAdmin = new AtomicReference<>();
+            final Supplier<TopicAdmin> topicAdminCreator = () -> topicAdmin.updateAndGet(existingAdmin -> {
+                if (existingAdmin != null) {
+                    return existingAdmin;
+                }
+                Map<String, Object> adminOverrides = adminConfigs(id.connector(), "connector-adminclient-" + id, config,
+                        sourceConfig, connectorClass, connectorClientConfigOverridePolicy, kafkaClusterId, ConnectorType.SOURCE);
+                Admin adminClient = Admin.create(adminOverrides);
+                return new TopicAdmin(adminOverrides.get(BOOTSTRAP_SERVERS_CONFIG), adminClient);
+            });
+
             Map<String, TopicCreationGroup> topicCreationGroups;
             if (config.topicCreationEnable() && sourceConfig.usesTopicCreation()) {
                 topicCreationGroups = TopicCreationGroup.configuredGroups(sourceConfig);
                 // Create a topic admin that the task can use for topic creation
-                Map<String, Object> adminOverrides = adminConfigs(id.connector(), "connector-adminclient-" + id, config,
-                        sourceConfig, connectorClass, connectorClientConfigOverridePolicy, kafkaClusterId, ConnectorType.SOURCE);
-                topicAdmin = new TopicAdmin(adminOverrides);
+                topicAdminCreator.get();

Review Comment:
   👍 done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org