FrankYang0529 commented on PR #22751:
URL: https://github.com/apache/kafka/pull/22751#issuecomment-7267775817

   Thanks for reporting this. I reproduced KAFKA-20762 on a local 3.9 cluster 
by following `docs/operations/kraft.md`. I'd like to suggest a broker-side fix 
instead. It needs no new CLI option, so it doesn't need a KIP.
   
   **Where it fails.** A ZK broker in migration mode accepts a v1 
`meta.properties`, because `KafkaServer` adds `REQUIRE_V0` only when 
`zookeeper.metadata.migration.enable` is false. The broker fails when the KRaft 
quorum is already deprovisioned and `/migration` is deleted.
   
   **Proposed fix.** The documented revert keeps 
`zookeeper.metadata.migration.enable=true` in the first roll, so every broker 
starts in migration mode before it starts in plain ZK mode. That migration-mode 
start can rewrite a v1 file as v0. Before it rewrites anything, the broker has 
already checked that `cluster.id` matches ZooKeeper and that the node id 
matches `broker.id`. A v0 file keeps `cluster.id`, the node id (as 
`broker.id`), and `directory.id`. The change is in `KafkaServer.startup`:
   
   ```diff
   @@ -292,6 +292,7 @@ class KafkaServer(
              
initialMetaPropsEnsemble.nonFailedDirectoryProps().forEachRemaining(e => {
                val logDir = e.getKey
                val builder = new MetaProperties.Builder(e.getValue).
   +              setVersion(MetaPropertiesVersion.V0).
                  setClusterId(_clusterId).
                  setNodeId(config.brokerId)
                if (!builder.directoryId().isPresent) {
   @@ -306,9 +307,11 @@ class KafkaServer(
                info(s"Rewriting $logDir${File.separator}meta.properties")
                Files.createDirectories(Paths.get(logDir))
              })
   -          copier.setWriteErrorHandler((logDir, e) => {
   -            logDirFailureChannel.maybeAddOfflineLogDir(logDir, s"Error 
while writing meta.properties to $logDir", e)
   -          })
   +          if (!config.migrationEnabled) {
   +            copier.setWriteErrorHandler((logDir, e) => {
   +              logDirFailureChannel.maybeAddOfflineLogDir(logDir, s"Error 
while writing meta.properties to $logDir", e)
   +            })
   +          }
              copier.writeLogDirChanges()
              copier.copy()
            }
   ```
   
   The first hunk changes nothing in plain ZK mode. `REQUIRE_V0` rejects v1 
files before this code runs, and new files are already v0. The second hunk 
covers the extra write. Without it, a log dir whose write fails starts as 
offline, so `ReplicaManager.handleLogDirFailure` returns early and the 
migration-mode halt never runs.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to