Search in sources :

Example 96 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class ClientCompatibilityTest method testDescribeConfigsMethod.

private void testDescribeConfigsMethod(final Admin client) throws Throwable {
    tryFeature("describeConfigsSupported", testConfig.describeConfigsSupported, () -> {
        try {
            Collection<Node> nodes = client.describeCluster().nodes().get();
            final ConfigResource configResource = new ConfigResource(ConfigResource.Type.BROKER, nodes.iterator().next().idString());
            Map<ConfigResource, Config> brokerConfig = client.describeConfigs(Collections.singleton(configResource)).all().get();
            if (brokerConfig.get(configResource).entries().isEmpty()) {
                throw new KafkaException("Expected to see config entries, but got zero entries");
            }
        } catch (ExecutionException e) {
            throw e.getCause();
        }
    });
}
Also used : ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) Config(org.apache.kafka.clients.admin.Config) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) AdminClientConfig(org.apache.kafka.clients.admin.AdminClientConfig) Node(org.apache.kafka.common.Node) KafkaException(org.apache.kafka.common.KafkaException) ExecutionException(java.util.concurrent.ExecutionException) ConfigResource(org.apache.kafka.common.config.ConfigResource)

Example 97 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class TopicBasedRemoteLogMetadataManagerHarness method initializeRemoteLogMetadataManager.

public void initializeRemoteLogMetadataManager(Set<TopicIdPartition> topicIdPartitions, boolean startConsumerThread) {
    String logDir = TestUtils.tempDirectory("rlmm_segs_").getAbsolutePath();
    topicBasedRemoteLogMetadataManager = new TopicBasedRemoteLogMetadataManager(startConsumerThread) {

        @Override
        public void onPartitionLeadershipChanges(Set<TopicIdPartition> leaderPartitions, Set<TopicIdPartition> followerPartitions) {
            Set<TopicIdPartition> allReplicas = new HashSet<>(leaderPartitions);
            allReplicas.addAll(followerPartitions);
            // Make sure the topic partition dirs exist as the topics might not have been created on this broker.
            for (TopicIdPartition topicIdPartition : allReplicas) {
                // Create partition directory in the log directory created by topicBasedRemoteLogMetadataManager.
                File partitionDir = new File(new File(config().logDir()), topicIdPartition.topicPartition().topic() + "-" + topicIdPartition.topicPartition().partition());
                partitionDir.mkdirs();
                if (!partitionDir.exists()) {
                    throw new KafkaException("Partition directory:[" + partitionDir + "] could not be created successfully.");
                }
            }
            super.onPartitionLeadershipChanges(leaderPartitions, followerPartitions);
        }
    };
    // Initialize TopicBasedRemoteLogMetadataManager.
    Map<String, Object> configs = new HashMap<>();
    configs.put(REMOTE_LOG_METADATA_COMMON_CLIENT_PREFIX + CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers(listenerName()));
    configs.put(BROKER_ID, 0);
    configs.put(LOG_DIR, logDir);
    configs.put(REMOTE_LOG_METADATA_TOPIC_PARTITIONS_PROP, METADATA_TOPIC_PARTITIONS_COUNT);
    configs.put(REMOTE_LOG_METADATA_TOPIC_REPLICATION_FACTOR_PROP, METADATA_TOPIC_REPLICATION_FACTOR);
    configs.put(REMOTE_LOG_METADATA_TOPIC_RETENTION_MS_PROP, METADATA_TOPIC_RETENTION_MS);
    log.debug("TopicBasedRemoteLogMetadataManager configs before adding overridden properties: {}", configs);
    // Add override properties.
    configs.putAll(overrideRemoteLogMetadataManagerProps());
    log.debug("TopicBasedRemoteLogMetadataManager configs after adding overridden properties: {}", configs);
    topicBasedRemoteLogMetadataManager.configure(configs);
    try {
        waitUntilInitialized(60_000);
    } catch (TimeoutException e) {
        throw new KafkaException(e);
    }
    topicBasedRemoteLogMetadataManager.onPartitionLeadershipChanges(topicIdPartitions, Collections.emptySet());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) TopicIdPartition(org.apache.kafka.common.TopicIdPartition) KafkaException(org.apache.kafka.common.KafkaException) File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException)

Example 98 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class ConsumerTask method maybeWaitForPartitionsAssignment.

private void maybeWaitForPartitionsAssignment() {
    Set<Integer> assignedMetaPartitionsSnapshot = Collections.emptySet();
    synchronized (assignPartitionsLock) {
        // in close() method with in the same lock to avoid any race conditions.
        if (closing) {
            return;
        }
        while (assignedMetaPartitions.isEmpty()) {
            // If no partitions are assigned, wait until they are assigned.
            log.debug("Waiting for assigned remote log metadata partitions..");
            try {
                // No timeout is set here, as it is always notified. Even when it is closed, the race can happen
                // between the thread calling this method and the thread calling close(). We should have a check
                // for closing as that might have been set and notified with assignPartitionsLock by `close`
                // method.
                assignPartitionsLock.wait();
                if (closing) {
                    return;
                }
            } catch (InterruptedException e) {
                throw new KafkaException(e);
            }
        }
        if (assignPartitions) {
            assignedMetaPartitionsSnapshot = new HashSet<>(assignedMetaPartitions);
            // Removing unassigned meta partitions from partitionToConsumedOffsets and partitionToCommittedOffsets
            partitionToConsumedOffsets.entrySet().removeIf(entry -> !assignedMetaPartitions.contains(entry.getKey()));
            assignPartitions = false;
        }
    }
    if (!assignedMetaPartitionsSnapshot.isEmpty()) {
        executeReassignment(assignedMetaPartitionsSnapshot);
    }
}
Also used : KafkaException(org.apache.kafka.common.KafkaException)

Example 99 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class ConsumerManager method startConsumerThread.

public void startConsumerThread() {
    try {
        // Start a thread to continuously consume records from topic partitions.
        consumerTaskThread.start();
        log.info("RLMM Consumer task thread is started");
    } catch (Exception e) {
        throw new KafkaException("Error encountered while initializing and scheduling ConsumerTask thread", e);
    }
}
Also used : KafkaException(org.apache.kafka.common.KafkaException) KafkaException(org.apache.kafka.common.KafkaException) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException)

Example 100 with KafkaException

use of org.apache.kafka.common.KafkaException in project kafka by apache.

the class ConsumerTask method maybeSyncCommittedDataAndOffsets.

private void maybeSyncCommittedDataAndOffsets(boolean forceSync) {
    // Return immediately if there is no consumption from last time.
    boolean noConsumedOffsetUpdates = partitionToConsumedOffsets.equals(lastSyncedPartitionToConsumedOffsets);
    if (noConsumedOffsetUpdates || !forceSync && time.milliseconds() - lastSyncedTimeMs < committedOffsetSyncIntervalMs) {
        log.debug("Skip syncing committed offsets, noConsumedOffsetUpdates: {}, forceSync: {}", noConsumedOffsetUpdates, forceSync);
        return;
    }
    try {
        // get updated by other threads.
        synchronized (assignPartitionsLock) {
            for (TopicIdPartition topicIdPartition : assignedTopicPartitions) {
                int metadataPartition = topicPartitioner.metadataPartition(topicIdPartition);
                Long offset = partitionToConsumedOffsets.get(metadataPartition);
                if (offset != null) {
                    remotePartitionMetadataEventHandler.syncLogMetadataSnapshot(topicIdPartition, metadataPartition, offset);
                } else {
                    log.debug("Skipping syncup of the remote-log-metadata-file for partition:{} , with remote log metadata partition{}, and no offset", topicIdPartition, metadataPartition);
                }
            }
            // Write partitionToConsumedOffsets into committed offsets file as we do not want to process them again
            // in case of restarts.
            committedOffsetsFile.writeEntries(partitionToConsumedOffsets);
            lastSyncedPartitionToConsumedOffsets = new HashMap<>(partitionToConsumedOffsets);
        }
        lastSyncedTimeMs = time.milliseconds();
    } catch (IOException e) {
        throw new KafkaException("Error encountered while writing committed offsets to a local file", e);
    }
}
Also used : KafkaException(org.apache.kafka.common.KafkaException) TopicIdPartition(org.apache.kafka.common.TopicIdPartition) IOException(java.io.IOException)

Aggregations

KafkaException (org.apache.kafka.common.KafkaException)262 Test (org.junit.Test)69 TopicPartition (org.apache.kafka.common.TopicPartition)56 Test (org.junit.jupiter.api.Test)47 HashMap (java.util.HashMap)40 IOException (java.io.IOException)39 StreamsException (org.apache.kafka.streams.errors.StreamsException)34 Map (java.util.Map)32 TimeoutException (org.apache.kafka.common.errors.TimeoutException)28 ArrayList (java.util.ArrayList)27 List (java.util.List)21 ByteBuffer (java.nio.ByteBuffer)19 ExecutionException (java.util.concurrent.ExecutionException)19 ConfigException (org.apache.kafka.common.config.ConfigException)16 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)14 HashSet (java.util.HashSet)13 Properties (java.util.Properties)13 Set (java.util.Set)11 Collectors (java.util.stream.Collectors)11 RecordMetadata (org.apache.kafka.clients.producer.RecordMetadata)11