Search in sources :

Example 1 with UnknownTopicIdException

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;
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) HashMap(java.util.HashMap) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) Uuid(org.apache.kafka.common.Uuid) UnknownTopicIdException(org.apache.kafka.common.errors.UnknownTopicIdException) HashMap(java.util.HashMap) Map(java.util.Map) TimeoutException(org.apache.kafka.common.errors.TimeoutException)

Example 2 with UnknownTopicIdException

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()));
}
Also used : ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) RemoveTopicRecord(org.apache.kafka.common.metadata.RemoveTopicRecord) UnknownTopicIdException(org.apache.kafka.common.errors.UnknownTopicIdException)

Example 3 with UnknownTopicIdException

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());
}
Also used : PartitionRegistration(org.apache.kafka.metadata.PartitionRegistration) UnknownTopicIdException(org.apache.kafka.common.errors.UnknownTopicIdException)

Aggregations

UnknownTopicIdException (org.apache.kafka.common.errors.UnknownTopicIdException)3 HashMap (java.util.HashMap)1 Map (java.util.Map)1 KafkaFuture (org.apache.kafka.common.KafkaFuture)1 Uuid (org.apache.kafka.common.Uuid)1 TimeoutException (org.apache.kafka.common.errors.TimeoutException)1 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)1 RemoveTopicRecord (org.apache.kafka.common.metadata.RemoveTopicRecord)1 PartitionRegistration (org.apache.kafka.metadata.PartitionRegistration)1 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)1