use of org.apache.kafka.common.errors.UnknownTopicIdException in project kafka by apache.
the class MockAdminClient method handleDescribeTopicsUsingIds.
public synchronized Map<Uuid, KafkaFuture<TopicDescription>> handleDescribeTopicsUsingIds(Collection<Uuid> topicIds, DescribeTopicsOptions options) {
Map<Uuid, KafkaFuture<TopicDescription>> topicDescriptions = new HashMap<>();
if (timeoutNextRequests > 0) {
for (Uuid requestedTopicId : topicIds) {
KafkaFutureImpl<TopicDescription> future = new KafkaFutureImpl<>();
future.completeExceptionally(new TimeoutException());
topicDescriptions.put(requestedTopicId, future);
}
--timeoutNextRequests;
return topicDescriptions;
}
for (Uuid requestedTopicId : topicIds) {
for (Map.Entry<String, TopicMetadata> topicDescription : allTopics.entrySet()) {
String topicName = topicDescription.getKey();
Uuid topicId = this.topicIds.get(topicName);
if (topicId != null && topicId.equals(requestedTopicId) && !topicDescription.getValue().markedForDeletion) {
if (topicDescription.getValue().fetchesRemainingUntilVisible > 0) {
topicDescription.getValue().fetchesRemainingUntilVisible--;
} else {
TopicMetadata topicMetadata = topicDescription.getValue();
KafkaFutureImpl<TopicDescription> future = new KafkaFutureImpl<>();
future.complete(new TopicDescription(topicName, topicMetadata.isInternalTopic, topicMetadata.partitions, Collections.emptySet(), topicId));
topicDescriptions.put(requestedTopicId, future);
break;
}
}
}
if (!topicDescriptions.containsKey(requestedTopicId)) {
KafkaFutureImpl<TopicDescription> future = new KafkaFutureImpl<>();
future.completeExceptionally(new UnknownTopicIdException("Topic id" + requestedTopicId + " not found."));
topicDescriptions.put(requestedTopicId, future);
}
}
return topicDescriptions;
}
use of org.apache.kafka.common.errors.UnknownTopicIdException in project kafka by apache.
the class ReplicationControlManager method deleteTopic.
void deleteTopic(Uuid id, List<ApiMessageAndVersion> records) {
TopicControlInfo topic = topics.get(id);
if (topic == null) {
throw new UnknownTopicIdException(UNKNOWN_TOPIC_ID.message());
}
records.add(new ApiMessageAndVersion(new RemoveTopicRecord().setTopicId(id), REMOVE_TOPIC_RECORD.highestSupportedVersion()));
}
use of org.apache.kafka.common.errors.UnknownTopicIdException in project kafka by apache.
the class ReplicationControlManager method replay.
public void replay(RemoveTopicRecord record) {
// Remove this topic from the topics map and the topicsByName map.
TopicControlInfo topic = topics.remove(record.topicId());
if (topic == null) {
throw new UnknownTopicIdException("Can't find topic with ID " + record.topicId() + " to remove.");
}
topicsByName.remove(topic.name);
reassigningTopics.remove(record.topicId());
// Delete the configurations associated with this topic.
configurationControl.deleteTopicConfigs(topic.name);
// Remove the entries for this topic in brokersToIsrs.
for (PartitionRegistration partition : topic.parts.values()) {
for (int i = 0; i < partition.isr.length; i++) {
brokersToIsrs.removeTopicEntryForBroker(topic.id, partition.isr[i]);
}
if (partition.leader != partition.preferredReplica()) {
preferredReplicaImbalanceCount.decrement();
}
globalPartitionCount.decrement();
}
brokersToIsrs.removeTopicEntryForBroker(topic.id, NO_LEADER);
controllerMetrics.setGlobalTopicsCount(topics.size());
controllerMetrics.setGlobalPartitionCount(globalPartitionCount.get());
controllerMetrics.setOfflinePartitionCount(brokersToIsrs.offlinePartitionCount());
controllerMetrics.setPreferredReplicaImbalanceCount(preferredReplicaImbalanceCount.get());
log.info("Removed topic {} with ID {}.", topic.name, record.topicId());
}
Aggregations