Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace DescribeLogDirsResult.values method with descriptions method #2190

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.stream.Collectors;
import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.common.Node;
import org.apache.kafka.common.protocol.Errors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -89,10 +88,10 @@ public void run() {
}
Map<Integer, Map<String, Long>> failedDisksByBroker = new HashMap<>();
Set<Integer> aliveBrokers = _kafkaCruiseControl.kafkaCluster().nodes().stream().mapToInt(Node::id).boxed().collect(Collectors.toSet());
_adminClient.describeLogDirs(aliveBrokers).values().forEach((broker, future) -> {
_adminClient.describeLogDirs(aliveBrokers).descriptions().forEach((broker, future) -> {
try {
future.get(_config.getLong(LOGDIR_RESPONSE_TIMEOUT_MS_CONFIG), TimeUnit.MILLISECONDS).forEach((logdir, info) -> {
if (info.error != Errors.NONE) {
if (info.error() != null) {
failedDisksByBroker.putIfAbsent(broker, new HashMap<>());
failedDisksByBroker.get(broker).put(logdir, _kafkaCruiseControl.timeMs());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
import java.util.concurrent.TimeoutException;
import com.linkedin.kafka.cruisecontrol.config.KafkaCruiseControlConfig;
import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.LogDirDescription;
import org.apache.kafka.clients.admin.ReplicaInfo;
import org.apache.kafka.common.KafkaFuture;
import org.apache.kafka.common.TopicPartitionReplica;
import org.apache.kafka.common.errors.KafkaStorageException;
import org.apache.kafka.common.errors.LogDirNotFoundException;
import org.apache.kafka.common.errors.ReplicaNotAvailableException;
import org.apache.kafka.common.protocol.Errors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static com.linkedin.kafka.cruisecontrol.config.constants.ExecutorConfig.LOGDIR_RESPONSE_TIMEOUT_MS_CONFIG;
import static org.apache.kafka.clients.admin.DescribeReplicaLogDirsResult.ReplicaLogDirInfo;
import static org.apache.kafka.common.requests.DescribeLogDirsResponse.LogDirInfo;

public final class ExecutorAdminUtils {
private static final Logger LOG = LoggerFactory.getLogger(ExecutorAdminUtils.class);
Expand Down Expand Up @@ -104,15 +104,16 @@ static void executeIntraBrokerReplicaMovements(List<ExecutionTask> tasksToExecut
* @param config The config object that holds all the Cruise Control related configs
* @return {@code true} if there is ongoing intra-broker replica movement.
*/
static boolean hasOngoingIntraBrokerReplicaMovement(Collection<Integer> brokersToCheck, AdminClient adminClient,
static boolean hasOngoingIntraBrokerReplicaMovement(Collection<Integer> brokersToCheck,
AdminClient adminClient,
KafkaCruiseControlConfig config)
throws InterruptedException, ExecutionException, TimeoutException {
Map<Integer, KafkaFuture<Map<String, LogDirInfo>>> logDirsByBrokerId = adminClient.describeLogDirs(brokersToCheck).values();
for (Map.Entry<Integer, KafkaFuture<Map<String, LogDirInfo>>> entry : logDirsByBrokerId.entrySet()) {
Map<String, LogDirInfo> logInfos = entry.getValue().get(config.getLong(LOGDIR_RESPONSE_TIMEOUT_MS_CONFIG), TimeUnit.MILLISECONDS);
for (LogDirInfo info : logInfos.values()) {
if (info.error == Errors.NONE) {
if (info.replicaInfos.values().stream().anyMatch(i -> i.isFuture)) {
Map<Integer, KafkaFuture<Map<String, LogDirDescription>>> logDirsByBrokerId = adminClient.describeLogDirs(brokersToCheck).descriptions();
for (Map.Entry<Integer, KafkaFuture<Map<String, LogDirDescription>>> entry : logDirsByBrokerId.entrySet()) {
Map<String, LogDirDescription> logInfos = entry.getValue().get(config.getLong(LOGDIR_RESPONSE_TIMEOUT_MS_CONFIG), TimeUnit.MILLISECONDS);
for (LogDirDescription info : logInfos.values()) {
if (info.error() == null) {
if (info.replicaInfos().values().stream().anyMatch(ReplicaInfo::isFuture)) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.LogDirDescription;
import org.apache.kafka.clients.admin.ReplicaInfo;
import org.apache.kafka.common.Cluster;
import org.apache.kafka.common.KafkaFuture;
import org.apache.kafka.common.Node;
import org.apache.kafka.common.PartitionInfo;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.protocol.Errors;
import org.apache.kafka.common.requests.DescribeLogDirsResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -370,15 +370,15 @@ static Map<TopicPartition, Map<Integer, String>> getReplicaPlacementInfo(Cluster
AdminClient adminClient,
KafkaCruiseControlConfig config) {
Map<TopicPartition, Map<Integer, String>> replicaPlacementInfo = new HashMap<>();
Map<Integer, KafkaFuture<Map<String, DescribeLogDirsResponse.LogDirInfo>>> logDirsByBrokerId =
adminClient.describeLogDirs(cluster.nodes().stream().mapToInt(Node::id).boxed().collect(Collectors.toList())).values();
for (Map.Entry<Integer, KafkaFuture<Map<String, DescribeLogDirsResponse.LogDirInfo>>> entry : logDirsByBrokerId.entrySet()) {
Map<Integer, KafkaFuture<Map<String, LogDirDescription>>> logDirsByBrokerId =
adminClient.describeLogDirs(cluster.nodes().stream().mapToInt(Node::id).boxed().collect(Collectors.toList())).descriptions();
for (Map.Entry<Integer, KafkaFuture<Map<String, LogDirDescription>>> entry : logDirsByBrokerId.entrySet()) {
Integer brokerId = entry.getKey();
try {
entry.getValue().get(config.getLong(LOGDIR_RESPONSE_TIMEOUT_MS_CONFIG), TimeUnit.MILLISECONDS).forEach((logdir, info) -> {
if (info.error == Errors.NONE) {
for (Map.Entry<TopicPartition, DescribeLogDirsResponse.ReplicaInfo> e : info.replicaInfos.entrySet()) {
if (!e.getValue().isFuture) {
if (info.error() == null) {
for (Map.Entry<TopicPartition, ReplicaInfo> e : info.replicaInfos().entrySet()) {
if (!e.getValue().isFuture()) {
replicaPlacementInfo.putIfAbsent(e.getKey(), new HashMap<>());
replicaPlacementInfo.get(e.getKey()).put(brokerId, logdir);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.LogDirDescription;
import org.apache.kafka.common.Cluster;
import org.apache.kafka.common.KafkaFuture;
import org.apache.kafka.common.Node;
import org.apache.kafka.common.PartitionInfo;
import org.apache.kafka.common.protocol.Errors;
import org.apache.kafka.common.requests.DescribeLogDirsResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -181,15 +180,15 @@ protected void populateKafkaBrokerLogDirState(Map<Integer, Set<String>> onlineLo
}
}

Map<Integer, KafkaFuture<Map<String, DescribeLogDirsResponse.LogDirInfo>>> logDirsByBrokerId
= _adminClient.describeLogDirs(aliveBrokers).values();
for (Map.Entry<Integer, KafkaFuture<Map<String, DescribeLogDirsResponse.LogDirInfo>>> entry : logDirsByBrokerId.entrySet()) {
Map<Integer, KafkaFuture<Map<String, LogDirDescription>>> logDirsByBrokerId
= _adminClient.describeLogDirs(aliveBrokers).descriptions();
for (Map.Entry<Integer, KafkaFuture<Map<String, LogDirDescription>>> entry : logDirsByBrokerId.entrySet()) {
onlineLogDirsByBrokerId.put(entry.getKey(), new HashSet<>());
offlineLogDirsByBrokerId.put(entry.getKey(), new HashSet<>());

try {
entry.getValue().get(_config.getLong(LOGDIR_RESPONSE_TIMEOUT_MS_CONFIG), TimeUnit.MILLISECONDS).forEach((key, value) -> {
if (value.error == Errors.NONE) {
if (value.error() == null) {
onlineLogDirsByBrokerId.get(entry.getKey()).add(key);
} else {
offlineLogDirsByBrokerId.get(entry.getKey()).add(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
import org.apache.kafka.clients.admin.ConfigEntry;
import org.apache.kafka.clients.admin.DescribeConfigsResult;
import org.apache.kafka.clients.admin.DescribeLogDirsResult;
import org.apache.kafka.clients.admin.LogDirDescription;
import org.apache.kafka.clients.admin.ReplicaInfo;
import org.apache.kafka.common.KafkaFuture;
import org.apache.kafka.common.TopicPartition;
import org.apache.kafka.common.config.ConfigResource;
import org.apache.kafka.common.protocol.Errors;
import org.apache.kafka.common.requests.DescribeLogDirsResponse;
import org.apache.kafka.common.utils.MockTime;
import org.apache.kafka.common.utils.Time;
import org.apache.kafka.common.config.TopicConfig;
Expand Down Expand Up @@ -533,8 +533,8 @@ private TestContext prepareContext(int numWindowToPreserve, boolean isClusterJBO

// Create mock DescribeLogDirsResult
DescribeLogDirsResult mockDescribeLogDirsResult = EasyMock.mock(DescribeLogDirsResult.class);
EasyMock.expect(mockDescribeLogDirsResult.values())
.andReturn(getDescribeLogDirsResultValues())
EasyMock.expect(mockDescribeLogDirsResult.descriptions())
.andReturn(getDescribeLogDirsResultDescriptions())
.anyTimes();
EasyMock.replay(mockDescribeLogDirsResult);

Expand Down Expand Up @@ -607,28 +607,26 @@ private Map<ConfigResource, KafkaFuture<Config>> getDescribeConfigsResultValues(
return Collections.singletonMap(CLUSTER_CONFIG, clusterConfigFuture);
}

private Map<Integer, KafkaFuture<Map<String, DescribeLogDirsResponse.LogDirInfo>>> getDescribeLogDirsResultValues() {
private Map<Integer, KafkaFuture<Map<String, LogDirDescription>>> getDescribeLogDirsResultDescriptions() {

Map<Integer, KafkaFuture<Map<String, DescribeLogDirsResponse.LogDirInfo>>> futureByBroker = new HashMap<>();
Map<String, DescribeLogDirsResponse.LogDirInfo> logdirInfoBylogdir = new HashMap<>();
Map<TopicPartition, DescribeLogDirsResponse.ReplicaInfo> replicaInfoByPartition = new HashMap<>();
replicaInfoByPartition.put(T0P0, new DescribeLogDirsResponse.ReplicaInfo(0, 0, false));
replicaInfoByPartition.put(T0P1, new DescribeLogDirsResponse.ReplicaInfo(0, 0, false));
replicaInfoByPartition.put(T1P0, new DescribeLogDirsResponse.ReplicaInfo(0, 0, false));
replicaInfoByPartition.put(T1P1, new DescribeLogDirsResponse.ReplicaInfo(0, 0, false));
logdirInfoBylogdir.put("/tmp/kafka-logs", new DescribeLogDirsResponse.LogDirInfo(Errors.NONE, replicaInfoByPartition));
Map<Integer, KafkaFuture<Map<String, LogDirDescription>>> futureByBroker = new HashMap<>();
Map<String, LogDirDescription> logdirInfoBylogdir = new HashMap<>();
Map<TopicPartition, ReplicaInfo> replicaInfoByPartition = new HashMap<>();
replicaInfoByPartition.put(T0P0, new ReplicaInfo(0, 0, false));
replicaInfoByPartition.put(T0P1, new ReplicaInfo(0, 0, false));
replicaInfoByPartition.put(T1P0, new ReplicaInfo(0, 0, false));
replicaInfoByPartition.put(T1P1, new ReplicaInfo(0, 0, false));
logdirInfoBylogdir.put("/tmp/kafka-logs", new LogDirDescription(null, replicaInfoByPartition));
futureByBroker.put(0, completedFuture(logdirInfoBylogdir));

logdirInfoBylogdir = new HashMap<>();
replicaInfoByPartition = new HashMap<>();
replicaInfoByPartition.put(T0P0, new DescribeLogDirsResponse.ReplicaInfo(0, 0, false));
replicaInfoByPartition.put(T0P1, new DescribeLogDirsResponse.ReplicaInfo(0, 0, false));
replicaInfoByPartition.put(T1P0, new DescribeLogDirsResponse.ReplicaInfo(0, 0, false));
logdirInfoBylogdir.put("/tmp/kafka-logs-1", new DescribeLogDirsResponse.LogDirInfo(Errors.NONE, replicaInfoByPartition));
replicaInfoByPartition.put(T0P0, new ReplicaInfo(0, 0, false));
replicaInfoByPartition.put(T0P1, new ReplicaInfo(0, 0, false));
replicaInfoByPartition.put(T1P0, new ReplicaInfo(0, 0, false));
logdirInfoBylogdir.put("/tmp/kafka-logs-1", new LogDirDescription(null, replicaInfoByPartition));
logdirInfoBylogdir.put("/tmp/kafka-logs-2",
new DescribeLogDirsResponse.LogDirInfo(Errors.NONE,
Collections.singletonMap(T1P1,
new DescribeLogDirsResponse.ReplicaInfo(0, 0, false))));
new LogDirDescription(null, Collections.singletonMap(T1P1, new ReplicaInfo(0, 0, false))));
futureByBroker.put(1, completedFuture(logdirInfoBylogdir));
return futureByBroker;
}
Expand Down