Skip to content

Commit 6b2d6d4

Browse files
committed
HDFS-15009. FSCK -list-corruptfileblocks return Invalid Entries. Contributed by hemanthboyina.
1 parent a2dadac commit 6b2d6d4

File tree

9 files changed

+37
-28
lines changed

9 files changed

+37
-28
lines changed

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/resolver/MountTableResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.FEDERATION_MOUNT_TABLE_MAX_CACHE_SIZE_DEFAULT;
2525
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.FEDERATION_MOUNT_TABLE_CACHE_ENABLE;
2626
import static org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys.FEDERATION_MOUNT_TABLE_CACHE_ENABLE_DEFAULT;
27-
import static org.apache.hadoop.hdfs.server.federation.router.FederationUtil.isParentEntry;
27+
import static org.apache.hadoop.hdfs.DFSUtil.isParentEntry;
2828

2929
import java.io.IOException;
3030
import java.util.Collection;

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/FederationUtil.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.EnumSet;
2828

2929
import org.apache.hadoop.conf.Configuration;
30-
import org.apache.hadoop.fs.Path;
3130
import org.apache.hadoop.hdfs.DFSUtil;
3231
import org.apache.hadoop.hdfs.protocol.HdfsFileStatus;
3332
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
@@ -224,25 +223,6 @@ public static ActiveNamenodeResolver newActiveNamenodeResolver(
224223
return newInstance(conf, null, null, clazz);
225224
}
226225

227-
/**
228-
* Check if the given path is the child of parent path.
229-
* @param path Path to be check.
230-
* @param parent Parent path.
231-
* @return True if parent path is parent entry for given path.
232-
*/
233-
public static boolean isParentEntry(final String path, final String parent) {
234-
if (!path.startsWith(parent)) {
235-
return false;
236-
}
237-
238-
if (path.equals(parent)) {
239-
return true;
240-
}
241-
242-
return path.charAt(parent.length()) == Path.SEPARATOR_CHAR
243-
|| parent.equals(Path.SEPARATOR);
244-
}
245-
246226
/**
247227
* Add the the number of children for an existing HdfsFileStatus object.
248228
* @param dirStatus HdfsfileStatus object.

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/Quota.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hdfs.server.federation.router;
1919

20+
import static org.apache.hadoop.hdfs.DFSUtil.isParentEntry;
21+
2022
import java.io.IOException;
2123
import java.util.ArrayList;
2224
import java.util.Collection;
@@ -217,7 +219,7 @@ private List<RemoteLocation> getValidQuotaLocations(String path)
217219
boolean isChildPath = false;
218220

219221
for (RemoteLocation d : dests) {
220-
if (FederationUtil.isParentEntry(loc.getDest(), d.getDest())) {
222+
if (isParentEntry(loc.getDest(), d.getDest())) {
221223
isChildPath = true;
222224
break;
223225
}

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/RouterQuotaManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
package org.apache.hadoop.hdfs.server.federation.router;
1919

20-
import static org.apache.hadoop.hdfs.server.federation.router.FederationUtil.isParentEntry;
20+
import static org.apache.hadoop.hdfs.DFSUtil.isParentEntry;
2121

2222
import java.util.HashSet;
2323
import java.util.Map.Entry;

hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/impl/MountTableStoreImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package org.apache.hadoop.hdfs.server.federation.store.impl;
1919

20+
import static org.apache.hadoop.hdfs.DFSUtil.isParentEntry;
21+
2022
import java.io.IOException;
2123
import java.util.Collections;
2224
import java.util.Iterator;
@@ -25,7 +27,6 @@
2527
import org.apache.hadoop.classification.InterfaceAudience;
2628
import org.apache.hadoop.classification.InterfaceStability;
2729
import org.apache.hadoop.fs.permission.FsAction;
28-
import org.apache.hadoop.hdfs.server.federation.router.FederationUtil;
2930
import org.apache.hadoop.hdfs.server.federation.router.RouterAdminServer;
3031
import org.apache.hadoop.hdfs.server.federation.router.RouterPermissionChecker;
3132
import org.apache.hadoop.hdfs.server.federation.store.MountTableStore;
@@ -140,7 +141,7 @@ public GetMountTableEntriesResponse getMountTableEntries(
140141
while (it.hasNext()) {
141142
MountTable record = it.next();
142143
String srcPath = record.getSourcePath();
143-
if (!FederationUtil.isParentEntry(srcPath, reqSrcPath)) {
144+
if (!isParentEntry(srcPath, reqSrcPath)) {
144145
it.remove();
145146
} else if (pc != null) {
146147
// do the READ permission check

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/DFSUtil.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,4 +1816,22 @@ public static EnumSet<HdfsFileStatus.Flags> getFlags(
18161816
return flags;
18171817
}
18181818

1819+
/**
1820+
* Check if the given path is the child of parent path.
1821+
* @param path Path to be check.
1822+
* @param parent Parent path.
1823+
* @return True if parent path is parent entry for given path.
1824+
*/
1825+
public static boolean isParentEntry(final String path, final String parent) {
1826+
if (!path.startsWith(parent)) {
1827+
return false;
1828+
}
1829+
1830+
if (path.equals(parent)) {
1831+
return true;
1832+
}
1833+
1834+
return path.charAt(parent.length()) == Path.SEPARATOR_CHAR
1835+
|| parent.equals(Path.SEPARATOR);
1836+
}
18191837
}

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSNamesystem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_REPLICATION_KEY;
9090
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SNAPSHOT_DIFF_LISTING_LIMIT;
9191
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_NAMENODE_SNAPSHOT_DIFF_LISTING_LIMIT_DEFAULT;
92+
import static org.apache.hadoop.hdfs.DFSUtil.isParentEntry;
9293

9394
import org.apache.hadoop.hdfs.protocol.HdfsConstants;
9495
import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_STORAGE_POLICY_ENABLED_KEY;
@@ -5665,7 +5666,7 @@ Collection<CorruptFileBlockInfo> listCorruptFileBlocks(String path,
56655666
skip++;
56665667
if (inode != null) {
56675668
String src = inode.getFullPathName();
5668-
if (src.startsWith(path)){
5669+
if (isParentEntry(src, path)) {
56695670
corruptFiles.add(new CorruptFileBlockInfo(src, blk));
56705671
count++;
56715672
if (count >= maxCorruptFileBlocksReturn)

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NamenodeFsck.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@
9494
* This class provides rudimentary checking of DFS volumes for errors and
9595
* sub-optimal conditions.
9696
* <p>The tool scans all files and directories, starting from an indicated
97-
* root path. The following abnormal conditions are detected and handled:</p>
97+
* root path and its descendants. The following abnormal conditions are
98+
* detected and handled:</p>
9899
* <ul>
99100
* <li>files with blocks that are completely missing from all datanodes.<br>
100101
* In this case the tool can perform one of the following actions:

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/TestFsck.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,14 @@ public void testFsckListCorruptFilesBlocks() throws Exception {
11711171
outStr = runFsck(conf, 0, true, "/goodData", "-list-corruptfileblocks");
11721172
System.out.println("3. good fsck out: " + outStr);
11731173
assertTrue(outStr.contains("has 0 CORRUPT files"));
1174-
util.cleanup(fs, "/corruptData");
11751174
util.cleanup(fs, "/goodData");
1175+
1176+
// validate if a directory have any invalid entries
1177+
util.createFiles(fs, "/corruptDa");
1178+
outStr = runFsck(conf, 0, true, "/corruptDa", "-list-corruptfileblocks");
1179+
assertTrue(outStr.contains("has 0 CORRUPT files"));
1180+
util.cleanup(fs, "/corruptData");
1181+
util.cleanup(fs, "/corruptDa");
11761182
}
11771183

11781184
/**

0 commit comments

Comments
 (0)