@@ -1104,8 +1104,7 @@ private ClusterAndWaitTime waitOnMetadata(String topic, Integer partition, long
1104
1104
metadata .awaitUpdate (version , remainingWaitMs );
1105
1105
} catch (TimeoutException ex ) {
1106
1106
// 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 );
1109
1108
if (metadata .getError (topic ) != null ) {
1110
1109
throw new TimeoutException (errorMessage , metadata .getError (topic ).exception ());
1111
1110
}
@@ -1114,11 +1113,7 @@ private ClusterAndWaitTime waitOnMetadata(String topic, Integer partition, long
1114
1113
cluster = metadata .fetch ();
1115
1114
elapsed = time .milliseconds () - nowMs ;
1116
1115
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 );
1122
1117
if (metadata .getError (topic ) != null && metadata .getError (topic ).exception () instanceof RetriableException ) {
1123
1118
throw new TimeoutException (errorMessage , metadata .getError (topic ).exception ());
1124
1119
}
@@ -1134,6 +1129,13 @@ private ClusterAndWaitTime waitOnMetadata(String topic, Integer partition, long
1134
1129
return new ClusterAndWaitTime (cluster , elapsed );
1135
1130
}
1136
1131
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
+ }
1137
1139
/**
1138
1140
* Validate that the record size isn't too large
1139
1141
*/
0 commit comments