-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-8503; Add default api timeout to AdminClient (KIP-533) #8011
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
635513c
edc0711
4ad7c90
c83cf9d
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 |
|---|---|---|
|
|
@@ -53,6 +53,7 @@ | |
| import org.apache.kafka.common.acl.AclBindingFilter; | ||
| import org.apache.kafka.common.acl.AclOperation; | ||
| import org.apache.kafka.common.annotation.InterfaceStability; | ||
| import org.apache.kafka.common.config.ConfigException; | ||
| import org.apache.kafka.common.config.ConfigResource; | ||
| import org.apache.kafka.common.errors.ApiException; | ||
| import org.apache.kafka.common.errors.AuthenticationException; | ||
|
|
@@ -263,7 +264,12 @@ public class KafkaAdminClient extends AdminClient { | |
| /** | ||
| * The default timeout to use for an operation. | ||
| */ | ||
| private final int defaultTimeoutMs; | ||
| private final int defaultApiTimeoutMs; | ||
|
|
||
| /** | ||
| * The timeout to use for a single request. | ||
| */ | ||
| private final int requestTimeoutMs; | ||
|
|
||
| /** | ||
| * The name of this AdminClient instance. | ||
|
|
@@ -391,7 +397,7 @@ static String generateClientId(AdminClientConfig config) { | |
| private long calcDeadlineMs(long now, Integer optionTimeoutMs) { | ||
| if (optionTimeoutMs != null) | ||
| return now + Math.max(0, optionTimeoutMs); | ||
| return now + defaultTimeoutMs; | ||
| return now + defaultApiTimeoutMs; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -500,9 +506,10 @@ private KafkaAdminClient(AdminClientConfig config, | |
| KafkaClient client, | ||
| TimeoutProcessorFactory timeoutProcessorFactory, | ||
| LogContext logContext) { | ||
| this.defaultTimeoutMs = config.getInt(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG); | ||
| this.clientId = clientId; | ||
| this.log = logContext.logger(KafkaAdminClient.class); | ||
| this.requestTimeoutMs = config.getInt(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG); | ||
| this.defaultApiTimeoutMs = configureDefaultApiTimeoutMs(config); | ||
| this.time = time; | ||
| this.metadataManager = metadataManager; | ||
| this.metrics = metrics; | ||
|
|
@@ -520,8 +527,29 @@ private KafkaAdminClient(AdminClientConfig config, | |
| thread.start(); | ||
| } | ||
|
|
||
| Time time() { | ||
| return time; | ||
| /** | ||
| * If a default.api.timeout.ms has been explicitly specified, raise an error if it conflicts with request.timeout.ms. | ||
| * If no default.api.timeout.ms has been configured, then set its value as the max of the default and request.timeout.ms. Also we should probably log a warning. | ||
| * Otherwise, use the provided values for both configurations. | ||
| * | ||
| * @param config The configuration | ||
| */ | ||
| private int configureDefaultApiTimeoutMs(AdminClientConfig config) { | ||
|
Member
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. This could even be static now, yes?
Contributor
Author
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. We still have the log message, which is a bit annoying. Guess I will leave it as is unless you feel strongly about it. |
||
| int requestTimeoutMs = config.getInt(AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG); | ||
| int defaultApiTimeoutMs = config.getInt(AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG); | ||
|
|
||
| if (defaultApiTimeoutMs < requestTimeoutMs) { | ||
| if (config.originals().containsKey(AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG)) { | ||
| throw new ConfigException("The specified value of " + AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG + | ||
| " must be no smaller than the value of " + AdminClientConfig.REQUEST_TIMEOUT_MS_CONFIG + "."); | ||
| } else { | ||
| log.warn("Overriding the default value for {} ({}) with the explicitly configured request timeout {}", | ||
| AdminClientConfig.DEFAULT_API_TIMEOUT_MS_CONFIG, this.defaultApiTimeoutMs, | ||
| requestTimeoutMs); | ||
| return requestTimeoutMs; | ||
| } | ||
| } | ||
| return defaultApiTimeoutMs; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -993,16 +1021,18 @@ private long sendEligibleCalls(long now) { | |
| continue; | ||
| } | ||
| Call call = calls.remove(0); | ||
| int timeoutMs = calcTimeoutMsRemainingAsInt(now, call.deadlineMs); | ||
| int requestTimeoutMs = Math.min(KafkaAdminClient.this.requestTimeoutMs, | ||
| calcTimeoutMsRemainingAsInt(now, call.deadlineMs)); | ||
|
mumrah marked this conversation as resolved.
|
||
| AbstractRequest.Builder<?> requestBuilder; | ||
| try { | ||
| requestBuilder = call.createRequest(timeoutMs); | ||
| requestBuilder = call.createRequest(requestTimeoutMs); | ||
| } catch (Throwable throwable) { | ||
| call.fail(now, new KafkaException(String.format( | ||
| "Internal error sending %s to %s.", call.callName, node))); | ||
| continue; | ||
| } | ||
| ClientRequest clientRequest = client.newClientRequest(node.idString(), requestBuilder, now, true); | ||
| ClientRequest clientRequest = client.newClientRequest(node.idString(), requestBuilder, now, | ||
| true, requestTimeoutMs, null); | ||
| log.trace("Sending {} to {}. correlationId={}", requestBuilder, node, clientRequest.correlationId()); | ||
| client.send(clientRequest, now); | ||
| getOrCreateListValue(callsInFlight, node.idString()).add(call); | ||
|
|
@@ -1300,7 +1330,7 @@ void call(Call call, long now) { | |
| * Create a new metadata call. | ||
| */ | ||
| private Call makeMetadataCall(long now) { | ||
| return new Call(true, "fetchMetadata", calcDeadlineMs(now, defaultTimeoutMs), | ||
| return new Call(true, "fetchMetadata", calcDeadlineMs(now, requestTimeoutMs), | ||
| new MetadataUpdateNodeIdProvider()) { | ||
| @Override | ||
| public MetadataRequest.Builder createRequest(int timeoutMs) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.