Skip to content

Commit 6612dd5

Browse files
committed
KAFKA-8862: Improve Producer error message for failed metadata update (#18587)
We should provide the same informative error message for both timeout cases. Reviewers: Kirk True <[email protected]>, Andrew Schofield <[email protected]>, Ismael Juma <[email protected]>
1 parent c6d452b commit 6612dd5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,8 +1104,7 @@ private ClusterAndWaitTime waitOnMetadata(String topic, Integer partition, long
11041104
metadata.awaitUpdate(version, remainingWaitMs);
11051105
} catch (TimeoutException ex) {
11061106
// Rethrow with original maxWaitMs to prevent logging exception with remainingWaitMs
1107-
final String errorMessage = String.format("Topic %s not present in metadata after %d ms.",
1108-
topic, maxWaitMs);
1107+
final String errorMessage = getErrorMessage(partitionsCount, topic, partition, maxWaitMs);
11091108
if (metadata.getError(topic) != null) {
11101109
throw new TimeoutException(errorMessage, metadata.getError(topic).exception());
11111110
}
@@ -1114,11 +1113,7 @@ private ClusterAndWaitTime waitOnMetadata(String topic, Integer partition, long
11141113
cluster = metadata.fetch();
11151114
elapsed = time.milliseconds() - nowMs;
11161115
if (elapsed >= maxWaitMs) {
1117-
final String errorMessage = partitionsCount == null ?
1118-
String.format("Topic %s not present in metadata after %d ms.",
1119-
topic, maxWaitMs) :
1120-
String.format("Partition %d of topic %s with partition count %d is not present in metadata after %d ms.",
1121-
partition, topic, partitionsCount, maxWaitMs);
1116+
final String errorMessage = getErrorMessage(partitionsCount, topic, partition, maxWaitMs);
11221117
if (metadata.getError(topic) != null && metadata.getError(topic).exception() instanceof RetriableException) {
11231118
throw new TimeoutException(errorMessage, metadata.getError(topic).exception());
11241119
}
@@ -1134,6 +1129,13 @@ private ClusterAndWaitTime waitOnMetadata(String topic, Integer partition, long
11341129
return new ClusterAndWaitTime(cluster, elapsed);
11351130
}
11361131

1132+
private String getErrorMessage(Integer partitionsCount, String topic, Integer partition, long maxWaitMs) {
1133+
return partitionsCount == null ?
1134+
String.format("Topic %s not present in metadata after %d ms.",
1135+
topic, maxWaitMs) :
1136+
String.format("Partition %d of topic %s with partition count %d is not present in metadata after %d ms.",
1137+
partition, topic, partitionsCount, maxWaitMs);
1138+
}
11371139
/**
11381140
* Validate that the record size isn't too large
11391141
*/

0 commit comments

Comments
 (0)