HDFS-13115. In getNumUnderConstructionBlocks(), ignore the inodeIds for which the inodes have been deleted. Contributed by Yongjun Zhang.

(cherry picked from commit f491f717e9ee6b75ad5cfca48da9c6297e94a8f7)

Conflicts:

	hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/LeaseManager.java
This commit is contained in:
Yongjun Zhang 2018-02-07 14:19:18 -08:00
parent 821729905e
commit 60d82ac61f

View File

@ -142,7 +142,15 @@ synchronized long getNumUnderConstructionBlocks() {
+ "acquired before counting under construction blocks"; + "acquired before counting under construction blocks";
long numUCBlocks = 0; long numUCBlocks = 0;
for (Long id : getINodeIdWithLeases()) { for (Long id : getINodeIdWithLeases()) {
final INodeFile cons = fsnamesystem.getFSDirectory().getInode(id).asFile(); INode inode = fsnamesystem.getFSDirectory().getInode(id);
if (inode == null) {
// The inode could have been deleted after getINodeIdWithLeases() is
// called, check here, and ignore it if so
LOG.warn("Failed to find inode " + id +
" in getNumUnderConstructionBlocks().");
continue;
}
final INodeFile cons = inode.asFile();
if (!cons.isUnderConstruction()) { if (!cons.isUnderConstruction()) {
LOG.warn("The file " + cons.getFullPathName() LOG.warn("The file " + cons.getFullPathName()
+ " is not under construction but has lease."); + " is not under construction but has lease.");
@ -153,10 +161,11 @@ synchronized long getNumUnderConstructionBlocks() {
continue; continue;
} }
for(BlockInfo b : blocks) { for(BlockInfo b : blocks) {
if(!b.isComplete()) if(!b.isComplete()) {
numUCBlocks++; numUCBlocks++;
} }
} }
}
LOG.info("Number of blocks under construction: " + numUCBlocks); LOG.info("Number of blocks under construction: " + numUCBlocks);
return numUCBlocks; return numUCBlocks;
} }