jim0987795064 commented on code in PR #22815:
URL: https://github.com/apache/kafka/pull/22815#discussion_r3673801771
##########
server/src/test/java/org/apache/kafka/server/CordonedLogDirsIntegrationTest.java:
##########
@@ -400,6 +401,64 @@ public void testDecommissionBroker() throws
ExecutionException, InterruptedExcep
}
}
+ @ClusterTest(
+ brokers = 2,
+ controllers = 1
+ )
+ public void testDecommissionLogDir() throws ExecutionException,
InterruptedException {
+ // Select the target broker
+ int brokerId = clusterInstance.brokerIds().stream().filter(id ->
!clusterInstance.controllerIds().contains(id)).findFirst().get();
+ try (var admin = clusterInstance.admin()) {
+ List<String> logDirs =
clusterInstance.brokers().get(brokerId).config().logDirs();
+ assertTrue(logDirs.size() > 1, "Test requires more than one log
dir per broker");
+ String logDirToRemove = logDirs.remove(logDirs.size() - 1);
+
+ // Create 10 topics, replicated to every broker so brokerId is
guaranteed to host some
+ // replicas on the log dir we're about to decommission
+ for (int i = 0; i < 10; i++) {
+ admin.createTopics(newTopic("topic" + i)).all().get();
+ }
+ TestUtils.waitForCondition(() ->
admin.listTopics().names().get().size() == 10, 10_000, "Topics were not
created");
+
+ ConfigResource brokerResource = new
ConfigResource(ConfigResource.Type.BROKER, String.valueOf(brokerId));
+
+ // Cordon the log dir we're going to decommission and move any
replicas hosted on it elsewhere
+ setCordonedLogDirs(admin, List.of(logDirToRemove), brokerResource);
+ Set<TopicPartition> partitionsToMove = new HashSet<>();
+ LogDirDescription description =
admin.describeLogDirs(List.of(brokerId)).allDescriptions().get().get(brokerId).get(logDirToRemove);
+ partitionsToMove.addAll(description.replicaInfos().keySet());
+ assertFalse(partitionsToMove.isEmpty());
+ int target = clusterInstance.brokerIds().stream().filter(id -> id
!= brokerId).findFirst().get();
+ movePartitions(admin, partitionsToMove, brokerId,
Optional.of(logDirToRemove), target);
+
+ // Shut down the broker so the log dir can be physically
decommissioned while it's offline
+ clusterInstance.brokers().get(brokerId).shutdown();
+ clusterInstance.brokers().get(brokerId).awaitShutdown();
+
+ // Uncordon the log dir via the controller while the broker is
shut down
+ try (Admin controllerAdmin = clusterInstance.admin(Map.of(),
true)) {
+ controllerAdmin.incrementalAlterConfigs(cordonedDirsConfig("",
brokerResource)).all().get();
+ }
+
+ // Physically decommission the log dir: restart the
+ // broker without it in its static log.dirs config
+ Map<String, Object> propOverrides = Map.of(LOG_DIRS_CONFIG,
String.join(",", logDirs), CORDONED_LOG_DIRS_CONFIG, "");
+ clusterInstance.restartBroker(brokerId, propOverrides);
+ clusterInstance.waitForReadyBrokers();
+
+ // The broker restarted with the reduced set of log dirs, and no
longer reports the removed one
+ assertEquals(logDirs,
clusterInstance.brokers().get(brokerId).config().logDirs());
+ TestUtils.waitForCondition(() ->
+
!admin.describeLogDirs(List.of(brokerId)).allDescriptions().get().get(brokerId).containsKey(logDirToRemove),
+ 10_000, "Broker " + brokerId + " is still reporting the
removed log dir " + logDirToRemove);
Review Comment:
@m1a2st
Fixed, thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]