Search in sources :

Example 1 with ReplicaNotAvailableException

use of org.apache.kafka.common.errors.ReplicaNotAvailableException in project cruise-control by linkedin.

the class ExecutorAdminUtils method executeIntraBrokerReplicaMovements.

/**
 * Execute intra-broker replica movement tasks by sending alterReplicaLogDirs request.
 *
 * @param tasksToExecute The tasks to execute.
 * @param adminClient The adminClient to send alterReplicaLogDirs request.
 * @param executionTaskManager The task manager to do bookkeeping for task execution state.
 * @param config The config object that holds all the Cruise Control related configs
 */
static void executeIntraBrokerReplicaMovements(List<ExecutionTask> tasksToExecute, AdminClient adminClient, ExecutionTaskManager executionTaskManager, KafkaCruiseControlConfig config) {
    Map<TopicPartitionReplica, String> replicaAssignment = new HashMap<>();
    Map<TopicPartitionReplica, ExecutionTask> replicaToTask = new HashMap<>();
    tasksToExecute.forEach(t -> {
        TopicPartitionReplica tpr = new TopicPartitionReplica(t.proposal().topic(), t.proposal().partitionId(), t.brokerId());
        replicaAssignment.put(tpr, t.proposal().replicasToMoveBetweenDisksByBroker().get(t.brokerId()).logdir());
        replicaToTask.put(tpr, t);
    });
    for (Map.Entry<TopicPartitionReplica, KafkaFuture<Void>> entry : adminClient.alterReplicaLogDirs(replicaAssignment).values().entrySet()) {
        try {
            entry.getValue().get(config.getLong(LOGDIR_RESPONSE_TIMEOUT_MS_CONFIG), TimeUnit.MILLISECONDS);
        } catch (InterruptedException | ExecutionException | TimeoutException | LogDirNotFoundException | KafkaStorageException | ReplicaNotAvailableException e) {
            LOG.warn("Encounter exception {} when trying to execute task {}, mark task dead.", e.getMessage(), replicaToTask.get(entry.getKey()));
            executionTaskManager.markTaskAborting(replicaToTask.get(entry.getKey()));
            executionTaskManager.markTaskDead(replicaToTask.get(entry.getKey()));
        }
    }
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) HashMap(java.util.HashMap) ReplicaNotAvailableException(org.apache.kafka.common.errors.ReplicaNotAvailableException) LogDirNotFoundException(org.apache.kafka.common.errors.LogDirNotFoundException) TopicPartitionReplica(org.apache.kafka.common.TopicPartitionReplica) ExecutionException(java.util.concurrent.ExecutionException) HashMap(java.util.HashMap) Map(java.util.Map) TimeoutException(java.util.concurrent.TimeoutException) KafkaStorageException(org.apache.kafka.common.errors.KafkaStorageException)

Example 2 with ReplicaNotAvailableException

use of org.apache.kafka.common.errors.ReplicaNotAvailableException in project kafka by apache.

the class MockAdminClient method alterReplicaLogDirs.

@Override
public synchronized AlterReplicaLogDirsResult alterReplicaLogDirs(Map<TopicPartitionReplica, String> replicaAssignment, AlterReplicaLogDirsOptions options) {
    Map<TopicPartitionReplica, KafkaFuture<Void>> results = new HashMap<>();
    for (Map.Entry<TopicPartitionReplica, String> entry : replicaAssignment.entrySet()) {
        TopicPartitionReplica replica = entry.getKey();
        String newLogDir = entry.getValue();
        KafkaFutureImpl<Void> future = new KafkaFutureImpl<>();
        results.put(replica, future);
        List<String> dirs = brokerLogDirs.get(replica.brokerId());
        if (dirs == null) {
            future.completeExceptionally(new ReplicaNotAvailableException("Can't find " + replica));
        } else if (!dirs.contains(newLogDir)) {
            future.completeExceptionally(new KafkaStorageException("Log directory " + newLogDir + " is offline"));
        } else {
            TopicMetadata metadata = allTopics.get(replica.topic());
            if (metadata == null || metadata.partitions.size() <= replica.partition()) {
                future.completeExceptionally(new ReplicaNotAvailableException("Can't find " + replica));
            } else {
                String currentLogDir = metadata.partitionLogDirs.get(replica.partition());
                replicaMoves.put(replica, new ReplicaLogDirInfo(currentLogDir, 0, newLogDir, 0));
                future.complete(null);
            }
        }
    }
    return new AlterReplicaLogDirsResult(results);
}
Also used : ReplicaLogDirInfo(org.apache.kafka.clients.admin.DescribeReplicaLogDirsResult.ReplicaLogDirInfo) KafkaFuture(org.apache.kafka.common.KafkaFuture) HashMap(java.util.HashMap) ReplicaNotAvailableException(org.apache.kafka.common.errors.ReplicaNotAvailableException) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) TopicPartitionReplica(org.apache.kafka.common.TopicPartitionReplica) HashMap(java.util.HashMap) Map(java.util.Map) KafkaStorageException(org.apache.kafka.common.errors.KafkaStorageException)

Aggregations

HashMap (java.util.HashMap)2 Map (java.util.Map)2 KafkaFuture (org.apache.kafka.common.KafkaFuture)2 TopicPartitionReplica (org.apache.kafka.common.TopicPartitionReplica)2 KafkaStorageException (org.apache.kafka.common.errors.KafkaStorageException)2 ReplicaNotAvailableException (org.apache.kafka.common.errors.ReplicaNotAvailableException)2 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 ReplicaLogDirInfo (org.apache.kafka.clients.admin.DescribeReplicaLogDirsResult.ReplicaLogDirInfo)1 LogDirNotFoundException (org.apache.kafka.common.errors.LogDirNotFoundException)1 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)1