HDFS-14661. RBF: updateMountTableEntry shouldn't update mountTableEntry if targetPath not exist. Contributed by xuzq.

This commit is contained in:
Ayush Saxena 2019-08-01 08:43:39 +05:30
parent c1f74405d7
commit 89b102f916
2 changed files with 42 additions and 17 deletions

View File

@ -269,13 +269,19 @@ public UpdateMountTableEntryResponse updateMountTableEntry(
UpdateMountTableEntryRequest request) throws IOException { UpdateMountTableEntryRequest request) throws IOException {
UpdateMountTableEntryResponse response = UpdateMountTableEntryResponse response =
getMountTableStore().updateMountTableEntry(request); getMountTableStore().updateMountTableEntry(request);
try {
MountTable mountTable = request.getEntry(); MountTable mountTable = request.getEntry();
if (mountTable != null && router.isQuotaEnabled()) { if (mountTable != null && router.isQuotaEnabled()) {
synchronizeQuota(mountTable.getSourcePath(), synchronizeQuota(mountTable.getSourcePath(),
mountTable.getQuota().getQuota(), mountTable.getQuota().getQuota(),
mountTable.getQuota().getSpaceQuota()); mountTable.getQuota().getSpaceQuota());
} }
} catch (Exception e) {
// Ignore exception, if any while reseting quota. Specifically to handle
// if the actual destination doesn't exist.
LOG.warn("Unable to reset quota at the destinations for {}: {}",
request.getEntry().toString(), e.getMessage());
}
return response; return response;
} }

View File

@ -59,6 +59,7 @@
import org.apache.hadoop.hdfs.server.federation.store.protocol.RemoveMountTableEntryRequest; import org.apache.hadoop.hdfs.server.federation.store.protocol.RemoveMountTableEntryRequest;
import org.apache.hadoop.hdfs.server.federation.store.protocol.RemoveMountTableEntryResponse; import org.apache.hadoop.hdfs.server.federation.store.protocol.RemoveMountTableEntryResponse;
import org.apache.hadoop.hdfs.server.federation.store.protocol.UpdateMountTableEntryRequest; import org.apache.hadoop.hdfs.server.federation.store.protocol.UpdateMountTableEntryRequest;
import org.apache.hadoop.hdfs.server.federation.store.protocol.UpdateMountTableEntryResponse;
import org.apache.hadoop.hdfs.server.federation.store.records.MountTable; import org.apache.hadoop.hdfs.server.federation.store.records.MountTable;
import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.Time; import org.apache.hadoop.util.Time;
@ -244,6 +245,25 @@ private boolean addMountTable(final MountTable entry) throws IOException {
return addResponse.getStatus(); return addResponse.getStatus();
} }
/**
* Update a mount table entry to the mount table through the admin API.
* @param entry Mount table entry to update.
* @return If it was successfully updated
* @throws IOException Problems update entries
*/
private boolean updateMountTable(final MountTable entry) throws IOException {
RouterClient client = routerContext.getAdminClient();
MountTableManager mountTableManager = client.getMountTableManager();
UpdateMountTableEntryRequest updateRequest =
UpdateMountTableEntryRequest.newInstance(entry);
UpdateMountTableEntryResponse updateResponse =
mountTableManager.updateMountTableEntry(updateRequest);
// Reload the Router cache
resolver.loadCache(true);
return updateResponse.getStatus();
}
/** /**
* Append data in specified file. * Append data in specified file.
* @param path Path of file. * @param path Path of file.
@ -496,11 +516,7 @@ public void testQuotaSynchronization() throws IOException {
mountTable.setQuota(new RouterQuotaUsage.Builder().quota(updateNsQuota) mountTable.setQuota(new RouterQuotaUsage.Builder().quota(updateNsQuota)
.spaceQuota(updateSsQuota).build()); .spaceQuota(updateSsQuota).build());
UpdateMountTableEntryRequest updateRequest = UpdateMountTableEntryRequest updateMountTable(mountTable);
.newInstance(mountTable);
RouterClient client = routerContext.getAdminClient();
MountTableManager mountTableManager = client.getMountTableManager();
mountTableManager.updateMountTableEntry(updateRequest);
// verify if the quota is updated in real path // verify if the quota is updated in real path
realQuota = nnContext1.getFileSystem().getQuotaUsage( realQuota = nnContext1.getFileSystem().getQuotaUsage(
@ -512,18 +528,21 @@ public void testQuotaSynchronization() throws IOException {
mountTable.setQuota(new RouterQuotaUsage.Builder() mountTable.setQuota(new RouterQuotaUsage.Builder()
.quota(HdfsConstants.QUOTA_RESET) .quota(HdfsConstants.QUOTA_RESET)
.spaceQuota(HdfsConstants.QUOTA_RESET).build()); .spaceQuota(HdfsConstants.QUOTA_RESET).build());
updateMountTable(mountTable);
updateRequest = UpdateMountTableEntryRequest
.newInstance(mountTable);
client = routerContext.getAdminClient();
mountTableManager = client.getMountTableManager();
mountTableManager.updateMountTableEntry(updateRequest);
// verify if the quota is updated in real path // verify if the quota is updated in real path
realQuota = nnContext1.getFileSystem().getQuotaUsage( realQuota = nnContext1.getFileSystem().getQuotaUsage(
new Path("/testsync")); new Path("/testsync"));
assertEquals(HdfsConstants.QUOTA_RESET, realQuota.getQuota()); assertEquals(HdfsConstants.QUOTA_RESET, realQuota.getQuota());
assertEquals(HdfsConstants.QUOTA_RESET, realQuota.getSpaceQuota()); assertEquals(HdfsConstants.QUOTA_RESET, realQuota.getSpaceQuota());
// Verify updating mount entry with actual destinations not present.
mountTable = MountTable.newInstance("/testupdate",
Collections.singletonMap("ns0", "/testupdate"), Time.now(), Time.now());
addMountTable(mountTable);
mountTable.setQuota(new RouterQuotaUsage.Builder().quota(1)
.spaceQuota(2).build());
assertTrue(updateMountTable(mountTable));
} }
@Test @Test