-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-10021: Changed Kafka backing stores to use shared admin client to get end offsets and create topics #9780
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ | |
| import org.apache.kafka.common.utils.LogContext; | ||
| import org.apache.kafka.common.utils.ThreadUtils; | ||
| import org.apache.kafka.common.utils.Time; | ||
| import org.apache.kafka.common.utils.Utils; | ||
| import org.apache.kafka.connect.connector.Connector; | ||
| import org.apache.kafka.connect.connector.policy.ConnectorClientConfigOverridePolicy; | ||
| import org.apache.kafka.connect.errors.AlreadyExistsException; | ||
|
|
@@ -66,6 +67,7 @@ | |
| import javax.crypto.SecretKey; | ||
| import javax.ws.rs.core.Response; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.HashSet; | ||
|
|
@@ -138,6 +140,7 @@ public class DistributedHerder extends AbstractHerder implements Runnable { | |
|
|
||
| private final Time time; | ||
| private final HerderMetrics herderMetrics; | ||
| private final List<AutoCloseable> uponShutdown; | ||
|
|
||
| private final String workerGroupId; | ||
| private final int workerSyncTimeoutMs; | ||
|
|
@@ -185,16 +188,33 @@ public class DistributedHerder extends AbstractHerder implements Runnable { | |
|
|
||
| private final DistributedConfig config; | ||
|
|
||
| /** | ||
| * Create a herder that will form a Connect cluster with other {@link DistributedHerder} instances (in this or other JVMs) | ||
| * that have the same group ID. | ||
| * | ||
| * @param config the configuration for the worker; may not be null | ||
| * @param time the clock to use; may not be null | ||
| * @param worker the {@link Worker} instance to use; may not be null | ||
| * @param kafkaClusterId the identifier of the Kafka cluster to use for internal topics; may not be null | ||
| * @param statusBackingStore the backing store for statuses; may not be null | ||
| * @param configBackingStore the backing store for connector configurations; may not be null | ||
| * @param restUrl the URL of this herder's REST API; may not be null | ||
| * @param connectorClientConfigOverridePolicy the policy specifying the client configuration properties that may be overridden | ||
| * in connector configurations; may not be null | ||
| * @param uponShutdown any {@link AutoCloseable} objects that should be closed when this herder is {@link #stop() stopped}, | ||
| * after all services and resources owned by this herder are stopped | ||
| */ | ||
| public DistributedHerder(DistributedConfig config, | ||
| Time time, | ||
| Worker worker, | ||
| String kafkaClusterId, | ||
| StatusBackingStore statusBackingStore, | ||
| ConfigBackingStore configBackingStore, | ||
| String restUrl, | ||
| ConnectorClientConfigOverridePolicy connectorClientConfigOverridePolicy) { | ||
| ConnectorClientConfigOverridePolicy connectorClientConfigOverridePolicy, | ||
| AutoCloseable... uponShutdown) { | ||
| this(config, worker, worker.workerId(), kafkaClusterId, statusBackingStore, configBackingStore, null, restUrl, worker.metrics(), | ||
| time, connectorClientConfigOverridePolicy); | ||
| time, connectorClientConfigOverridePolicy, uponShutdown); | ||
| configBackingStore.setUpdateListener(new ConfigUpdateListener()); | ||
| } | ||
|
|
||
|
|
@@ -209,7 +229,8 @@ public DistributedHerder(DistributedConfig config, | |
| String restUrl, | ||
| ConnectMetrics metrics, | ||
| Time time, | ||
| ConnectorClientConfigOverridePolicy connectorClientConfigOverridePolicy) { | ||
| ConnectorClientConfigOverridePolicy connectorClientConfigOverridePolicy, | ||
| AutoCloseable... uponShutdown) { | ||
|
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. see comment above |
||
| super(worker, workerId, kafkaClusterId, statusBackingStore, configBackingStore, connectorClientConfigOverridePolicy); | ||
|
|
||
| this.time = time; | ||
|
|
@@ -223,6 +244,7 @@ public DistributedHerder(DistributedConfig config, | |
| this.keySignatureVerificationAlgorithms = config.getList(DistributedConfig.INTER_WORKER_VERIFICATION_ALGORITHMS_CONFIG); | ||
| this.keyGenerator = config.getInternalRequestKeyGenerator(); | ||
| this.isTopicTrackingEnabled = config.getBoolean(TOPIC_TRACKING_ENABLE_CONFIG); | ||
| this.uponShutdown = Arrays.asList(uponShutdown); | ||
|
|
||
| String clientIdConfig = config.getString(CommonClientConfigs.CLIENT_ID_CONFIG); | ||
| String clientId = clientIdConfig.length() <= 0 ? "connect-" + CONNECT_CLIENT_ID_SEQUENCE.getAndIncrement() : clientIdConfig; | ||
|
|
@@ -676,6 +698,15 @@ public void halt() { | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected void stopServices() { | ||
| try { | ||
| super.stopServices(); | ||
| } finally { | ||
| this.uponShutdown.forEach(closeable -> Utils.closeQuietly(closeable, closeable != null ? closeable.toString() : "<unknown>")); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void stop() { | ||
| log.info("Herder stopping"); | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to avoid a variadic argument here.
Parameters tend to get added with new features in such constructors. And if a new parameter is required that is also a list, then we'll have a mix of list args with a variadic in the end.
Since we transform to list I'd suggest using this type here and pass the single argument with
Collections.singletonListin the caller.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I used a variadic array here was to avoid having to create a new connector when no
AutoCloseableinstances are supplied. If we use a List, then we can change the usage in Connect runtime and in MirrorMaker 2, but anywhere else will break without keeping the old signature. WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can always keep a constructor with the old signature along with the new if we wanted not to break classes that use
DistributedHerder. I'm fine with the change here as a short term workaround. I guess it saves us one constructor but we can use it only once.