slfan1989 commented on code in PR #10284:
URL: https://github.com/apache/ozone/pull/10284#discussion_r3252587859


##########
hadoop-hdds/container-service/src/main/java/org/apache/hadoop/ozone/container/diskbalancer/DiskBalancerService.java:
##########
@@ -332,17 +332,33 @@ private synchronized DiskBalancerInfo 
readDiskBalancerInfoFile(
   private synchronized void writeDiskBalancerInfoTo(
       DiskBalancerInfo diskBalancerInfo, File path)
       throws IOException {
-    if (path.exists()) {
-      if (!path.delete() || !path.createNewFile()) {
-        throw new IOException("Unable to overwrite the DiskBalancerInfo 
file.");
-      }
-    } else {
-      if (!path.getParentFile().exists() &&
-          !path.getParentFile().mkdirs()) {
-        throw new IOException("Unable to create DiskBalancerInfo 
directories.");
-      }
+    writeDiskBalancerInfoFile(diskBalancerInfo, path);
+  }
+
+  @VisibleForTesting
+  static void writeDiskBalancerInfoFile(DiskBalancerInfo diskBalancerInfo,

Review Comment:
   The two steps are implemented by AtomicFileOutputStream used in 
YamlUtils.dump():
   
   DiskBalancerService.writeDiskBalancerInfoFile()
     -> DiskBalancerYaml.createDiskBalancerInfoFile()
     -> YamlUtils.dump()
     -> new AtomicFileOutputStream(file)
   
   So DiskBalancerService no longer creates the temporary file or moves it 
directly. It relies on the existing YamlUtils atomic write path and avoids the 
previous non-atomic delete/createNewFile before writing.
   



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to