HDFS-14756. RBF: getQuotaUsage may ignore some folders. Contributed by Chen Zhang.

This commit is contained in:
Inigo Goiri 2019-08-21 09:39:57 -07:00
parent 5eeb6da2d4
commit 93595febaa
2 changed files with 9 additions and 3 deletions

View File

@ -25,7 +25,6 @@
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.fs.QuotaUsage; import org.apache.hadoop.fs.QuotaUsage;
import org.apache.hadoop.fs.StorageType; import org.apache.hadoop.fs.StorageType;
import org.apache.hadoop.hdfs.protocol.ClientProtocol; import org.apache.hadoop.hdfs.protocol.ClientProtocol;
@ -138,7 +137,7 @@ private List<RemoteLocation> getValidQuotaLocations(String path)
boolean isChildPath = false; boolean isChildPath = false;
for (RemoteLocation d : dests) { for (RemoteLocation d : dests) {
if (StringUtils.startsWith(loc.getDest(), d.getDest())) { if (FederationUtil.isParentEntry(loc.getDest(), d.getDest())) {
isChildPath = true; isChildPath = true;
break; break;
} }

View File

@ -332,9 +332,11 @@ public void testGetQuota() throws Exception {
// /getquota --> ns0---/testdir7 // /getquota --> ns0---/testdir7
// /getquota/subdir1 --> ns0---/testdir7/subdir // /getquota/subdir1 --> ns0---/testdir7/subdir
// /getquota/subdir2 --> ns1---/testdir8 // /getquota/subdir2 --> ns1---/testdir8
// /getquota/subdir3 --> ns1---/testdir8-ext
nnFs1.mkdirs(new Path("/testdir7")); nnFs1.mkdirs(new Path("/testdir7"));
nnFs1.mkdirs(new Path("/testdir7/subdir")); nnFs1.mkdirs(new Path("/testdir7/subdir"));
nnFs2.mkdirs(new Path("/testdir8")); nnFs2.mkdirs(new Path("/testdir8"));
nnFs2.mkdirs(new Path("/testdir8-ext"));
MountTable mountTable1 = MountTable.newInstance("/getquota", MountTable mountTable1 = MountTable.newInstance("/getquota",
Collections.singletonMap("ns0", "/testdir7")); Collections.singletonMap("ns0", "/testdir7"));
mountTable1 mountTable1
@ -350,11 +352,16 @@ public void testGetQuota() throws Exception {
Collections.singletonMap("ns1", "/testdir8")); Collections.singletonMap("ns1", "/testdir8"));
addMountTable(mountTable3); addMountTable(mountTable3);
MountTable mountTable4 = MountTable.newInstance("/getquota/subdir3",
Collections.singletonMap("ns1", "/testdir8-ext"));
addMountTable(mountTable4);
// use router client to create new files // use router client to create new files
DFSClient routerClient = routerContext.getClient(); DFSClient routerClient = routerContext.getClient();
routerClient.create("/getquota/file", true).close(); routerClient.create("/getquota/file", true).close();
routerClient.create("/getquota/subdir1/file", true).close(); routerClient.create("/getquota/subdir1/file", true).close();
routerClient.create("/getquota/subdir2/file", true).close(); routerClient.create("/getquota/subdir2/file", true).close();
routerClient.create("/getquota/subdir3/file", true).close();
ClientProtocol clientProtocol = routerContext.getClient().getNamenode(); ClientProtocol clientProtocol = routerContext.getClient().getNamenode();
RouterQuotaUpdateService updateService = routerContext.getRouter() RouterQuotaUpdateService updateService = routerContext.getRouter()
@ -362,7 +369,7 @@ public void testGetQuota() throws Exception {
updateService.periodicInvoke(); updateService.periodicInvoke();
final QuotaUsage quota = clientProtocol.getQuotaUsage("/getquota"); final QuotaUsage quota = clientProtocol.getQuotaUsage("/getquota");
// the quota should be aggregated // the quota should be aggregated
assertEquals(6, quota.getFileAndDirectoryCount()); assertEquals(8, quota.getFileAndDirectoryCount());
} }
@Test @Test