Parcourir la source

HDFS-14010. Pass correct DF usage to ReservedSpaceCalculator builder. Contributed by Virajith Jalaparti.

(cherry picked from commit 1cc1530b4e874391a17ec81e24cb55dfbbabd36a)
(cherry picked from commit 223a582eb839bb6e4298a2fe0243bc27d73fc977)
Wei-Chiu Chuang il y a 6 ans
Parent
commit
29c4aded34

+ 8 - 3
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/FsVolumeImpl.java

@@ -164,6 +164,13 @@ public class FsVolumeImpl implements FsVolumeSpi {
     this.storageType = storageLocation.getStorageType();
     this.configuredCapacity = -1;
     this.usage = usage;
+    if (this.usage != null) {
+      reserved = new ReservedSpaceCalculator.Builder(conf)
+          .setUsage(this.usage).setStorageType(storageType).build();
+    } else {
+      reserved = null;
+      LOG.warn("Setting reserved to null as usage is null");
+    }
     if (currentDir != null) {
       File parent = currentDir.getParentFile();
       cacheExecutor = initializeCacheExecutor(parent);
@@ -174,8 +181,6 @@ public class FsVolumeImpl implements FsVolumeSpi {
     }
     this.conf = conf;
     this.fileIoProvider = fileIoProvider;
-    this.reserved = new ReservedSpaceCalculator.Builder(conf)
-        .setUsage(usage).setStorageType(storageType).build();
   }
 
   protected ThreadPoolExecutor initializeCacheExecutor(File parent) {
@@ -480,7 +485,7 @@ public class FsVolumeImpl implements FsVolumeSpi {
   }
 
   long getReserved(){
-    return reserved.getReserved();
+    return reserved != null ? reserved.getReserved() : 0;
   }
 
   @VisibleForTesting

+ 8 - 0
hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/TestProvidedImpl.java

@@ -352,6 +352,14 @@ public class TestProvidedImpl {
     }
   }
 
+  @Test
+  public void testReserved() throws Exception {
+    for (FsVolumeSpi vol : providedVolumes) {
+      // the reserved space for provided volumes should be 0.
+      assertEquals(0, ((FsVolumeImpl) vol).getReserved());
+    }
+  }
+
   @Test
   public void testProvidedVolumeImpl() throws IOException {