You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "mimaison (via GitHub)" <gi...@apache.org> on 2026/04/15 18:50:37 UTC

[PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

mimaison opened a new pull request, #22070:
URL: https://github.com/apache/kafka/pull/22070

   
   Following feedback from https://github.com/apache/kafka/pull/21273#pullrequestreview-4101165731


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3118507168


##########
metadata/src/main/java/org/apache/kafka/controller/ClusterControlManager.java:
##########


Review Comment:
   I pushed an update implementing these changes.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3137602094


##########
core/src/main/scala/kafka/server/DynamicBrokerConfig.scala:
##########
@@ -618,10 +617,16 @@ class DynamicLogConfig(logManager: LogManager, directoryEventHandler: DirectoryE
     val newUncordoned = new util.HashSet[String](oldConfig.cordonedLogDirs)
     newUncordoned.removeAll(newConfig.cordonedLogDirs)
     if (!newCordoned.isEmpty) {
-      directoryEventHandler.handleCordoned(newCordoned.stream.map(dir => logManager.directoryId(dir).get).collect(Collectors.toSet()))
+      directoryEventHandler.handleCordoned(newCordoned.stream

Review Comment:
   `logManager.directoryId(dir).get` would NPE when cordoning an offline log dir so we need to guard against that here.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3112204825


##########
metadata/src/main/java/org/apache/kafka/controller/ClusterControlManager.java:
##########


Review Comment:
   Yes I think you identified a real issue. There are several scenarios to consider:
   
   1. Different cordoned log dirs in static properties file and local metadata:
   To get this scenario, start a broker with no cordoned log dirs and dynamically cordon a log dir. Then upon restarting the broker applies all configuration changes in its local metadata (in `DynamicBrokerConfig.readDynamicBrokerConfigsFromSnapshot()`) before sending its registration. I'm not entirely sure if this behavior, configuration update in the snapshot replace static values, is documented.
   
   2. Different cordoned log dirs in local and remote metadata
   While playing with this scenario I encountered a few issues. First there the race condition you highlighted. I believe you are correct that the broker will register, and can even heartbeat, with the cordoned log dirs it found from its local metadata, before catching up with the latest metadata.
   
   One approach could be to only send the cordoned log dirs once the broker has caught up and is unfenced. So we'd remove the cordoned log dirs field from `BrokerRegistrationRequest`, as `BrokerLifecycleManager.initialCatchUpFuture()` can only complete after a heartbeat. We would also only include cordoned log dirs in heartbeats once that future has completed. This should ensure no inconsistent state. How does that sounds?
   
   



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "jsancio (via GitHub)" <gi...@apache.org>.
jsancio commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3148876533


##########
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java:
##########
@@ -349,8 +357,10 @@ private ApiError validateAlterConfig(
                 return DISALLOWED_BROKER_MIN_ISR_TRANSITION_ERROR;
             } else if (isDisallowedClusterMinIsrTransition(configRecord)) {
                 return DISALLOWED_CLUSTER_MIN_ISR_REMOVAL_ERROR;
-            } else if (isCordonedLogDirsDisallowed(configRecord)) {
-                return DISALLOWED_CORDONED_LOG_DIRS_ERROR;
+            } else if (isCordonedLogDirsDisabled(configRecord)) {
+                return DISABLED_CORDONED_LOG_DIRS_ERROR;
+            } else if (isCordonedLogDirsInvalid(configRecord, existingConfigsMap.get(CORDONED_LOG_DIRS_CONFIG), forwarded)) {
+                return INVALID_CORDONED_LOG_DIRS_ERROR;

Review Comment:
   Why do you need the custom validator logic? Ideally, the controller shouldn't have custom config logic and it should rely on the injected config validator. If we add this to LogConfig's or ServerLogConfig's validate values method and make sure that the config validator calls that method, does that resolve this issue?
   
   This is outside the scope of your PR but I think adding log.dirs and cordoned.log.dirs to ServeLogConfig doesn't seem right. In most cases *LogConfig is more like the configuration of the topic partition (log). This is more a configuration of the broker's LogManager. What do you think?



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3149657385


##########
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java:
##########
@@ -422,7 +438,21 @@ boolean isDisallowedBrokerMinIsrTransition(ConfigRecord configRecord) {
         return false;
     }
 
-    boolean isCordonedLogDirsDisallowed(ConfigRecord configRecord) {
+    // Prevent updating cordoned.log.dirs if the request is not forwarded and the new value adds directories not
+    // already cordoned

Review Comment:
   > Instead of explain the "what" and "how" can we document the "why"? E.g. why do you need to check if the RPC was forwarded?
   
   Yes I'll update the comment.
   
   > Do we agree that we are going to revert this change when @chia7712 and company implement proper controller side validation of broker configs?
   
   Yes if we have the `log.dirs` or `log.dir` configuration of the brokers available we should be able to fully validate the configuration.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3156656443


##########
metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java:
##########
@@ -1546,16 +1546,19 @@ void handleDirectoriesCordoned(
             List<ApiMessageAndVersion> records
     ) {
         BrokerRegistration registration = clusterControl.registration(brokerId);
-        List<Uuid> newCordonedDirs = registration.directoryIntersection(cordonedDirs);
-        if (!newCordonedDirs.isEmpty()) {
+        List<Uuid> unknownDirectories = new ArrayList<>(cordonedDirs);
+        unknownDirectories.removeAll(registration.directories());
+        if (!unknownDirectories.isEmpty()) {
+            throw new InvalidRequestException("All cordoned directories must be existing directories. Found unknown directories: " + unknownDirectories);

Review Comment:
   This logic was removed in https://github.com/apache/kafka/pull/22070/commits/f77c398cc2c2642be9a3211ea9c73ebe13cd1dc8



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3162838981


##########
checkstyle/suppressions.xml:
##########
@@ -43,6 +43,9 @@
     <suppress checks="ClassDataAbstractionCoupling|ClassFanOutComplexity" files="SharePartitionManagerTest"/>
     <suppress checks="CyclomaticComplexity" files="SharePartition.java"/>
 
+    <!-- server -->
+    <suppress checks="CyclomaticComplexity" files="BrokerLifecycleManager.java"/>

Review Comment:
   Done



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3162717524


##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -681,6 +647,12 @@ public void run() {
                                 logger.info("The broker has caught up. Transitioning from STARTING to RECOVERY.");
                                 state = BrokerState.RECOVERY;
                                 initialCatchUpFuture.complete(null);
+                                // Update the known cordoned log dirs so the next heartbeat includes them
+                                config.cordonedLogDirs().forEach(logDir -> {
+                                    if (logDirs.containsKey(logDir)) {
+                                        cordonedLogDirs.add(logDirs.get(logDir));

Review Comment:
   I think I get your point. We're calling `add()` incidentally here because of the stream syntax, while we're effectively setting `cordonedLogDirs`.
   This line means `cordonedLogDirs = <VALUE>` not `cordonedLogDirs.add(<VALUE>)` but I can understand the confusion. I was considering setting `cordonedLogDirs` to `null` initially and have an proper assignment here to make things clearer.
   
   Would it help to refactor this logic to have a clear assignment?
   Something like:
   ```
   cordonedLogDirs = config.cordonedLogDirs().stream()
       .flatMap(logDir -> Optional.ofNullable(logDirs.get(logDir)).stream())
       .collect(Collectors.toSet());
   ```
   
   Since we only send the cordoned log dirs as part of a heartbeat once fully caught up, I'm uneasy with tracking both the static and dynamic values. In the end we only care about the current "computed" or "aggregated" value so having collections for both is confusing.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3112204825


##########
metadata/src/main/java/org/apache/kafka/controller/ClusterControlManager.java:
##########


Review Comment:
   Yes I think you identified a real issue. There are several scenarios to consider:
   
   1. Different cordoned log dirs in static properties file and local metadata:
   To get this scenario, start a broker with no cordoned log dirs and dynamically cordon a log dir. Then upon restarting the broker applies all configuration changes in its local metadata (in `DynamicBrokerConfig.readDynamicBrokerConfigsFromSnapshot()`) before sending its registration. I'm not entirely sure if this behavior, configuration update in the snapshot replace static values, is documented.
   
   2. Different cordoned log dirs in local and remote metadata
   While playing with this scenario I encountered a few issues. First there the race condition you highlighted. I believe you are correct that the broker will register, and can even heartbeat, with the cordoned log dirs it found from its local metadata, before catching up with the latest metadata.
   
   One approach could be to only send the cordoned log dirs once the broker has caught up and is unfenced. So we'd remove the cordoned log dirs field from `BrokerRegistrationRequest`, as `BrokerLifecycleManager.initialCatchUpFuture()` can only complete after a heartbeat. We would also only include cordoned log dirs in heartbeats once that future has completed. This should ensure no inconsistent state.
   
   



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3113214172


##########
metadata/src/main/java/org/apache/kafka/metadata/BrokerRegistration.java:
##########


Review Comment:
   We are currently preparing a KIP for this, but I'd like to share a few core concepts here to address the concerns:
   
   1. The static configs included in the broker registration will be specifically used for verification. To avoid bloating the payload, we only plan to send the configs that require controller-side validation (e.g., configs that have a Validator defined).
   2. These static configs will indeed be persisted in the metadata partition to ensure they survive a controller failover and remain visible to the next leader.
   
   We will detail this in the upcoming KIP.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3162717524


##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -681,6 +647,12 @@ public void run() {
                                 logger.info("The broker has caught up. Transitioning from STARTING to RECOVERY.");
                                 state = BrokerState.RECOVERY;
                                 initialCatchUpFuture.complete(null);
+                                // Update the known cordoned log dirs so the next heartbeat includes them
+                                config.cordonedLogDirs().forEach(logDir -> {
+                                    if (logDirs.containsKey(logDir)) {
+                                        cordonedLogDirs.add(logDirs.get(logDir));

Review Comment:
   I think I get your point. We're calling `add()` incidentally here because of the stream syntax, while we're effectively setting `cordonedLogDirs`.
   This line means `cordonedLogDirs = <VALUE>` not `cordonedLogDirs.add(<VALUE>)` but I can understand the confusion. I was considering setting `cordonedLogDirs` to `null` initially and have an proper assignment here to make things clearer.
   
   Why it help to refactor this logic to have a clear assignment?
   
   Since we only send the cordoned log dirs as part of a heartbeat once fully caught up, I'm uneasy with tracking both the static and dynamic values. In the end we only care about the current "computed" or "aggregated" value so having collections for both is confusing.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3149679767


##########
metadata/src/main/java/org/apache/kafka/metadata/BrokerRegistration.java:
##########
@@ -331,10 +340,12 @@ public ApiMessageAndVersion toRecord(ImageWriterOptions options) {
             options.handleLoss("the online log directories of one or more brokers");
         }
 
-        if (cordonedDirectories.isEmpty() || options.metadataVersion().isCordonedLogDirsSupported()) {
-            registrationRecord.setCordonedLogDirs(cordonedDirectories);
-        } else {
-            options.handleLoss("the cordoned log directories of one or more brokers");
+        if (cordonedDirectories != null) {
+            if (cordonedDirectories.isEmpty() || options.metadataVersion().isCordonedLogDirsSupported()) {
+                registrationRecord.setCordonedLogDirs(cordonedDirectories);

Review Comment:
   Good catch, yes we need to remove the `cordonedDirectories.isEmpty()` here



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on PR #22070:
URL: https://github.com/apache/kafka/pull/22070#issuecomment-4350394949

   @chia7712 Do you want to take another look?


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3156546257


##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -681,6 +674,8 @@ public void run() {
                                 logger.info("The broker has caught up. Transitioning from STARTING to RECOVERY.");
                                 state = BrokerState.RECOVERY;
                                 initialCatchUpFuture.complete(null);
+                                // Update the known cordoned log dirs so the next heartbeat includes them
+                                config.cordonedLogDirs().forEach(logDir -> cordonedLogDirs.add(logDirs.get(logDir)));

Review Comment:
   So I confirm that `config.cordonedLogDirs()` returns the computed value. If the static config has `cordoned.log.dirs=/tmp/kraft-combined-logs1` but we dynamically set it to `/tmp/kraft-combined-logs2`, `config.cordonedLogDirs()` returns `/tmp/kraft-combined-logs2`.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on PR #22070:
URL: https://github.com/apache/kafka/pull/22070#issuecomment-4289626309

   Thanks for all the feedback I pushed a major update that should address all identified issues.
   
   1. Cordoned log directories are not included in `BrokerRegistrationRequest`. So I reverted this API to v4. Brokers only send cordoned log directories via `BrokerHeartbeatRequest` once they have caught up with the metadata log. Earlier heartbeats have cordoned log dirs set to null. Once caught up, cordoned log directories are passed in each heartbeat and the corresponding `BrokerRegistration` is updated as necessary via `BrokerRegistrationChangeRecord` where null means no changes. This should resolve the race condition highlighted in https://github.com/apache/kafka/pull/22070#discussion_r3103057848
   
   2. I've added validation when updating `cordoned.log.dirs`. Controllers don't know the directory paths so if a request is not forwarded (so it has already been validated by the right broker), controllers only allow removing entries from or clearing `cordoned.log.dirs`. This should resolve the validation and consistency issues described in https://github.com/apache/kafka/pull/22070#discussion_r3112243759


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3112516514


##########
metadata/src/main/java/org/apache/kafka/metadata/BrokerRegistration.java:
##########


Review Comment:
   KAFKA-20486 will enhance the broker registration to carry static configs, so the controller will be able to perform strict validation after KAFKA-20486 is resolved



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on PR #22070:
URL: https://github.com/apache/kafka/pull/22070#issuecomment-4282794587

   > It seems like a safeguard in the tool is preventing us from deleting a non-existent config. I think this protection can be removed, as deleting a non-existent config should be an idempotent operation.
   > 
   > @mimaison WDYT? We can file a patch for it quickly
   
   If you can look into this in parallel that would be really helpful. I'm still trying to figure out the other 2 issues ([0](https://github.com/apache/kafka/pull/22070#discussion_r3112204825), [1](https://github.com/apache/kafka/pull/22070#discussion_r3112243759)). 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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #22070:
URL: https://github.com/apache/kafka/pull/22070#issuecomment-4352742672

   > @chia7712 Do you want to take another look?
   
   Currently on the road. I'll take a look once I get home in 6 hours


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #22070:
URL: https://github.com/apache/kafka/pull/22070#issuecomment-4282766703

   > I found another issue with the log directory decommission process. With kafka-configs.sh, I'm unable to update cordoned.log.dirs for a broker while it's down, even by connecting to a controller.
   I can run Admin.incrementalAlterConfigs() fine, but kafka-configs.sh times out as it gets into a loop trying to describe the cluster.
   
   It seems like a safeguard in the tool is preventing us from deleting a non-existent config. I think this protection can be removed, as deleting a non-existent config should be an idempotent operation.
   
   @mimaison WDYT? We can file a patch for it quickly
   


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on PR #22070:
URL: https://github.com/apache/kafka/pull/22070#issuecomment-4282683205

   I found another issue with the log directory decommission process. With `kafka-configs.sh`, I'm unable to update `cordoned.log.dirs` for a broker while it's down, even by connecting to a controller.
   
   I can run `Admin.incrementalAlterConfigs()` fine, but `kafka-configs.sh` times out as it gets into a loop trying to describe the cluster.


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3137605035


##########
metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java:
##########
@@ -1546,11 +1547,6 @@ void handleDirectoriesCordoned(
             List<ApiMessageAndVersion> records
     ) {
         BrokerRegistration registration = clusterControl.registration(brokerId);
-        List<Uuid> unknownDirectories = new ArrayList<>(cordonedDirs);
-        unknownDirectories.removeAll(registration.directories());
-        if (!unknownDirectories.isEmpty()) {
-            throw new InvalidRequestException("All cordoned directories must be existing directories. Found unknown directories: " + unknownDirectories);
-        }

Review Comment:
   I decided to remove this validation as explained in https://github.com/apache/kafka/pull/22070#discussion_r3137220812



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3163251579


##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -681,6 +647,12 @@ public void run() {
                                 logger.info("The broker has caught up. Transitioning from STARTING to RECOVERY.");
                                 state = BrokerState.RECOVERY;
                                 initialCatchUpFuture.complete(null);
+                                // Update the known cordoned log dirs so the next heartbeat includes them
+                                config.cordonedLogDirs().forEach(logDir -> {
+                                    if (logDirs.containsKey(logDir)) {
+                                        cordonedLogDirs.add(logDirs.get(logDir));

Review Comment:
   I pushed an update with that alternative implementation.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3156554068


##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -442,9 +438,7 @@ private class CordonedDirEvent implements EventQueue.Event {
 
         @Override
         public void run() {
-            for (Uuid dir : dirs) {
-                cordonedLogDirs.put(dir, true);
-            }
+            cordonedLogDirs.addAll(dirs);

Review Comment:
   Yes that's a nice way to simplify the logic. That way `CordonedDirEvent` just contains the new value. I'll implement that. Thanks for the suggestion



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "junrao (via GitHub)" <gi...@apache.org>.
junrao commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3183502848


##########
clients/src/main/resources/common/message/BrokerRegistrationRequest.json:
##########
@@ -61,8 +60,6 @@
     { "name": "LogDirs", "type":  "[]uuid", "versions":  "2+",
       "about": "Log directories configured in this broker which are available.", "ignorable": true },
     { "name": "PreviousBrokerEpoch", "type": "int64", "versions": "3+", "default": "-1", "ignorable": true,
-      "about": "The epoch before a clean shutdown." },
-    { "name": "CordonedLogDirs", "type":  "[]uuid", "versions":  "5+", "taggedVersions": "5+",

Review Comment:
   @mimaison : Since this changes the public interface in the original KIP-1066, could you update the KIP wiki and send an email to the KIP mailing thread that summarizes the changes?



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on PR #22070:
URL: https://github.com/apache/kafka/pull/22070#issuecomment-4372454801

   Backported to 4.3: https://github.com/apache/kafka/commit/cf9f8ad376a9088d4d9bb9be217d28554e1be5b6


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "jsancio (via GitHub)" <gi...@apache.org>.
jsancio commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3113022262


##########
metadata/src/main/java/org/apache/kafka/controller/ClusterControlManager.java:
##########


Review Comment:
   > Then upon restarting the broker applies all configuration changes in its local metadata (in DynamicBrokerConfig.readDynamicBrokerConfigsFromSnapshot()) before sending its registration. I'm not entirely sure if this behavior, configuration update in the snapshot replace static values, is documented.
   
   If I remember correctly, this was done specifically to address an issue where the user might dynamically changed the broker configuration needed to connect to the controller(s). In KRaft the HWM is not persisted, to establish the HWM the replicas need to elect a leader and discover the HWM from the leader. This all requires a working network layer.
   
   > as BrokerLifecycleManager.initialCatchUpFuture() can only complete after a heartbeat. We would also only include cordoned log dirs in heartbeats once that future has completed. This should ensure no inconsistent state. How does that sounds?
   
   Seems reasonable to me. Basically, don't update the cordon log dir until we have the latest config values. Does that mean that we need to change the semantic of cordon log dir in the registration (BrokerHeartbeat RPC and BrokerRegistrationRecord? You have identified the following high-level states:
   1. The cordoned log dir is unknown. This could be represent with `null` in the cluster metadata persisted state
   2. There are no cordoned log dirs. This can be represented with the empty array/list.
   3. There are cordoned log dirs. This can be represented by the non-empty array/list.
   
   I think it is fair to say that the BrokerRegistrationChangeRecord doesn't need to represent the "unknown" state so we can continue to use `null` in the change record to mean no change. In other words, at the cluster metadata level if the cordoned log dirs was ever known it cannot transition back to unknown. It can only be unknown the first time a broker registers. What do you think?



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "jsancio (via GitHub)" <gi...@apache.org>.
jsancio commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3119969159


##########
core/src/test/scala/unit/kafka/server/ReplicationQuotasTest.scala:
##########
@@ -120,7 +120,7 @@ class ReplicationQuotasTest extends QuorumTestHarness {
           Map(new ConfigResource(BROKER, String.valueOf(brokerId)) -> Map(
             QuotaConfig.LEADER_REPLICATION_THROTTLED_RATE_CONFIG -> entry,
             QuotaConfig.FOLLOWER_REPLICATION_THROTTLED_RATE_CONFIG -> entry).asJava).asJava,
-          false
+          false, false

Review Comment:
   Let's keep the formatting consistent in this file. You can add a newline. We can also add a comment explaining the literal:
   ```scala
      false, // validateOnly
      false // forwarded
   )
   ```



##########
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java:
##########
@@ -422,7 +438,21 @@ boolean isDisallowedBrokerMinIsrTransition(ConfigRecord configRecord) {
         return false;
     }
 
-    boolean isCordonedLogDirsDisallowed(ConfigRecord configRecord) {
+    // Prevent updating cordoned.log.dirs if the request is not forwarded and the new value adds directories not
+    // already cordoned

Review Comment:
   Instead of explain the "what" and "how" can we document the "why"? E.g. why do you need to check if the RPC was forwarded?
   
   Do we agree that we are going to revert this change when @chia7712 and company implement proper controller side validation of broker configs?



##########
metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java:
##########
@@ -1696,8 +1699,7 @@ ControllerResult<BrokerHeartbeatReply> processBrokerHeartbeat(
         if (featureControl.metadataVersionOrThrow().isDirectoryAssignmentSupported()) {
             handleDirectoriesOffline(brokerId, brokerEpoch, request.offlineLogDirs(), records);
         }
-        if (featureControl.metadataVersionOrThrow().isCordonedLogDirsSupported()) {
-            clusterControl.updateCordonedLogDirs(brokerId, request.cordonedLogDirs());
+        if (featureControl.metadataVersionOrThrow().isCordonedLogDirsSupported() && request.cordonedLogDirs() != null) {

Review Comment:
   Minor but can we add the != null check to handleDirectoriesCordoned? Let's also add a "why" comment for this check.



##########
metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java:
##########
@@ -1546,16 +1546,19 @@ void handleDirectoriesCordoned(
             List<ApiMessageAndVersion> records
     ) {
         BrokerRegistration registration = clusterControl.registration(brokerId);
-        List<Uuid> newCordonedDirs = registration.directoryIntersection(cordonedDirs);
-        if (!newCordonedDirs.isEmpty()) {
+        List<Uuid> unknownDirectories = new ArrayList<>(cordonedDirs);
+        unknownDirectories.removeAll(registration.directories());
+        if (!unknownDirectories.isEmpty()) {
+            throw new InvalidRequestException("All cordoned directories must be existing directories. Found unknown directories: " + unknownDirectories);

Review Comment:
   @mimaison please double check but I don't think throwing the exception here fails the RPC. When I looked, this thread stack doesn't catch this or ApiException. An exception here will cause the controller to failover.



##########
metadata/src/main/java/org/apache/kafka/metadata/BrokerRegistration.java:
##########
@@ -331,10 +340,12 @@ public ApiMessageAndVersion toRecord(ImageWriterOptions options) {
             options.handleLoss("the online log directories of one or more brokers");
         }
 
-        if (cordonedDirectories.isEmpty() || options.metadataVersion().isCordonedLogDirsSupported()) {
-            registrationRecord.setCordonedLogDirs(cordonedDirectories);
-        } else {
-            options.handleLoss("the cordoned log directories of one or more brokers");
+        if (cordonedDirectories != null) {
+            if (cordonedDirectories.isEmpty() || options.metadataVersion().isCordonedLogDirsSupported()) {
+                registrationRecord.setCordonedLogDirs(cordonedDirectories);

Review Comment:
   You changed default value to `null` for the broker registration record. This mean that empty list is not allowed if the metadata version doesn't support this feature/field. This code should be relative agnostic of the higher-level semantics. How about:
   ```java
   if (cordonedDirectories == null || options.metadataVersion().isCordonedLogDirsSupported()) {
       registrationRecord.setCordonedLogDirs(cordonedDirectories);
   } else {
       options.handleLoss("the cordoned log directories of one or more brokers");
   }
   ```
   
   Are we missing a test since the CI didn't catch this issue?



##########
metadata/src/main/java/org/apache/kafka/metadata/BrokerRegistration.java:
##########
@@ -308,6 +310,13 @@ public List<Uuid> directoryDifference(List<Uuid> otherDirectories) {
         return results;
     }
 
+    public boolean cordonedDirChanged(List<Uuid> otherDirectories) {
+        if (cordonedDirectories == null) return true;

Review Comment:
   Let's add a comment explaining why this check is necessary.



##########
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java:
##########
@@ -464,7 +495,7 @@ ControllerResult<Map<ConfigResource, ApiError>> legacyAlterConfigs(
                 resourceEntry.getValue(),
                 newlyCreatedResource,
                 outputRecords,
-                outputResults);
+                outputResults, forwarded);

Review Comment:
   Let's fix this formatting to match the pattern used in the rest of the file. E.g.:
   ```java
       outputResult,
       forwarded
   );



##########
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java:
##########
@@ -453,7 +483,8 @@ boolean isDisallowedClusterMinIsrTransition(ConfigRecord configRecord) {
      */
     ControllerResult<Map<ConfigResource, ApiError>> legacyAlterConfigs(
         Map<ConfigResource, Map<String, String>> newConfigs,
-        boolean newlyCreatedResource
+        boolean newlyCreatedResource,
+        boolean forwarded

Review Comment:
   Let's update the javadoc to include this new parameter. Can you also document the existing parameter: newlyCreatedResource?



##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -442,9 +438,7 @@ private class CordonedDirEvent implements EventQueue.Event {
 
         @Override
         public void run() {
-            for (Uuid dir : dirs) {
-                cordonedLogDirs.put(dir, true);
-            }
+            cordonedLogDirs.addAll(dirs);

Review Comment:
   Since there are a few actors (threads) involved here wouldn't it just be easier to do `cordonedLogDir = dirs` and remove the `UncordonedDirEvent`? This would simplify the logic in DynamicBrokerConfig#reconfigure, no?



##########
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java:
##########
@@ -349,8 +357,10 @@ private ApiError validateAlterConfig(
                 return DISALLOWED_BROKER_MIN_ISR_TRANSITION_ERROR;
             } else if (isDisallowedClusterMinIsrTransition(configRecord)) {
                 return DISALLOWED_CLUSTER_MIN_ISR_REMOVAL_ERROR;
-            } else if (isCordonedLogDirsDisallowed(configRecord)) {
-                return DISALLOWED_CORDONED_LOG_DIRS_ERROR;
+            } else if (isCordonedLogDirsDisabled(configRecord)) {
+                return DISABLED_CORDONED_LOG_DIRS_ERROR;
+            } else if (isCordonedLogDirsInvalid(configRecord, existingConfigsMap.get(CORDONED_LOG_DIRS_CONFIG), forwarded)) {
+                return INVALID_CORDONED_LOG_DIRS_ERROR;

Review Comment:
   Why do you need the custom validator logic? Ideally, the controller should have custom config logic and it should rely on the injected config validator. If we add this to LogConfig's or ServerLogConfig's validate values method and make sure that the config validator calls that method, does that resolve this issue?
   
   This is outside the scope of your PR but I think adding log.dirs and cordoned.log.dirs to ServeLogConfig doesn't seem right. In most cases *LogConfig is more like the configuration of the topic partition (log). This is more a configuration of the broker's LogManager. What do you think?



##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -681,6 +674,8 @@ public void run() {
                                 logger.info("The broker has caught up. Transitioning from STARTING to RECOVERY.");
                                 state = BrokerState.RECOVERY;
                                 initialCatchUpFuture.complete(null);
+                                // Update the known cordoned log dirs so the next heartbeat includes them
+                                config.cordonedLogDirs().forEach(logDir -> cordonedLogDirs.add(logDirs.get(logDir)));

Review Comment:
   @mimaison I am confused about the the semantic of this set. Does this mean that the cordoned log dir is the union of the static cordoned log dirs and the dynamic cordoned log dir? Is that the intention?
   
   For example, if the static configuration is (X, Y) and later the user set the dynamic configuration to (Z). Shouldn't the cordoned log dir would just be (Z) but I think with this implementation it would be (X, Y, Z).
   
   If you agree that this is not correct, are we missing a test that catches these cases?
   
   Also, do we have a race between this event and the "dynamic configuration event" (CordonedDirEvent)? I think the easiest implementation is to track the static config separate from the dynamic config:
   ```java
   private var staticCordonedLogDir = Optional.empty();
   private var dynamicCordonedLogDir = Optional.empty();
   ```
   
   When sending the heartbeat the broker lifecycle manager can:
   ```java
   dynamicCordonedLogDir.orElse(staticCordonedLogDir.orElse(null))
   ```



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "jsancio (via GitHub)" <gi...@apache.org>.
jsancio commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3102810125


##########
metadata/src/main/java/org/apache/kafka/metadata/BrokerRegistration.java:
##########


Review Comment:
   Should the controller validate that cordonedDirectory is a subset of directories? Ideally, the controller will fail the registration and heartbeat request if this invariant is violated. What do you think?
   
   Does the broker perform a similar validation when it validates the broker config? How about during dynamic configuration does the broker validate that cordoned is a subset of directories? Looks like the answer is yes but thought I still ask.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on PR #22070:
URL: https://github.com/apache/kafka/pull/22070#issuecomment-4338837840

   Thanks @jsancio for another insightful review. I've responded to all your comments and pushed an update.


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3156494546


##########
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java:
##########
@@ -349,8 +357,10 @@ private ApiError validateAlterConfig(
                 return DISALLOWED_BROKER_MIN_ISR_TRANSITION_ERROR;
             } else if (isDisallowedClusterMinIsrTransition(configRecord)) {
                 return DISALLOWED_CLUSTER_MIN_ISR_REMOVAL_ERROR;
-            } else if (isCordonedLogDirsDisallowed(configRecord)) {
-                return DISALLOWED_CORDONED_LOG_DIRS_ERROR;
+            } else if (isCordonedLogDirsDisabled(configRecord)) {
+                return DISABLED_CORDONED_LOG_DIRS_ERROR;
+            } else if (isCordonedLogDirsInvalid(configRecord, existingConfigsMap.get(CORDONED_LOG_DIRS_CONFIG), forwarded)) {
+                return INVALID_CORDONED_LOG_DIRS_ERROR;

Review Comment:
   Actually we also need the `forwarded` flag which we currently don't have in `ConfigurationValidator`. I'm wondering if we could keep the logic where it is for now and follow up with a refactor post 4.3.0.
   
   Regarding your other point about where this config should be defined, I thought put it next to `log.dirs`/`log.dir` was the most natural place.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3156637247


##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -681,6 +674,8 @@ public void run() {
                                 logger.info("The broker has caught up. Transitioning from STARTING to RECOVERY.");
                                 state = BrokerState.RECOVERY;
                                 initialCatchUpFuture.complete(null);
+                                // Update the known cordoned log dirs so the next heartbeat includes them
+                                config.cordonedLogDirs().forEach(logDir -> cordonedLogDirs.add(logDirs.get(logDir)));

Review Comment:
   Regarding the race scenario you mention, do you mean:
   At startup, the broker will try to send a heartbeat with the current cordoned log dirs once it's fully caught up with the metadata. If an alter config request to update the cordoned log dirs was processed before the first heartbeat with the cordoned log dirs set, the heartbeat could effectively overwrite the alteration from the request.
   
   Did I understand correctly?
   
   If so I'm not sure this can happen. In `BrokerServer` we wait for `initialUnfenceFuture` to complete before we enable request processing. The unfence event happens once `RECOVERY` is complete which should only happen after the heartbeat that contains the initial cordoned log dirs completes.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "jsancio (via GitHub)" <gi...@apache.org>.
jsancio commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3103057848


##########
metadata/src/main/java/org/apache/kafka/controller/ClusterControlManager.java:
##########


Review Comment:
   I think we have a race with dynamic cordoned directory. Not sure if we have a test for this. Let's assume that log dirs in broker.properties is (X, Y, Z) and that cordoned log dirs in broker.properties is (X). Let's also assume that the dynamic cordon directory was set to (X, Y). This means that the broker registration has the log dir as (X, Y, Z) and the cordoned log dir as (X, Y).
   
   Looking at the broker startup code it looks like the broker will send log dirs (X, Y, Z) and cordoned log dir (X). This will override the metadata's cordon log dir to (X). Now the cordon log dir is (X) and not (X, Y).
   
   While replaying the cluster metadata dynamic configuration it will discover that the cordoned log dir is (X, Y). The next broker heartbeat will set the cordoned log dir to (X, Y). In short there seems to be a race because broker registration and broker heartbeat, and the broker replaying the dynamic broker config. Does this match your understanding?
   
   Take a look at this [set of instructions](https://github.com/mimaison/kafka/blob/ca435e568ed03c427dac46933066bc26f07bfe56/core/src/main/scala/kafka/server/BrokerServer.scala#L550-L575). 
   



##########
metadata/src/main/java/org/apache/kafka/metadata/BrokerRegistration.java:
##########


Review Comment:
   Should the controller validate that cordonedDirectory is a subset of directories? Ideally, the controller will fail the registration and heartbeat request if this invariant is violated. What do you think?
   
   Does the broker perform a similar validation when it validates the broker config? How about during dynamic configuration does the broker validate that cordoned is a subset of directories?



##########
metadata/src/main/resources/common/metadata/BrokerRegistrationChangeRecord.json:
##########
@@ -33,7 +33,8 @@
      "about": "0 if no change, 1 if the broker is in controlled shutdown." },
    { "name": "LogDirs", "type":  "[]uuid", "versions":  "2+", "taggedVersions": "2+", "tag": 2,
      "about": "Log directories configured in this broker which are available." },
-   { "name": "CordonedLogDirs", "type":  "[]uuid", "versions":  "3+", "taggedVersions": "3+", "tag": "3",
-     "about": "Log directories that are cordoned." }
+   { "name": "CordonedLogDirs", "type":  "[]uuid", "versions":  "3+", "taggedVersions": "3+", "tag": 3,
+     "nullableVersions": "3+", "default": "null",
+     "about": "Log directories that are cordoned or null if no change." }

Review Comment:
   Thanks for updating the documentation. The new schema looks good to me.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3136625408


##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -681,6 +674,8 @@ public void run() {
                                 logger.info("The broker has caught up. Transitioning from STARTING to RECOVERY.");
                                 state = BrokerState.RECOVERY;
                                 initialCatchUpFuture.complete(null);
+                                // Update the known cordoned log dirs so the next heartbeat includes them
+                                config.cordonedLogDirs().forEach(logDir -> cordonedLogDirs.add(logDirs.get(logDir)));

Review Comment:
   Yes we should guard against `null` here. If a log directory can't be loaded we don't know its id. I think we can just ignore them in the cordon logic as if a directory is offline no replicas will be placed on it anyway.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3187645156


##########
clients/src/main/resources/common/message/BrokerRegistrationRequest.json:
##########
@@ -61,8 +60,6 @@
     { "name": "LogDirs", "type":  "[]uuid", "versions":  "2+",
       "about": "Log directories configured in this broker which are available.", "ignorable": true },
     { "name": "PreviousBrokerEpoch", "type": "int64", "versions": "3+", "default": "-1", "ignorable": true,
-      "about": "The epoch before a clean shutdown." },
-    { "name": "CordonedLogDirs", "type":  "[]uuid", "versions":  "5+", "taggedVersions": "5+",

Review Comment:
   Yes I have updated the KIP [0] and sent an update to the dev list [1]
   
   0: https://cwiki.apache.org/confluence/x/Lg_TEg
   1: https://lists.apache.org/thread/6lz5pkxmpvpqf7jt5v9ns196zhv9zp5x



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3118491290


##########
metadata/src/main/java/org/apache/kafka/metadata/BrokerRegistration.java:
##########
@@ -197,6 +198,11 @@ private BrokerRegistration(
         directories.sort(Uuid::compareTo);
         this.directories = Collections.unmodifiableList(directories);
         this.cordonedDirectories = Collections.unmodifiableList(cordonedDirectories);
+        List<Uuid> unknownDirectories = new ArrayList<>(cordonedDirectories);
+        unknownDirectories.removeAll(directories);
+        if (!unknownDirectories.isEmpty()) {
+            throw new IllegalArgumentException("All cordoned directories must be existing directories. Found unknown directories: " + unknownDirectories);

Review Comment:
   I moved that logic to `ReplicationControlManager.handleDirectoriesCordoned()` which should fail the request instead.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3132313742


##########
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java:
##########
@@ -259,7 +264,8 @@ ControllerResult<ApiError> incrementalAlterConfig(
         ApiError apiError = incrementalAlterConfigResource(configResource,
             keyToOps,
             newlyCreatedResource,
-            outputRecords);
+            outputRecords,
+            false);

Review Comment:
   I understand that this flag doesn't trigger cordon validation due to the topic type. However, passing false is a bit confusing since topic creation could be forwarded here.



##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -681,6 +674,8 @@ public void run() {
                                 logger.info("The broker has caught up. Transitioning from STARTING to RECOVERY.");
                                 state = BrokerState.RECOVERY;
                                 initialCatchUpFuture.complete(null);
+                                // Update the known cordoned log dirs so the next heartbeat includes them
+                                config.cordonedLogDirs().forEach(logDir -> cordonedLogDirs.add(logDirs.get(logDir)));

Review Comment:
   IIRC, `logDirs` only contains live directories. Would this cause an NPE if `cordonedLogDirs` includes an offline path?



##########
metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java:
##########
@@ -1546,16 +1546,19 @@ void handleDirectoriesCordoned(
             List<ApiMessageAndVersion> records
     ) {
         BrokerRegistration registration = clusterControl.registration(brokerId);
-        List<Uuid> newCordonedDirs = registration.directoryIntersection(cordonedDirs);
-        if (!newCordonedDirs.isEmpty()) {
+        List<Uuid> unknownDirectories = new ArrayList<>(cordonedDirs);
+        unknownDirectories.removeAll(registration.directories());
+        if (!unknownDirectories.isEmpty()) {
+            throw new InvalidRequestException("All cordoned directories must be existing directories. Found unknown directories: " + unknownDirectories);

Review Comment:
   Out of curiosity, is it legal to cordon an offline directory, even if that directory is still listed in the log.dirs property?



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3162717524


##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -681,6 +647,12 @@ public void run() {
                                 logger.info("The broker has caught up. Transitioning from STARTING to RECOVERY.");
                                 state = BrokerState.RECOVERY;
                                 initialCatchUpFuture.complete(null);
+                                // Update the known cordoned log dirs so the next heartbeat includes them
+                                config.cordonedLogDirs().forEach(logDir -> {
+                                    if (logDirs.containsKey(logDir)) {
+                                        cordonedLogDirs.add(logDirs.get(logDir));

Review Comment:
   I think I get your point. We're calling `add()` incidentally here because of the stream syntax, while we're effectively setting `cordonedLogDirs`.
   This line means `cordonedLogDirs = <VALUE>` not `cordonedLogDirs.add(<VALUE>)` but I can understand the confusion. I was considering setting `cordonedLogDirs` to `null` initially and have an proper assignment here to make things clearer.
   
   Since we only send the cordoned log dirs as part of a heartbeat once fully caught up, I'm uneasy with tracking both the static and dynamic values. In the end we only care about the current "computed" or "aggregated" value so having collections for both is confusing.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison merged PR #22070:
URL: https://github.com/apache/kafka/pull/22070


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "jsancio (via GitHub)" <gi...@apache.org>.
jsancio commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3112845291


##########
metadata/src/main/java/org/apache/kafka/metadata/BrokerRegistration.java:
##########


Review Comment:
   @chia7712 I know that there was another issue/PR where we determined that the broker needs to do dynamic config validation when it applies specifically to the broker.
   
   Are you planning the send all of the configs in "broker.properties" to the controller and the controller will persist this in the cluster metadata partition? Do you have a KIP for this?
   
   I think @junrao was reviewing this PR.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3111440058


##########
metadata/src/main/java/org/apache/kafka/metadata/BrokerRegistration.java:
##########


Review Comment:
   Yes good call. I've added validation here to ensure cordoned log dirs are existing log dirs.
   
   We check the cordoned log dirs are a subset of log dirs at startup and when the configuration is updated dynamically. I add a new test in `CordonedLogDirsIntegrationTest` for that second case.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3112369688


##########
metadata/src/main/java/org/apache/kafka/metadata/BrokerRegistration.java:
##########


Review Comment:
   Following up on the issue mentioned above. If we update the cordoned log dirs with a bad value via the controllers it does not fail the broker:
   ```
   java.lang.IllegalArgumentException: requirement failed: All entries in cordoned.log.dirs must be present in cordoned.log.dirs or log.dir. Missing entries : /dgsdhf
   	at scala.Predef$.require(Predef.scala:337)
   	at kafka.server.KafkaConfig.validateCordonedLogDirs(KafkaConfig.scala:402)
   	at kafka.server.KafkaConfig.validateValues(KafkaConfig.scala:537)
   	at kafka.server.KafkaConfig.<init>(KafkaConfig.scala:406)
   	at kafka.server.KafkaConfig.<init>(KafkaConfig.scala:109)
   	at kafka.server.DynamicBrokerConfig.processReconfiguration(DynamicBrokerConfig.scala:447)
   	at kafka.server.DynamicBrokerConfig.updateCurrentConfig(DynamicBrokerConfig.scala:436)
   	at kafka.server.DynamicBrokerConfig.$anonfun$updateBrokerConfig$1(DynamicBrokerConfig.scala:281)
   	at org.apache.kafka.server.util.LockUtils.inLock(LockUtils.java:96)
   	at org.apache.kafka.server.util.LockUtils.inWriteLock(LockUtils.java:115)
   	at kafka.server.DynamicBrokerConfig.updateBrokerConfig(DynamicBrokerConfig.scala:276)
   	at kafka.server.BrokerConfigHandler.processConfigChanges(ConfigHandler.scala:153)
   	at kafka.server.metadata.DynamicConfigPublisher.$anonfun$onMetadataUpdate$5(DynamicConfigPublisher.scala:92)
   	at scala.Option.foreach(Option.scala:437)
   	at kafka.server.metadata.DynamicConfigPublisher.$anonfun$onMetadataUpdate$2(DynamicConfigPublisher.scala:74)
   	at java.base/java.util.HashMap$KeySet.forEach(HashMap.java:1008)
   	at kafka.server.metadata.DynamicConfigPublisher.$anonfun$onMetadataUpdate$1(DynamicConfigPublisher.scala:57)
   	at kafka.server.metadata.DynamicConfigPublisher.$anonfun$onMetadataUpdate$1$adapted(DynamicConfigPublisher.scala:56)
   	at scala.Option.foreach(Option.scala:437)
   	at kafka.server.metadata.DynamicConfigPublisher.onMetadataUpdate(DynamicConfigPublisher.scala:56)
   	at kafka.server.metadata.BrokerMetadataPublisher.onMetadataUpdate(BrokerMetadataPublisher.scala:189)
   	at org.apache.kafka.image.loader.MetadataLoader.maybePublishMetadata(MetadataLoader.java:364)
   	at org.apache.kafka.image.loader.MetadataBatchLoader.applyDeltaAndUpdate(MetadataBatchLoader.java:285)
   	at org.apache.kafka.image.loader.MetadataBatchLoader.maybeFlushBatches(MetadataBatchLoader.java:221)
   	at org.apache.kafka.image.loader.MetadataLoader.lambda$handleCommit$1(MetadataLoader.java:406)
   	at org.apache.kafka.queue.KafkaEventQueue$EventContext.run(KafkaEventQueue.java:134)
   	at org.apache.kafka.queue.KafkaEventQueue$EventHandler.handleEvents(KafkaEventQueue.java:217)
   	at org.apache.kafka.queue.KafkaEventQueue$EventHandler.run(KafkaEventQueue.java:188)
   	at java.base/java.lang.Thread.run(Thread.java:840)
   ```
   
   In `DynamicBrokerConfig.updateDefaultConfig()` we catch Exception, so we never propagate the error up the stack to `DynamicConfigPublisher.onMetadataUpdate()`. Anyway `metadataPublishingFaultHandler` is non fatal, so it wouldn't fail the broker either.
   
   But this quirk kind of "helps" us with the [decommissioning process issue](https://github.com/apache/kafka/pull/22070#issuecomment-4282683205), as it allows restarting a broker which has a dynamically set cordoned log dir not present in its log.dirs anymore.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3149667565


##########
metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java:
##########
@@ -1696,8 +1699,7 @@ ControllerResult<BrokerHeartbeatReply> processBrokerHeartbeat(
         if (featureControl.metadataVersionOrThrow().isDirectoryAssignmentSupported()) {
             handleDirectoriesOffline(brokerId, brokerEpoch, request.offlineLogDirs(), records);
         }
-        if (featureControl.metadataVersionOrThrow().isCordonedLogDirsSupported()) {
-            clusterControl.updateCordonedLogDirs(brokerId, request.cordonedLogDirs());
+        if (featureControl.metadataVersionOrThrow().isCordonedLogDirsSupported() && request.cordonedLogDirs() != null) {

Review Comment:
   Are you suggesting to move the null check to `handleDirectoriesCordoned()` instead of here?



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3149753071


##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -681,6 +674,8 @@ public void run() {
                                 logger.info("The broker has caught up. Transitioning from STARTING to RECOVERY.");
                                 state = BrokerState.RECOVERY;
                                 initialCatchUpFuture.complete(null);
+                                // Update the known cordoned log dirs so the next heartbeat includes them
+                                config.cordonedLogDirs().forEach(logDir -> cordonedLogDirs.add(logDirs.get(logDir)));

Review Comment:
   I can't double check now, but I think `config.cordonedLogDirs()` should return the updated value at runtime, even if there have been dynamic updates. Here the whole metadata should have been replayed, so if the static config was (X, Y) and later updated to (Z), `config.cordonedLogDirs()` should return (Z).



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "jsancio (via GitHub)" <gi...@apache.org>.
jsancio commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3112845291


##########
metadata/src/main/java/org/apache/kafka/metadata/BrokerRegistration.java:
##########


Review Comment:
   @chia7712 I know that there was another issue PR where we determine that the broker needs to do dynamic config validation when it applies specifically to the broker.
   
   Are you planning the send all of the configs in "broker.properties" to the controller and the controller will persist this in the cluster metadata partition? Do you have a KIP for this?
   
   I think @junrao was reviewing this PR.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "jsancio (via GitHub)" <gi...@apache.org>.
jsancio commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3161569917


##########
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java:
##########
@@ -349,8 +357,10 @@ private ApiError validateAlterConfig(
                 return DISALLOWED_BROKER_MIN_ISR_TRANSITION_ERROR;
             } else if (isDisallowedClusterMinIsrTransition(configRecord)) {
                 return DISALLOWED_CLUSTER_MIN_ISR_REMOVAL_ERROR;
-            } else if (isCordonedLogDirsDisallowed(configRecord)) {
-                return DISALLOWED_CORDONED_LOG_DIRS_ERROR;
+            } else if (isCordonedLogDirsDisabled(configRecord)) {
+                return DISABLED_CORDONED_LOG_DIRS_ERROR;
+            } else if (isCordonedLogDirsInvalid(configRecord, existingConfigsMap.get(CORDONED_LOG_DIRS_CONFIG), forwarded)) {
+                return INVALID_CORDONED_LOG_DIRS_ERROR;

Review Comment:
   I am okay with addressing this in a separate PR. Maybe we can clean this up when we enhance the controller validation logic for broker configs.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "jsancio (via GitHub)" <gi...@apache.org>.
jsancio commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3163132280


##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -681,6 +647,12 @@ public void run() {
                                 logger.info("The broker has caught up. Transitioning from STARTING to RECOVERY.");
                                 state = BrokerState.RECOVERY;
                                 initialCatchUpFuture.complete(null);
+                                // Update the known cordoned log dirs so the next heartbeat includes them
+                                config.cordonedLogDirs().forEach(logDir -> {
+                                    if (logDirs.containsKey(logDir)) {
+                                        cordonedLogDirs.add(logDirs.get(logDir));

Review Comment:
   Sounds good. That works for me



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3162835346


##########
core/src/main/scala/kafka/server/DynamicBrokerConfig.scala:
##########
@@ -609,29 +609,14 @@ class DynamicLogConfig(logManager: LogManager, directoryEventHandler: DirectoryE
 
   override def reconfigure(oldConfig: KafkaConfig, newConfig: KafkaConfig): Unit = {
     val newBrokerDefaults = new util.HashMap[String, Object](newConfig.extractLogConfigMap)
-
-    logManager.updateCordonedLogDirs(util.Set.copyOf(newConfig.cordonedLogDirs))
-    val newCordoned = new util.HashSet[String](newConfig.cordonedLogDirs)
-    newCordoned.removeAll(oldConfig.cordonedLogDirs)
-
-    val newUncordoned = new util.HashSet[String](oldConfig.cordonedLogDirs)
-    newUncordoned.removeAll(newConfig.cordonedLogDirs)
-    if (!newCordoned.isEmpty) {
-      directoryEventHandler.handleCordoned(newCordoned.stream
-        .map[Uuid](dir => logManager.directoryId(dir).orElse(null))
-        .filter(Objects.nonNull)
-        .collect(Collectors.toSet[Uuid]))
-    }
-    if (!newUncordoned.isEmpty) {
-      directoryEventHandler.handleUncordoned(newUncordoned.stream
-        .map[Uuid](dir => logManager.directoryId(dir).orElse(null))
-        .filter(Objects.nonNull)
-        .collect(Collectors.toSet[Uuid]))
-    }
-
     logManager.reconfigureDefaultLogConfig(new LogConfig(newBrokerDefaults))
-
     updateLogsConfig(newBrokerDefaults.asScala)
+
+    logManager.updateCordonedLogDirs(util.Set.copyOf(newConfig.cordonedLogDirs))
+    directoryEventHandler.handleCordoned(newConfig.cordonedLogDirs.stream
+      .map[Uuid](dir => logManager.directoryId(dir).orElse(null))
+      .filter(Objects.nonNull)

Review Comment:
   Nice suggestion, done
   I used `.flatMap[Uuid](dir => logManager.directoryId(dir).stream)`



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3162811621


##########
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java:
##########
@@ -349,8 +357,10 @@ private ApiError validateAlterConfig(
                 return DISALLOWED_BROKER_MIN_ISR_TRANSITION_ERROR;
             } else if (isDisallowedClusterMinIsrTransition(configRecord)) {
                 return DISALLOWED_CLUSTER_MIN_ISR_REMOVAL_ERROR;
-            } else if (isCordonedLogDirsDisallowed(configRecord)) {
-                return DISALLOWED_CORDONED_LOG_DIRS_ERROR;
+            } else if (isCordonedLogDirsDisabled(configRecord)) {
+                return DISABLED_CORDONED_LOG_DIRS_ERROR;
+            } else if (isCordonedLogDirsInvalid(configRecord, existingConfigsMap.get(CORDONED_LOG_DIRS_CONFIG), forwarded)) {
+                return INVALID_CORDONED_LOG_DIRS_ERROR;

Review Comment:
   I raised https://issues.apache.org/jira/browse/KAFKA-20544



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3094762746


##########
metadata/src/main/java/org/apache/kafka/controller/ClusterControlManager.java:
##########
@@ -663,7 +647,7 @@ public void replay(BrokerRegistrationChangeRecord record) {
                 () -> new IllegalStateException(String.format("Unable to replay %s: unknown " +
                     "value for inControlledShutdown field: %x", record, record.inControlledShutdown())));
         Optional<List<Uuid>> directoriesChange = Optional.ofNullable(record.logDirs()).filter(list -> !list.isEmpty());
-        Optional<List<Uuid>> cordonedDirectoriesChange = Optional.ofNullable(record.cordonedLogDirs()).filter(list -> !list.isEmpty());
+        Optional<List<Uuid>> cordonedDirectoriesChange = Optional.ofNullable(record.cordonedLogDirs());

Review Comment:
   Would you mind fixing `ClusterDelta` as well?
   
   https://github.com/apache/kafka/blob/trunk/metadata/src/main/java/org/apache/kafka/image/ClusterDelta.java#L145



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3095120449


##########
metadata/src/main/java/org/apache/kafka/controller/ClusterControlManager.java:
##########
@@ -663,7 +647,7 @@ public void replay(BrokerRegistrationChangeRecord record) {
                 () -> new IllegalStateException(String.format("Unable to replay %s: unknown " +
                     "value for inControlledShutdown field: %x", record, record.inControlledShutdown())));
         Optional<List<Uuid>> directoriesChange = Optional.ofNullable(record.logDirs()).filter(list -> !list.isEmpty());
-        Optional<List<Uuid>> cordonedDirectoriesChange = Optional.ofNullable(record.cordonedLogDirs()).filter(list -> !list.isEmpty());
+        Optional<List<Uuid>> cordonedDirectoriesChange = Optional.ofNullable(record.cordonedLogDirs());

Review Comment:
   Yes it should be identical. Updated



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3112243759


##########
metadata/src/main/java/org/apache/kafka/metadata/BrokerRegistration.java:
##########


Review Comment:
   Playing a bit more with it I noticed another issue.
   
   When the value is updated dynamically, brokers check the paths are actual log dirs. But that does not happen when you connect to the controller directly. The controller has no way of knowing which paths are valid, so it should only accept removing entries from the cordoned log dirs list, or deleting the configuration.
   
   



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on PR #22070:
URL: https://github.com/apache/kafka/pull/22070#issuecomment-4305129684

   @jsancio @chia7712 Can you take another look? 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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on PR #22070:
URL: https://github.com/apache/kafka/pull/22070#issuecomment-4254626267

   cc @chia7712 @jsancio 


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on PR #22070:
URL: https://github.com/apache/kafka/pull/22070#issuecomment-4282855690

   > If you can look into this in parallel that would be really helpful. I'm still trying to figure out the other 2 issues (https://github.com/apache/kafka/pull/22070#discussion_r3112204825, https://github.com/apache/kafka/pull/22070#discussion_r3112243759). Thanks
   
   sure. opened KAFKA-20506 and will file a patch soon


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "jsancio (via GitHub)" <gi...@apache.org>.
jsancio commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3113241951


##########
metadata/src/main/java/org/apache/kafka/metadata/BrokerRegistration.java:
##########
@@ -197,6 +198,11 @@ private BrokerRegistration(
         directories.sort(Uuid::compareTo);
         this.directories = Collections.unmodifiableList(directories);
         this.cordonedDirectories = Collections.unmodifiableList(cordonedDirectories);
+        List<Uuid> unknownDirectories = new ArrayList<>(cordonedDirectories);
+        unknownDirectories.removeAll(directories);
+        if (!unknownDirectories.isEmpty()) {
+            throw new IllegalArgumentException("All cordoned directories must be existing directories. Found unknown directories: " + unknownDirectories);

Review Comment:
   This will fail the controller, no? It is okay to keep this check as a worst case if you like. 
   
   If the invalid change came from the `BrokerHeartbeatRequest`, it is better to fail the response of that request instead of failing the active controller. Otherwise, a bad broker can lead to cascading active controller failures.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3137220812


##########
metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java:
##########
@@ -1546,16 +1546,19 @@ void handleDirectoriesCordoned(
             List<ApiMessageAndVersion> records
     ) {
         BrokerRegistration registration = clusterControl.registration(brokerId);
-        List<Uuid> newCordonedDirs = registration.directoryIntersection(cordonedDirs);
-        if (!newCordonedDirs.isEmpty()) {
+        List<Uuid> unknownDirectories = new ArrayList<>(cordonedDirs);
+        unknownDirectories.removeAll(registration.directories());
+        if (!unknownDirectories.isEmpty()) {
+            throw new InvalidRequestException("All cordoned directories must be existing directories. Found unknown directories: " + unknownDirectories);

Review Comment:
   I've gone back and forth on that point. At this point I think it's simpler to allow cordoning an offline log directory. This should have no impact on the functionality as to find usable brokers we start from the online log directories and remove cordoned log directory. 
   
   This would be a bit cleaner as we wouldn't include cordoned log directories that are offline in heartbeats. This should be a marginal scenario, hence why I propose to keep it simple for now as we're already deep into code freeze. I think we should be able to careful track offline and cordoned log directories so we can follow up in a separate issue.
   
   For that reason, I'm leaning towards removing this validation now.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3162717524


##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -681,6 +647,12 @@ public void run() {
                                 logger.info("The broker has caught up. Transitioning from STARTING to RECOVERY.");
                                 state = BrokerState.RECOVERY;
                                 initialCatchUpFuture.complete(null);
+                                // Update the known cordoned log dirs so the next heartbeat includes them
+                                config.cordonedLogDirs().forEach(logDir -> {
+                                    if (logDirs.containsKey(logDir)) {
+                                        cordonedLogDirs.add(logDirs.get(logDir));

Review Comment:
   I think I get your point. We're calling `add()` incidentally here because of the stream syntax, while we're effectively setting `cordonedLogDirs`.
   This line means `cordonedLogDirs = <VALUE>` not `cordonedLogDirs.add(<VALUE>)` but I can understand the confusion. I was considering setting `cordonedLogDirs` to `null` initially and have an proper assignment here to make things clearer.
   
   Why it help to refactor this logic to have a clear assignment?
   Something like:
   ```
   cordonedLogDirs = config.cordonedLogDirs().stream()
       .flatMap(logDir -> Optional.ofNullable(logDirs.get(logDir)).stream())
       .collect(Collectors.toSet());
   ```
   
   Since we only send the cordoned log dirs as part of a heartbeat once fully caught up, I'm uneasy with tracking both the static and dynamic values. In the end we only care about the current "computed" or "aggregated" value so having collections for both is confusing.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "jsancio (via GitHub)" <gi...@apache.org>.
jsancio commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3161616493


##########
core/src/main/scala/kafka/server/DynamicBrokerConfig.scala:
##########
@@ -609,29 +609,14 @@ class DynamicLogConfig(logManager: LogManager, directoryEventHandler: DirectoryE
 
   override def reconfigure(oldConfig: KafkaConfig, newConfig: KafkaConfig): Unit = {
     val newBrokerDefaults = new util.HashMap[String, Object](newConfig.extractLogConfigMap)
-
-    logManager.updateCordonedLogDirs(util.Set.copyOf(newConfig.cordonedLogDirs))
-    val newCordoned = new util.HashSet[String](newConfig.cordonedLogDirs)
-    newCordoned.removeAll(oldConfig.cordonedLogDirs)
-
-    val newUncordoned = new util.HashSet[String](oldConfig.cordonedLogDirs)
-    newUncordoned.removeAll(newConfig.cordonedLogDirs)
-    if (!newCordoned.isEmpty) {
-      directoryEventHandler.handleCordoned(newCordoned.stream
-        .map[Uuid](dir => logManager.directoryId(dir).orElse(null))
-        .filter(Objects.nonNull)
-        .collect(Collectors.toSet[Uuid]))
-    }
-    if (!newUncordoned.isEmpty) {
-      directoryEventHandler.handleUncordoned(newUncordoned.stream
-        .map[Uuid](dir => logManager.directoryId(dir).orElse(null))
-        .filter(Objects.nonNull)
-        .collect(Collectors.toSet[Uuid]))
-    }
-
     logManager.reconfigureDefaultLogConfig(new LogConfig(newBrokerDefaults))
-
     updateLogsConfig(newBrokerDefaults.asScala)
+
+    logManager.updateCordonedLogDirs(util.Set.copyOf(newConfig.cordonedLogDirs))
+    directoryEventHandler.handleCordoned(newConfig.cordonedLogDirs.stream
+      .map[Uuid](dir => logManager.directoryId(dir).orElse(null))
+      .filter(Objects.nonNull)

Review Comment:
   Nit but this can be done with flatMap:
   ```java
         .flatMap[Uuid](dir => Stream.ofNullable(logManager.directoryId(dir)))
         .collect(Collectors.toSet[Uuid]))
   ```



##########
checkstyle/suppressions.xml:
##########
@@ -43,6 +43,9 @@
     <suppress checks="ClassDataAbstractionCoupling|ClassFanOutComplexity" files="SharePartitionManagerTest"/>
     <suppress checks="CyclomaticComplexity" files="SharePartition.java"/>
 
+    <!-- server -->
+    <suppress checks="CyclomaticComplexity" files="BrokerLifecycleManager.java"/>

Review Comment:
   Nit. Do you mind adding this suppression as an annotation in the code? You can limit the annotation to the complex method instead of the entire type. E.g. `@SuppressWarnings({"CyclomaticComplexity"})`.



##########
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java:
##########
@@ -439,8 +439,19 @@ boolean isDisallowedBrokerMinIsrTransition(ConfigRecord configRecord) {
         return false;
     }
 
-    // Prevent updating cordoned.log.dirs if the request is not forwarded and the new value adds directories not
-    // already cordoned
+    /**
+     * Return whether the update to cordoned.log.dirs is valid or not
+     *
+     * Updates to cordoned.log.dirs normally go through the concerned broker which is able to validate the new value
+     * before forwarding the request to the controller.
+     * However, it's also possible to directly go to controllers, but since controllers only have directory ids, they
+     * cannot fully validate updates (cordoned.log.dirs is a list of paths). So if the request has not been forwarded
+     * by a broker, controllers can only accept updates that remove entries in cordoned.log.dirs.

Review Comment:
   Thanks for the detail comment. The next kafka contributor is going to appreciate this explanation. 😄 



##########
server/src/main/java/org/apache/kafka/server/BrokerLifecycleManager.java:
##########
@@ -681,6 +647,12 @@ public void run() {
                                 logger.info("The broker has caught up. Transitioning from STARTING to RECOVERY.");
                                 state = BrokerState.RECOVERY;
                                 initialCatchUpFuture.complete(null);
+                                // Update the known cordoned log dirs so the next heartbeat includes them
+                                config.cordonedLogDirs().forEach(logDir -> {
+                                    if (logDirs.containsKey(logDir)) {
+                                        cordonedLogDirs.add(logDirs.get(logDir));

Review Comment:
   @mimaison it is odd to me that we are **adding** directories to cordoned log dirs when handling the heartbeat **response**.
   
   When the broker lifecycle manager sends a heartbeat it is already checking that the initialCatchUpFuture has completed successfully from line 649 above.
   
   To me this is not an issue of handling the heartbeat response but making sure that the heartbeat request contains the correct information.
   
   The set of cordoned directory come from the static configuration or the dynamic configuration with the dynamic configuration taking precedence. The static cordoned director information is known at startup. The dynamic configuration is only known when the broker has caught up enough.
   
   This is why I suggested injecting the static cordoned in the constructor and only updating the dynamic cordoned directory.
   
   ```java
   private final Set<Uuid> staticCordonedLogDirs;
   private Optional<Set<Uuid>> dynamciCordonedLogDirs = Optional.empty();
   
   public BrokerLifecycleManager(...) {
       ...
       this.staticCordonedLogDirs = staticCordonedLogDirs;
   }
   ```
   
   We can update the CordonedDirEvent to make this update `cordonedLogDirs = Optional.of(dirs);`
   
   Finally when generating the heartbeat request the lifecycle manager can:
   ```java
           if (initialCatchUpFuture.isDone() &&
               !initialCatchUpFuture.isCompletedExceptionally() &&
               cordonedLogDirsSupported.get()
           ) {
               data.setCordonedLogDirs(dynamciCordonedLogDirs.orElse(staticCordonedLogDirs));
           }
   ```
   
   What do you think? The code you have may be correct in practice but conceptually I can't seem to reason why `cordonedLogDirs.add(logDirs.get(logDir))` is correct. The fact that we are calling `add` doesn't seem right to me.
   
   The other solution, as you point out, is to just send the latest value in `AbstractKafkaConfig config` as that type should already be doing a similar resolution.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3169583903


##########
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java:
##########
@@ -422,7 +439,32 @@ boolean isDisallowedBrokerMinIsrTransition(ConfigRecord configRecord) {
         return false;
     }
 
-    boolean isCordonedLogDirsDisallowed(ConfigRecord configRecord) {
+    /**
+     * Return whether the update to cordoned.log.dirs is valid or not
+     *
+     * Updates to cordoned.log.dirs normally go through the concerned broker which is able to validate the new value
+     * before forwarding the request to the controller.
+     * However, it's also possible to directly go to controllers, but since controllers only have directory ids, they
+     * cannot fully validate updates (cordoned.log.dirs is a list of paths). So if the request has not been forwarded
+     * by a broker, controllers can only accept updates that remove entries in cordoned.log.dirs.
+     *
+     * @param configRecord The configuration record
+     * @param currentValue The current cordoned.log.dirs value
+     * @param forwarded    True is the request has been forwarded by a broker
+     */
+    boolean isCordonedLogDirsInvalid(ConfigRecord configRecord, String currentValue, boolean forwarded) {
+        if (!configRecord.name().equals(CORDONED_LOG_DIRS_CONFIG) || configRecord.resourceType() != BROKER.id() ||

Review Comment:
   Should we use `configRecord.value().trim().isEmpty()` to handle cases with only whitespace?



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on PR #22070:
URL: https://github.com/apache/kafka/pull/22070#issuecomment-4329020675

   @jsancio @chia7712 Can you take another look? 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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "jsancio (via GitHub)" <gi...@apache.org>.
jsancio commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3154136380


##########
metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java:
##########
@@ -1696,8 +1699,7 @@ ControllerResult<BrokerHeartbeatReply> processBrokerHeartbeat(
         if (featureControl.metadataVersionOrThrow().isDirectoryAssignmentSupported()) {
             handleDirectoriesOffline(brokerId, brokerEpoch, request.offlineLogDirs(), records);
         }
-        if (featureControl.metadataVersionOrThrow().isCordonedLogDirsSupported()) {
-            clusterControl.updateCordonedLogDirs(brokerId, request.cordonedLogDirs());
+        if (featureControl.metadataVersionOrThrow().isCordonedLogDirsSupported() && request.cordonedLogDirs() != null) {

Review Comment:
   Yes.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3149624812


##########
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java:
##########
@@ -349,8 +357,10 @@ private ApiError validateAlterConfig(
                 return DISALLOWED_BROKER_MIN_ISR_TRANSITION_ERROR;
             } else if (isDisallowedClusterMinIsrTransition(configRecord)) {
                 return DISALLOWED_CLUSTER_MIN_ISR_REMOVAL_ERROR;
-            } else if (isCordonedLogDirsDisallowed(configRecord)) {
-                return DISALLOWED_CORDONED_LOG_DIRS_ERROR;
+            } else if (isCordonedLogDirsDisabled(configRecord)) {
+                return DISABLED_CORDONED_LOG_DIRS_ERROR;
+            } else if (isCordonedLogDirsInvalid(configRecord, existingConfigsMap.get(CORDONED_LOG_DIRS_CONFIG), forwarded)) {
+                return INVALID_CORDONED_LOG_DIRS_ERROR;

Review Comment:
   I was not aware of the `ConfigurationValidator` class. So yes the validation should be moved there.
   
   Currently this config is only validated in `KafkaConfig.validateValues()`. However here we do a different kind of validation, we check whether the update is valid to do by the controller. If the request is forwarded, the broker runs `KafkaConfig.validateValues()` before forwarding it. But if it's not forwarded we only want to allow specific type of updates, (only allow subsets), and this is what we do here.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KAFKA-20441: Fix handling of cordoned log dirs [kafka]

Posted by "mimaison (via GitHub)" <gi...@apache.org>.
mimaison commented on code in PR #22070:
URL: https://github.com/apache/kafka/pull/22070#discussion_r3136747749


##########
metadata/src/main/java/org/apache/kafka/controller/ConfigurationControlManager.java:
##########
@@ -259,7 +264,8 @@ ControllerResult<ApiError> incrementalAlterConfig(
         ApiError apiError = incrementalAlterConfigResource(configResource,
             keyToOps,
             newlyCreatedResource,
-            outputRecords);
+            outputRecords,
+            false);

Review Comment:
   Passing the `forwarded` flag all the way till here requires quite a few changes. As it's not used in this code path, I thought this would be ok to hard code it to `false`.
   
   I've made the changes to pass the `forwarded` value and it's actually not too bad. I'll update the PR and we can decide whether it's worth keeping or not.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org