chia7712 commented on code in PR #16010:
URL: https://github.com/apache/kafka/pull/16010#discussion_r1609745329


##########
core/src/main/scala/kafka/tools/StorageTool.scala:
##########
@@ -452,19 +452,20 @@ object StorageTool extends Logging {
       stream.println("All of the log directories are already formatted.")
     } else {
       metaPropertiesEnsemble.emptyLogDirs().forEach(logDir => {
-        copier.setLogDirProps(logDir, new 
MetaProperties.Builder(metaProperties).
-          setDirectoryId(copier.generateValidDirectoryId()).
+        val loggingCopier = new 
MetaPropertiesEnsemble.Copier(metaPropertiesEnsemble)
+        loggingCopier.setLogDirProps(logDir, new 
MetaProperties.Builder(metaProperties).
+          setDirectoryId(loggingCopier.generateValidDirectoryId()).
           build())
-        copier.setPreWriteHandler((logDir, _, _) => {
+        loggingCopier.setPreWriteHandler((logDir, _, _) => {
           stream.println(s"Formatting $logDir with metadata.version 
$metadataVersion.")
           Files.createDirectories(Paths.get(logDir))
           val bootstrapDirectory = new BootstrapDirectory(logDir, 
Optional.empty())
           bootstrapDirectory.writeBinaryFile(bootstrapMetadata)
         })
-        copier.setWriteErrorHandler((logDir, e) => {
+        loggingCopier.setWriteErrorHandler((logDir, e) => {
           throw new TerseFailure(s"Error while writing meta.properties file 
$logDir: ${e.getMessage}")
         })
-        copier.writeLogDirChanges()

Review Comment:
   If we do care the order of format, we should change `logDirProps` from 
`HashMap` to `LinkedHashMap`
   
   
https://github.com/apache/kafka/blob/5552f5c26df4eb07b2d6ee218e4a29e4ca790d5c/metadata/src/main/java/org/apache/kafka/metadata/properties/MetaPropertiesEnsemble.java#L192
   
   However, I don't think the order is important, since all we want to do is to 
make sure all of them get format only once, right?



##########
core/src/test/scala/unit/kafka/tools/StorageToolTest.scala:
##########
@@ -307,30 +307,30 @@ Found problem:
     
"SCRAM-SHA-256=[name=alice,salt=\"MWx2NHBkbnc0ZndxN25vdGN4bTB5eTFrN3E=\",saltedpassword=\"mT0yyUUxnlJaC99HXgRTSYlbuqa4FSGtJCJfTMvjYCE=\",iterations=8192]",
     "-S",
     
"SCRAM-SHA-256=[name=george,salt=\"MWx2NHBkbnc0ZndxN25vdGN4bTB5eTFrN3E=\",saltedpassword=\"mT0yyUUxnlJaC99HXgRTSYlbuqa4FSGtJCJfTMvjYCE=\",iterations=8192]")
-    

Review Comment:
   please revert those unrelated changes 



##########
core/src/test/scala/unit/kafka/tools/StorageToolTest.scala:
##########
@@ -488,4 +488,26 @@ Found problem:
       assertEquals(1, exitStatus)
     }
   }
+
+  @Test
+  def testFormatMultiEmptyDirectory(): Unit = {

Review Comment:
   There is already a similar test case 
`testFormatSucceedsIfAllDirectoriesAreAvailable`, so could you please add new 
check to `testFormatSucceedsIfAllDirectoriesAreAvailable`? for example, we can 
split the `stream#toString` by new line literal and then check the duplicate 
contents.



-- 
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