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()));
}
}
}
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);
}
Aggregations