poorbarcode commented on code in PR #24975:
URL: https://github.com/apache/pulsar/pull/24975#discussion_r2532072834
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/persistent/PersistentTopic.java:
##########
@@ -1520,8 +1517,23 @@ private CompletableFuture<Void> delete(boolean
failIfHasSubscriptions,
"Topic has " + producers.size() + " connected
producers"));
}
} else if (currentUsageCount() > 0) {
- return FutureUtil.failedFuture(new TopicBusyException(
- "Topic has " + currentUsageCount() + " connected
producers/consumers"));
+ StringBuilder errorMsg = new StringBuilder("Topic has");
+ errorMsg.append(" ").append(currentUsageCount())
+ .append(currentUsageCount() == 1 ? " client" : "
clients").append(" connected");
+ long consumerCount =
subscriptions.values().stream().map(sub -> sub.getConsumers().size())
+ .reduce(0, Integer::sum);
+ long replicatorCount = 0;
+ long producerCount = 0;
+ if (!producers.isEmpty()) {
+ replicatorCount =
producers.values().stream().filter(Producer::isRemote).count();
+ if (producers.size() > replicatorCount) {
+ producerCount = producers.size() - replicatorCount;
+ }
+ }
+ errorMsg.append(" Including").append("
").append(consumerCount).append(" consumers,")
+ .append(" ").append(producerCount).append("
producers,").append(" and")
+ .append(" ").append(replicatorCount).append("
replicators.");
+ return FutureUtil.failedFuture(new
TopicBusyException(errorMsg.toString()));
Review Comment:
Ah, they are the same. "String.format" throws an exception when placeholders
do not match, while stringBuffer is relatively safe.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]