slfan1989 commented on code in PR #8886:
URL: https://github.com/apache/hadoop/pull/8886#discussion_r4505488593


##########
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsDatasetImpl.java:
##########
@@ -529,36 +529,41 @@ public void addVolume(final StorageLocation location,
     StorageType storageType = location.getStorageType();
     final FsVolumeImpl fsVolume =
         createFsVolume(sd.getStorageUuid(), sd, location);
-    // no need to add lock
-    final ReplicaMap tempVolumeMap = new ReplicaMap();
-    ArrayList<IOException> exceptions = Lists.newArrayList();
+    try {
+      // no need to add lock
+      final ReplicaMap tempVolumeMap = new ReplicaMap();
+      ArrayList<IOException> exceptions = Lists.newArrayList();
 
-    for (final NamespaceInfo nsInfo : nsInfos) {
-      String bpid = nsInfo.getBlockPoolID();
-      try {
-        fsVolume.addBlockPool(bpid, this.conf, this.timer);
-        fsVolume.getVolumeMap(bpid, tempVolumeMap, ramDiskReplicaTracker);
-      } catch (IOException e) {
-        LOG.warn("Caught exception when adding " + fsVolume +
-            ". Will throw later.", e);
-        exceptions.add(e);
+      for (final NamespaceInfo nsInfo : nsInfos) {
+        String bpid = nsInfo.getBlockPoolID();
+        try {
+          fsVolume.addBlockPool(bpid, this.conf, this.timer);
+          fsVolume.getVolumeMap(bpid, tempVolumeMap, ramDiskReplicaTracker);
+        } catch (IOException e) {
+          LOG.warn("Caught exception when adding " + fsVolume +
+              ". Will throw later.", e);
+          exceptions.add(e);
+        }
       }
-    }
-    if (!exceptions.isEmpty()) {
-      try {
-        sd.unlock();
-      } catch (IOException e) {
-        exceptions.add(e);
+      if (!exceptions.isEmpty()) {
+        try {
+          sd.unlock();

Review Comment:
   Could we run `fsVolume.shutdown()` before releasing the storage directory 
lock, and put `sd.unlock()` in a finally block? 
   
   `BlockPoolSlice.shutdown()` rewrites the `dfsUsed` cache, so releasing the 
lock first allows another process to open the directory while cleanup is still 
writing to it. 
   
   The current test verifies that `shutdown()` is called. Could it also verify 
that shutdown happens before unlock?



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