Skip to content

Commit

Permalink
HDFS-14010. Pass correct DF usage to ReservedSpaceCalculator builder.…
Browse files Browse the repository at this point in the history
… Contributed by Virajith Jalaparti.
  • Loading branch information
jojochuang committed Jun 18, 2019
1 parent e188bb1 commit 335c1c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,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);
Expand All @@ -173,8 +180,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) {
Expand Down Expand Up @@ -473,7 +478,7 @@ long getRecentReserved() {
}

long getReserved(){
return reserved.getReserved();
return reserved != null ? reserved.getReserved() : 0;
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,14 @@ public void setUp() throws IOException {
}
}

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

Expand Down

0 comments on commit 335c1c9

Please sign in to comment.