diff --git a/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java b/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java index fc8352ce77802..56276af08d369 100644 --- a/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java +++ b/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java @@ -710,11 +710,7 @@ final void fail(long now, Throwable throwable) { // TimeoutException. In this case, we do not get any more retries - the call has // failed. We increment tries anyway in order to display an accurate log message. tries++; - if (log.isDebugEnabled()) { - log.debug("{} aborted at {} after {} attempt(s)", this, now, tries, - new Exception(prettyPrintException(throwable))); - } - handleFailure(new TimeoutException("Aborted due to timeout.")); + failWithTimeout(now, throwable); return; } // If this is an UnsupportedVersionException that we can retry, do so. Note that a @@ -731,14 +727,10 @@ final void fail(long now, Throwable throwable) { // If the call has timed out, fail. if (calcTimeoutMsRemainingAsInt(now, deadlineMs) < 0) { - if (log.isDebugEnabled()) { - log.debug("{} timed out at {} after {} attempt(s)", this, now, tries, - new Exception(prettyPrintException(throwable))); - } - handleFailure(throwable); + failWithTimeout(now, throwable); return; } - // If the exception is not retryable, fail. + // If the exception is not retriable, fail. if (!(throwable instanceof RetriableException)) { if (log.isDebugEnabled()) { log.debug("{} failed with non-retriable exception after {} attempt(s)", this, tries, @@ -749,11 +741,7 @@ final void fail(long now, Throwable throwable) { } // If we are out of retries, fail. if (tries > maxRetries) { - if (log.isDebugEnabled()) { - log.debug("{} failed after {} attempt(s)", this, tries, - new Exception(prettyPrintException(throwable))); - } - handleFailure(throwable); + failWithTimeout(now, throwable); return; } if (log.isDebugEnabled()) { @@ -763,6 +751,15 @@ final void fail(long now, Throwable throwable) { runnable.enqueue(this, now); } + private void failWithTimeout(long now, Throwable cause) { + if (log.isDebugEnabled()) { + log.debug("{} timed out at {} after {} attempt(s)", this, now, tries, + new Exception(prettyPrintException(cause))); + } + handleFailure(new TimeoutException(this + " timed out at " + now + + " after " + tries + " attempt(s)", cause)); + } + /** * Create an AbstractRequest.Builder for this Call. * @@ -783,7 +780,7 @@ final void fail(long now, Throwable throwable) { /** * Handle a failure. This will only be called if the failure exception was not - * retryable, or if we hit a timeout. + * retriable, or if we hit a timeout. * * @param throwable The exception. */ @@ -1115,7 +1112,7 @@ private void handleResponses(long now, List responses) { } // Handle the result of the call. This may involve retrying the call, if we got a - // retryible exception. + // retriable exception. if (response.versionMismatch() != null) { call.fail(now, response.versionMismatch()); } else if (response.wasDisconnected()) {