Skip to content

Commit d951388

Browse files
committed
HDFS-5283. Under construction blocks only inside snapshots should not be counted in safemode threshhold. Contributed by Vinay
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1532857 13f79535-47bb-0310-9956-ffa450edef68
1 parent 7866291 commit d951388

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ Release 2.3.0 - UNRELEASED
349349
HDFS-5352. Server#initLog() doesn't close InputStream in httpfs. (Ted Yu via
350350
jing9)
351351

352+
HDFS-5283. Under construction blocks only inside snapshots should not be
353+
counted in safemode threshhold. (Vinay via szetszwo)
354+
352355
Release 2.2.1 - UNRELEASED
353356

354357
INCOMPATIBLE CHANGES

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/blockmanagement/BlockManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,6 +1780,14 @@ private void processFirstBlockReport(final DatanodeDescriptor node,
17801780
if (isBlockUnderConstruction(storedBlock, ucState, reportedState)) {
17811781
((BlockInfoUnderConstruction)storedBlock).addReplicaIfNotPresent(
17821782
node, iblk, reportedState);
1783+
// OpenFileBlocks only inside snapshots also will be added to safemode
1784+
// threshold. So we need to update such blocks to safemode
1785+
// refer HDFS-5283
1786+
BlockInfoUnderConstruction blockUC = (BlockInfoUnderConstruction) storedBlock;
1787+
if (namesystem.isInSnapshot(blockUC)) {
1788+
int numOfReplicas = blockUC.getNumExpectedLocations();
1789+
namesystem.incrementSafeBlockCount(numOfReplicas);
1790+
}
17831791
//and fall through to next clause
17841792
}
17851793
//add replica if appropriate

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
import org.apache.hadoop.hdfs.security.token.block.BlockTokenSecretManager.AccessMode;
166166
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
167167
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenSecretManager;
168+
import org.apache.hadoop.hdfs.server.blockmanagement.BlockCollection;
168169
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
169170
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoUnderConstruction;
170171
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
@@ -3717,6 +3718,39 @@ private void finalizeINodeFileUnderConstruction(String src,
37173718
BlockInfo getStoredBlock(Block block) {
37183719
return blockManager.getStoredBlock(block);
37193720
}
3721+
3722+
@Override
3723+
public boolean isInSnapshot(BlockInfoUnderConstruction blockUC) {
3724+
assert hasReadOrWriteLock();
3725+
final BlockCollection bc = blockUC.getBlockCollection();
3726+
if (bc == null || !(bc instanceof INodeFileUnderConstruction)) {
3727+
return false;
3728+
}
3729+
3730+
INodeFileUnderConstruction inodeUC = (INodeFileUnderConstruction) blockUC
3731+
.getBlockCollection();
3732+
String fullName = inodeUC.getName();
3733+
try {
3734+
if (fullName != null && fullName.startsWith(Path.SEPARATOR)
3735+
&& dir.getINode(fullName) == inodeUC) {
3736+
// If file exists in normal path then no need to look in snapshot
3737+
return false;
3738+
}
3739+
} catch (UnresolvedLinkException e) {
3740+
LOG.error("Error while resolving the link : " + fullName, e);
3741+
return false;
3742+
}
3743+
/*
3744+
* 1. if bc is an instance of INodeFileUnderConstructionWithSnapshot, and
3745+
* bc is not in the current fsdirectory tree, bc must represent a snapshot
3746+
* file.
3747+
* 2. if fullName is not an absolute path, bc cannot be existent in the
3748+
* current fsdirectory tree.
3749+
* 3. if bc is not the current node associated with fullName, bc must be a
3750+
* snapshot inode.
3751+
*/
3752+
return true;
3753+
}
37203754

37213755
void commitBlockSynchronization(ExtendedBlock lastblock,
37223756
long newgenerationstamp, long newlength,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.apache.hadoop.classification.InterfaceAudience;
2121
import org.apache.hadoop.hdfs.protocol.Block;
22+
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoUnderConstruction;
2223
import org.apache.hadoop.hdfs.server.namenode.NameNode.OperationCategory;
2324
import org.apache.hadoop.hdfs.util.RwLock;
2425
import org.apache.hadoop.ipc.StandbyException;
@@ -43,4 +44,6 @@ public interface Namesystem extends RwLock, SafeMode {
4344
public void adjustSafeModeBlockTotals(int deltaSafe, int deltaTotal);
4445

4546
public void checkOperation(OperationCategory read) throws StandbyException;
47+
48+
public boolean isInSnapshot(BlockInfoUnderConstruction blockUC);
4649
}

hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/DFSTestUtil.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,4 +994,8 @@ public static void runOperations(MiniDFSCluster cluster,
994994
cluster.getNameNodeRpc(nnIndex), filePath, 0L, bytes.length);
995995
} while (locatedBlocks.isUnderConstruction());
996996
}
997+
998+
public static void abortStream(DFSOutputStream out) throws IOException {
999+
out.abort();
1000+
}
9971001
}

0 commit comments

Comments
 (0)