|
@@ -2020,7 +2020,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
BlockInfoContiguous oldBlock = file.getLastBlock();
|
|
|
boolean shouldCopyOnTruncate = shouldCopyOnTruncate(file, oldBlock);
|
|
|
if(newBlock == null) {
|
|
|
- newBlock = (shouldCopyOnTruncate) ? createNewBlock() :
|
|
|
+ newBlock = (shouldCopyOnTruncate) ? createNewBlock(file.isStriped()) :
|
|
|
new Block(oldBlock.getBlockId(), oldBlock.getNumBytes(),
|
|
|
nextGenerationStamp(blockIdManager.isLegacyBlock(oldBlock)));
|
|
|
}
|
|
@@ -2912,8 +2912,9 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
ExtendedBlock previous, Set<Node> excludedNodes,
|
|
|
List<String> favoredNodes) throws IOException {
|
|
|
final long blockSize;
|
|
|
- final int replication;
|
|
|
+ final short numTargets;
|
|
|
final byte storagePolicyID;
|
|
|
+ final boolean isStriped;
|
|
|
Node clientNode = null;
|
|
|
String clientMachine = null;
|
|
|
|
|
@@ -2951,7 +2952,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
.getClientMachine();
|
|
|
clientNode = blockManager.getDatanodeManager().getDatanodeByHost(
|
|
|
clientMachine);
|
|
|
- replication = pendingFile.getFileReplication();
|
|
|
+ // TODO: make block group size configurable (HDFS-7337)
|
|
|
+ isStriped = pendingFile.isStriped();
|
|
|
+ numTargets = isStriped ?
|
|
|
+ HdfsConstants.NUM_DATA_BLOCKS + HdfsConstants.NUM_PARITY_BLOCKS :
|
|
|
+ pendingFile.getFileReplication();
|
|
|
storagePolicyID = pendingFile.getStoragePolicyID();
|
|
|
} finally {
|
|
|
readUnlock();
|
|
@@ -2963,7 +2968,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
|
|
|
// choose targets for the new block to be allocated.
|
|
|
final DatanodeStorageInfo targets[] = getBlockManager().chooseTarget4NewBlock(
|
|
|
- src, replication, clientNode, excludedNodes, blockSize, favoredNodes,
|
|
|
+ src, numTargets, clientNode, excludedNodes, blockSize, favoredNodes,
|
|
|
storagePolicyID);
|
|
|
|
|
|
// Part II.
|
|
@@ -3002,9 +3007,9 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
ExtendedBlock.getLocalBlock(previous));
|
|
|
|
|
|
// allocate new block, record block locations in INode.
|
|
|
- newBlock = createNewBlock();
|
|
|
+ newBlock = createNewBlock(isStriped);
|
|
|
INodesInPath inodesInPath = INodesInPath.fromINode(pendingFile);
|
|
|
- saveAllocatedBlock(src, inodesInPath, newBlock, targets);
|
|
|
+ saveAllocatedBlock(src, inodesInPath, newBlock, targets, isStriped);
|
|
|
|
|
|
persistNewBlock(src, pendingFile);
|
|
|
offset = pendingFile.computeFileSize();
|
|
@@ -3425,13 +3430,15 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
* The last INode is the INode for {@code src} file.
|
|
|
* @param newBlock newly allocated block to be save
|
|
|
* @param targets target datanodes where replicas of the new block is placed
|
|
|
+ * @param isStriped is the file under striping or contigunous layout?
|
|
|
* @throws QuotaExceededException If addition of block exceeds space quota
|
|
|
*/
|
|
|
BlockInfoContiguous saveAllocatedBlock(String src, INodesInPath inodesInPath,
|
|
|
- Block newBlock, DatanodeStorageInfo[] targets)
|
|
|
+ Block newBlock, DatanodeStorageInfo[] targets, boolean isStriped)
|
|
|
throws IOException {
|
|
|
assert hasWriteLock();
|
|
|
- BlockInfoContiguous b = dir.addBlock(src, inodesInPath, newBlock, targets);
|
|
|
+ BlockInfoContiguous b = dir.addBlock(src, inodesInPath, newBlock, targets,
|
|
|
+ isStriped);
|
|
|
NameNode.stateChangeLog.info("BLOCK* allocate " + b + " for " + src);
|
|
|
DatanodeStorageInfo.incrementBlocksScheduled(targets);
|
|
|
return b;
|
|
@@ -3439,10 +3446,11 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
|
|
|
/**
|
|
|
* Create new block with a unique block id and a new generation stamp.
|
|
|
+ * @param isStriped is the file under striping or contiguous layout?
|
|
|
*/
|
|
|
- Block createNewBlock() throws IOException {
|
|
|
+ Block createNewBlock(boolean isStriped) throws IOException {
|
|
|
assert hasWriteLock();
|
|
|
- Block b = new Block(nextBlockId(), 0, 0);
|
|
|
+ Block b = new Block(nextBlockId(isStriped), 0, 0);
|
|
|
// Increment the generation stamp for every new block.
|
|
|
b.setGenerationStamp(nextGenerationStamp(false));
|
|
|
return b;
|
|
@@ -6005,11 +6013,13 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
|
|
|
|
|
|
/**
|
|
|
* Increments, logs and then returns the block ID
|
|
|
+ * @param isStriped is the file under striping or contiguous layout?
|
|
|
*/
|
|
|
- private long nextBlockId() throws IOException {
|
|
|
+ private long nextBlockId(boolean isStriped) throws IOException {
|
|
|
assert hasWriteLock();
|
|
|
checkNameNodeSafeMode("Cannot get next block ID");
|
|
|
- final long blockId = blockIdManager.nextBlockId();
|
|
|
+ final long blockId = isStriped ?
|
|
|
+ blockIdManager.nextBlockGroupId() : blockIdManager.nextBlockId();
|
|
|
getEditLog().logAllocateBlockId(blockId);
|
|
|
// NB: callers sync the log
|
|
|
return blockId;
|