Skip to content

Commit 24cad50

Browse files
authored
MINOR: Adjust the timing for creating connect config (#20612)
[In this PR](#20334), we added some validation checks for the connect config, such as ensuring that `plugin.path` cannot be empty. However, currently, Connect first loads the plugin and then creates the configuration. Even if `plugin.path` is empty, it still attempts to load the plugin first, and then throws an exception when creating the configuration. The approach should be to first create a configuration to validate that the config meet the requirements, and then load the plugin only if the validation passes. This allows for early detection of problems and avoids unnecessary plugin loading processes. Reviewers: Ken Huang <[email protected]>, Chia-Ping Tsai <[email protected]>
1 parent 71a7d85 commit 24cad50

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

connect/mirror/src/main/java/org/apache/kafka/connect/mirror/MirrorMaker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,13 @@ private void checkHerder(SourceAndTarget sourceAndTarget) {
233233
private void addHerder(SourceAndTarget sourceAndTarget) {
234234
log.info("creating herder for {}", sourceAndTarget.toString());
235235
Map<String, String> workerProps = config.workerConfig(sourceAndTarget);
236+
DistributedConfig distributedConfig = new DistributedConfig(workerProps);
236237
String encodedSource = encodePath(sourceAndTarget.source());
237238
String encodedTarget = encodePath(sourceAndTarget.target());
238239
List<String> restNamespace = List.of(encodedSource, encodedTarget);
239240
String workerId = generateWorkerId(sourceAndTarget);
240241
Plugins plugins = new Plugins(workerProps);
241242
plugins.compareAndSwapWithDelegatingLoader();
242-
DistributedConfig distributedConfig = new DistributedConfig(workerProps);
243243
String kafkaClusterId = distributedConfig.kafkaClusterId();
244244
String clientIdBase = ConnectUtils.clientIdBase(distributedConfig);
245245
// Create the admin client to be shared by all backing stores for this herder

connect/runtime/src/main/java/org/apache/kafka/connect/cli/AbstractConnectCli.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,15 @@ public Connect<H> startConnect(Map<String, String> workerProps) {
114114
log.info("Kafka Connect worker initializing ...");
115115
long initStart = time.hiResClockMs();
116116

117+
T config = createConfig(workerProps);
118+
log.debug("Kafka cluster ID: {}", config.kafkaClusterId());
119+
117120
WorkerInfo initInfo = new WorkerInfo();
118121
initInfo.logAll();
119122

120123
log.info("Scanning for plugin classes. This might take a moment ...");
121124
Plugins plugins = new Plugins(workerProps);
122125
plugins.compareAndSwapWithDelegatingLoader();
123-
T config = createConfig(workerProps);
124-
log.debug("Kafka cluster ID: {}", config.kafkaClusterId());
125126

126127
RestClient restClient = new RestClient(config);
127128

0 commit comments

Comments
 (0)