HDFS-8035. Move checkBlocksProperlyReplicated() in FSNamesystem to BlockManager. Contributed by Haohui Mai.
This commit is contained in:
parent
81ed3a2bb8
commit
6e36dbf03a
|
@ -568,6 +568,9 @@ Release 2.7.0 - UNRELEASED
|
||||||
HDFS-8008. Support client-side back off when the datanodes are congested.
|
HDFS-8008. Support client-side back off when the datanodes are congested.
|
||||||
(wheat9)
|
(wheat9)
|
||||||
|
|
||||||
|
HDFS-8035. Move checkBlocksProperlyReplicated() in FSNamesystem to
|
||||||
|
BlockManager. (wheat9)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HDFS-7454. Reduce memory footprint for AclEntries in NameNode.
|
HDFS-7454. Reduce memory footprint for AclEntries in NameNode.
|
||||||
|
|
|
@ -3411,6 +3411,27 @@ public class BlockManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the indicated blocks are present and
|
||||||
|
* replicated.
|
||||||
|
*/
|
||||||
|
public boolean checkBlocksProperlyReplicated(
|
||||||
|
String src, BlockInfoContiguous[] blocks) {
|
||||||
|
for (BlockInfoContiguous b: blocks) {
|
||||||
|
if (!b.isComplete()) {
|
||||||
|
final BlockInfoContiguousUnderConstruction uc =
|
||||||
|
(BlockInfoContiguousUnderConstruction)b;
|
||||||
|
final int numNodes = b.numNodes();
|
||||||
|
LOG.info("BLOCK* " + b + " is not COMPLETE (ucState = "
|
||||||
|
+ uc.getBlockUCState() + ", replication# = " + numNodes
|
||||||
|
+ (numNodes < minReplication ? " < ": " >= ")
|
||||||
|
+ " minimum = " + minReplication + ") in file " + src);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return 0 if the block is not found;
|
* @return 0 if the block is not found;
|
||||||
* otherwise, return the replication factor of the block.
|
* otherwise, return the replication factor of the block.
|
||||||
|
|
|
@ -3525,20 +3525,19 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
||||||
* @param targets target datanodes where replicas of the new block is placed
|
* @param targets target datanodes where replicas of the new block is placed
|
||||||
* @throws QuotaExceededException If addition of block exceeds space quota
|
* @throws QuotaExceededException If addition of block exceeds space quota
|
||||||
*/
|
*/
|
||||||
BlockInfoContiguous saveAllocatedBlock(String src, INodesInPath inodesInPath,
|
private void saveAllocatedBlock(String src, INodesInPath inodesInPath,
|
||||||
Block newBlock, DatanodeStorageInfo[] targets)
|
Block newBlock, DatanodeStorageInfo[] targets)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
assert hasWriteLock();
|
assert hasWriteLock();
|
||||||
BlockInfoContiguous b = dir.addBlock(src, inodesInPath, newBlock, targets);
|
BlockInfoContiguous b = dir.addBlock(src, inodesInPath, newBlock, targets);
|
||||||
NameNode.stateChangeLog.info("BLOCK* allocate " + b + " for " + src);
|
NameNode.stateChangeLog.info("BLOCK* allocate " + b + " for " + src);
|
||||||
DatanodeStorageInfo.incrementBlocksScheduled(targets);
|
DatanodeStorageInfo.incrementBlocksScheduled(targets);
|
||||||
return b;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new block with a unique block id and a new generation stamp.
|
* Create new block with a unique block id and a new generation stamp.
|
||||||
*/
|
*/
|
||||||
Block createNewBlock() throws IOException {
|
private Block createNewBlock() throws IOException {
|
||||||
assert hasWriteLock();
|
assert hasWriteLock();
|
||||||
Block b = new Block(nextBlockId(), 0, 0);
|
Block b = new Block(nextBlockId(), 0, 0);
|
||||||
// Increment the generation stamp for every new block.
|
// Increment the generation stamp for every new block.
|
||||||
|
@ -3555,51 +3554,21 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
||||||
readLock();
|
readLock();
|
||||||
try {
|
try {
|
||||||
if (checkall) {
|
if (checkall) {
|
||||||
// check all blocks of the file.
|
return blockManager.checkBlocksProperlyReplicated(src, v
|
||||||
for (BlockInfoContiguous block: v.getBlocks()) {
|
.getBlocks());
|
||||||
if (!isCompleteBlock(src, block, blockManager.minReplication)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// check the penultimate block of this file
|
// check the penultimate block of this file
|
||||||
BlockInfoContiguous b = v.getPenultimateBlock();
|
BlockInfoContiguous b = v.getPenultimateBlock();
|
||||||
if (b != null
|
return b == null ||
|
||||||
&& !isCompleteBlock(src, b, blockManager.minReplication)) {
|
blockManager.checkBlocksProperlyReplicated(
|
||||||
return false;
|
src, new BlockInfoContiguous[] { b });
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
} finally {
|
} finally {
|
||||||
readUnlock();
|
readUnlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isCompleteBlock(String src, BlockInfoContiguous b, int minRepl) {
|
/**
|
||||||
if (!b.isComplete()) {
|
|
||||||
final BlockInfoContiguousUnderConstruction uc = (BlockInfoContiguousUnderConstruction)b;
|
|
||||||
final int numNodes = b.numNodes();
|
|
||||||
LOG.info("BLOCK* " + b + " is not COMPLETE (ucState = "
|
|
||||||
+ uc.getBlockUCState() + ", replication# = " + numNodes
|
|
||||||
+ (numNodes < minRepl? " < ": " >= ")
|
|
||||||
+ " minimum = " + minRepl + ") in file " + src);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
// Here's how to handle block-copy failure during client write:
|
|
||||||
// -- As usual, the client's write should result in a streaming
|
|
||||||
// backup write to a k-machine sequence.
|
|
||||||
// -- If one of the backup machines fails, no worries. Fail silently.
|
|
||||||
// -- Before client is allowed to close and finalize file, make sure
|
|
||||||
// that the blocks are backed up. Namenode may have to issue specific backup
|
|
||||||
// commands to make up for earlier datanode failures. Once all copies
|
|
||||||
// are made, edit namespace and return to client.
|
|
||||||
////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Change the indicated filename.
|
* Change the indicated filename.
|
||||||
* @deprecated Use {@link #renameTo(String, String, boolean,
|
* @deprecated Use {@link #renameTo(String, String, boolean,
|
||||||
* Options.Rename...)} instead.
|
* Options.Rename...)} instead.
|
||||||
|
|
Loading…
Reference in New Issue