Skip to content

Commit 0e02f03

Browse files
abhishekdas99shvachko
authored andcommitted
HADOOP-17999. No-op implementation of setWriteChecksum and setVerifyChecksum in ViewFileSystem. Contributed by Abhishek Das. (#3639)
(cherry picked from commit 54a1d78)
1 parent 81f6cbc commit 0e02f03

File tree

3 files changed

+49
-26
lines changed

3 files changed

+49
-26
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -862,13 +862,9 @@ public void removeXAttr(Path path, String name) throws IOException {
862862
}
863863

864864
@Override
865-
public void setVerifyChecksum(final boolean verifyChecksum) {
866-
List<InodeTree.MountPoint<FileSystem>> mountPoints =
867-
fsState.getMountPoints();
868-
Map<String, FileSystem> fsMap = initializeMountedFileSystems(mountPoints);
869-
for (InodeTree.MountPoint<FileSystem> mount : mountPoints) {
870-
fsMap.get(mount.src).setVerifyChecksum(verifyChecksum);
871-
}
865+
public void setVerifyChecksum(final boolean verifyChecksum) {
866+
// This is a file system level operations, however ViewFileSystem
867+
// points to many file systems. Noop for ViewFileSystem.
872868
}
873869

874870
/**
@@ -964,13 +960,9 @@ public QuotaUsage getQuotaUsage(Path f) throws IOException {
964960
}
965961

966962
@Override
967-
public void setWriteChecksum(final boolean writeChecksum) {
968-
List<InodeTree.MountPoint<FileSystem>> mountPoints =
969-
fsState.getMountPoints();
970-
Map<String, FileSystem> fsMap = initializeMountedFileSystems(mountPoints);
971-
for (InodeTree.MountPoint<FileSystem> mount : mountPoints) {
972-
fsMap.get(mount.src).setWriteChecksum(writeChecksum);
973-
}
963+
public void setWriteChecksum(final boolean writeChecksum) {
964+
// This is a file system level operations, however ViewFileSystem
965+
// points to many file systems. Noop for ViewFileSystem.
974966
}
975967

976968
@Override

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemDelegation.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ public void testSanity() throws URISyntaxException {
8383
assertEquals(new URI("fs2:/").getAuthority(), fs2.getUri().getAuthority());
8484
}
8585

86-
@Test
87-
public void testVerifyChecksum() throws Exception {
88-
checkVerifyChecksum(false);
89-
checkVerifyChecksum(true);
90-
}
91-
9286
/**
9387
* Tests that ViewFileSystem dispatches calls for every ACL method through the
9488
* mount table to the correct underlying FileSystem with all Path arguments
@@ -144,12 +138,6 @@ public void testAclMethods() throws Exception {
144138
verify(mockFs2).getAclStatus(mockFsPath2);
145139
}
146140

147-
void checkVerifyChecksum(boolean flag) {
148-
viewFs.setVerifyChecksum(flag);
149-
assertEquals(flag, fs1.getVerifyChecksum());
150-
assertEquals(flag, fs2.getVerifyChecksum());
151-
}
152-
153141
static class FakeFileSystem extends LocalFileSystem {
154142
boolean verifyChecksum = true;
155143
URI uri;

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,4 +1474,47 @@ public void testTargetFileSystemLazyInitialization() throws Exception {
14741474
// viewfs inner cache is disabled
14751475
assertEquals(cacheSize + 2, TestFileUtil.getCacheSize());
14761476
}
1477+
1478+
@Test
1479+
public void testTargetFileSystemLazyInitializationForChecksumMethods()
1480+
throws Exception {
1481+
final String clusterName = "cluster" + new Random().nextInt();
1482+
Configuration config = new Configuration(conf);
1483+
config.setBoolean(CONFIG_VIEWFS_ENABLE_INNER_CACHE, false);
1484+
config.setClass("fs.othermockfs.impl",
1485+
TestChRootedFileSystem.MockFileSystem.class, FileSystem.class);
1486+
ConfigUtil.addLink(config, clusterName, "/user",
1487+
URI.create("othermockfs://mockauth1/mockpath"));
1488+
ConfigUtil.addLink(config, clusterName,
1489+
"/mock", URI.create("othermockfs://mockauth/mockpath"));
1490+
1491+
final int cacheSize = TestFileUtil.getCacheSize();
1492+
ViewFileSystem viewFs = (ViewFileSystem) FileSystem.get(
1493+
new URI("viewfs://" + clusterName + "/"), config);
1494+
1495+
// As no inner file system instance has been initialized,
1496+
// cache size will remain the same
1497+
// cache is disabled for viewfs scheme, so the viewfs:// instance won't
1498+
// go in the cache even after the initialization
1499+
assertEquals(cacheSize, TestFileUtil.getCacheSize());
1500+
1501+
// This is not going to initialize any filesystem instance
1502+
viewFs.setVerifyChecksum(true);
1503+
1504+
// Cache size will remain the same
1505+
assertEquals(cacheSize, TestFileUtil.getCacheSize());
1506+
1507+
// This resolve path will initialize the file system corresponding
1508+
// to the mount table entry of the path "/user"
1509+
viewFs.getFileChecksum(
1510+
new Path(String.format("viewfs://%s/%s", clusterName, "/user")));
1511+
1512+
// Cache size will increase by 1.
1513+
assertEquals(cacheSize + 1, TestFileUtil.getCacheSize());
1514+
1515+
viewFs.close();
1516+
// Initialized FileSystem instances will not be removed from cache as
1517+
// viewfs inner cache is disabled
1518+
assertEquals(cacheSize + 1, TestFileUtil.getCacheSize());
1519+
}
14771520
}

0 commit comments

Comments
 (0)