svn merge -c 1341141 from trunk for HDFS-3394. Do not use generic in INodeFile.getLastBlock(): the run-time ClassCastException check is useless since generic type information is only available in compile-time.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1341143 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1c65990dae
commit
8ba8542cde
|
@ -48,7 +48,11 @@ Release 2.0.1-alpha - UNRELEASED
|
||||||
(todd)
|
(todd)
|
||||||
|
|
||||||
HDFS-2885. Remove "federation" from the nameservice config options.
|
HDFS-2885. Remove "federation" from the nameservice config options.
|
||||||
(Tsz Wo (Nicholas) via eli)
|
(Tsz Wo (Nicholas) Sze via eli)
|
||||||
|
|
||||||
|
HDFS-3394. Do not use generic in INodeFile.getLastBlock(): the run-time
|
||||||
|
ClassCastException check is useless since generic type information is only
|
||||||
|
available in compile-time. (szetszwo)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,6 @@ package org.apache.hadoop.hdfs.server.blockmanagement;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoUnderConstruction;
|
|
||||||
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
|
|
||||||
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
|
|
||||||
import org.apache.hadoop.fs.ContentSummary;
|
import org.apache.hadoop.fs.ContentSummary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,19 +28,24 @@ import org.apache.hadoop.fs.ContentSummary;
|
||||||
public interface BlockCollection {
|
public interface BlockCollection {
|
||||||
/**
|
/**
|
||||||
* Get the last block of the collection.
|
* Get the last block of the collection.
|
||||||
* Make sure it has the right type.
|
|
||||||
*/
|
*/
|
||||||
public <T extends BlockInfo> T getLastBlock() throws IOException;
|
public BlockInfo getLastBlock() throws IOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get content summary.
|
* Get content summary.
|
||||||
*/
|
*/
|
||||||
public ContentSummary computeContentSummary();
|
public ContentSummary computeContentSummary();
|
||||||
|
|
||||||
/** @return the number of blocks */
|
/**
|
||||||
|
* @return the number of blocks
|
||||||
|
*/
|
||||||
public int numBlocks();
|
public int numBlocks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the blocks.
|
||||||
|
*/
|
||||||
public BlockInfo[] getBlocks();
|
public BlockInfo[] getBlocks();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get preferred block size for the collection
|
* Get preferred block size for the collection
|
||||||
* @return preferred block size in bytes
|
* @return preferred block size in bytes
|
||||||
|
@ -57,7 +59,7 @@ public interface BlockCollection {
|
||||||
public short getReplication();
|
public short getReplication();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get name of collection.
|
* Get the name of the collection.
|
||||||
*/
|
*/
|
||||||
public String getName();
|
public String getName();
|
||||||
}
|
}
|
||||||
|
|
|
@ -439,7 +439,7 @@ public class BlockManager {
|
||||||
* @throws IOException if the block does not have at least a minimal number
|
* @throws IOException if the block does not have at least a minimal number
|
||||||
* of replicas reported from data-nodes.
|
* of replicas reported from data-nodes.
|
||||||
*/
|
*/
|
||||||
private boolean commitBlock(final BlockInfoUnderConstruction block,
|
private static boolean commitBlock(final BlockInfoUnderConstruction block,
|
||||||
final Block commitBlock) throws IOException {
|
final Block commitBlock) throws IOException {
|
||||||
if (block.getBlockUCState() == BlockUCState.COMMITTED)
|
if (block.getBlockUCState() == BlockUCState.COMMITTED)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -19,26 +19,20 @@ package org.apache.hadoop.hdfs.server.blockmanagement;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
|
||||||
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoUnderConstruction;
|
|
||||||
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
|
|
||||||
import org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor;
|
|
||||||
import org.apache.hadoop.fs.ContentSummary;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface is used by the block manager to expose a
|
* This interface is used by the block manager to expose a
|
||||||
* few characteristics of a collection of Block/BlockUnderConstruction.
|
* few characteristics of a collection of Block/BlockUnderConstruction.
|
||||||
*/
|
*/
|
||||||
public interface MutableBlockCollection extends BlockCollection {
|
public interface MutableBlockCollection extends BlockCollection {
|
||||||
/**
|
/**
|
||||||
* Set block
|
* Set the block at the given index.
|
||||||
*/
|
*/
|
||||||
public void setBlock(int idx, BlockInfo blk);
|
public void setBlock(int index, BlockInfo blk);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the last block of the collection to an under-construction block.
|
* Convert the last block of the collection to an under-construction block
|
||||||
* Set its locations.
|
* and set the locations.
|
||||||
*/
|
*/
|
||||||
public BlockInfoUnderConstruction setLastBlock(BlockInfo lastBlock,
|
public BlockInfoUnderConstruction setLastBlock(BlockInfo lastBlock,
|
||||||
DatanodeDescriptor[] targets) throws IOException;
|
DatanodeDescriptor[] locations) throws IOException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2768,9 +2768,9 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
||||||
throw new IOException(message);
|
throw new IOException(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// no we know that the last block is not COMPLETE, and
|
// The last block is not COMPLETE, and
|
||||||
// that the penultimate block if exists is either COMPLETE or COMMITTED
|
// that the penultimate block if exists is either COMPLETE or COMMITTED
|
||||||
BlockInfoUnderConstruction lastBlock = pendingFile.getLastBlock();
|
final BlockInfo lastBlock = pendingFile.getLastBlock();
|
||||||
BlockUCState lastBlockState = lastBlock.getBlockUCState();
|
BlockUCState lastBlockState = lastBlock.getBlockUCState();
|
||||||
BlockInfo penultimateBlock = pendingFile.getPenultimateBlock();
|
BlockInfo penultimateBlock = pendingFile.getPenultimateBlock();
|
||||||
boolean penultimateBlockMinReplication;
|
boolean penultimateBlockMinReplication;
|
||||||
|
@ -2814,13 +2814,15 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
||||||
throw new AlreadyBeingCreatedException(message);
|
throw new AlreadyBeingCreatedException(message);
|
||||||
case UNDER_CONSTRUCTION:
|
case UNDER_CONSTRUCTION:
|
||||||
case UNDER_RECOVERY:
|
case UNDER_RECOVERY:
|
||||||
|
final BlockInfoUnderConstruction uc = (BlockInfoUnderConstruction)lastBlock;
|
||||||
// setup the last block locations from the blockManager if not known
|
// setup the last block locations from the blockManager if not known
|
||||||
if(lastBlock.getNumExpectedLocations() == 0)
|
if (uc.getNumExpectedLocations() == 0) {
|
||||||
lastBlock.setExpectedLocations(blockManager.getNodes(lastBlock));
|
uc.setExpectedLocations(blockManager.getNodes(lastBlock));
|
||||||
|
}
|
||||||
// start recovery of the last block for this file
|
// start recovery of the last block for this file
|
||||||
long blockRecoveryId = nextGenerationStamp();
|
long blockRecoveryId = nextGenerationStamp();
|
||||||
lease = reassignLease(lease, src, recoveryLeaseHolder, pendingFile);
|
lease = reassignLease(lease, src, recoveryLeaseHolder, pendingFile);
|
||||||
lastBlock.initializeBlockRecovery(blockRecoveryId);
|
uc.initializeBlockRecovery(blockRecoveryId);
|
||||||
leaseManager.renewLease(lease);
|
leaseManager.renewLease(lease);
|
||||||
// Cannot close file right now, since the last block requires recovery.
|
// Cannot close file right now, since the last block requires recovery.
|
||||||
// This may potentially cause infinite loop in lease recovery
|
// This may potentially cause infinite loop in lease recovery
|
||||||
|
@ -4557,15 +4559,16 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
||||||
LOG.info("updatePipeline(" + oldBlock + ") successfully to " + newBlock);
|
LOG.info("updatePipeline(" + oldBlock + ") successfully to " + newBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @see updatePipeline(String, ExtendedBlock, ExtendedBlock, DatanodeID[]) */
|
/** @see #updatePipeline(String, ExtendedBlock, ExtendedBlock, DatanodeID[]) */
|
||||||
private void updatePipelineInternal(String clientName, ExtendedBlock oldBlock,
|
private void updatePipelineInternal(String clientName, ExtendedBlock oldBlock,
|
||||||
ExtendedBlock newBlock, DatanodeID[] newNodes)
|
ExtendedBlock newBlock, DatanodeID[] newNodes)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
assert hasWriteLock();
|
assert hasWriteLock();
|
||||||
// check the vadility of the block and lease holder name
|
// check the vadility of the block and lease holder name
|
||||||
final INodeFileUnderConstruction pendingFile =
|
final INodeFileUnderConstruction pendingFile
|
||||||
checkUCBlock(oldBlock, clientName);
|
= checkUCBlock(oldBlock, clientName);
|
||||||
final BlockInfoUnderConstruction blockinfo = pendingFile.getLastBlock();
|
final BlockInfoUnderConstruction blockinfo
|
||||||
|
= (BlockInfoUnderConstruction)pendingFile.getLastBlock();
|
||||||
|
|
||||||
// check new GS & length: this is not expected
|
// check new GS & length: this is not expected
|
||||||
if (newBlock.getGenerationStamp() <= blockinfo.getGenerationStamp() ||
|
if (newBlock.getGenerationStamp() <= blockinfo.getGenerationStamp() ||
|
||||||
|
|
|
@ -177,14 +177,14 @@ abstract class INode implements Comparable<byte[]> {
|
||||||
return (short)PermissionStatusFormat.MODE.retrieve(permission);
|
return (short)PermissionStatusFormat.MODE.retrieve(permission);
|
||||||
}
|
}
|
||||||
/** Set the {@link FsPermission} of this {@link INode} */
|
/** Set the {@link FsPermission} of this {@link INode} */
|
||||||
protected void setPermission(FsPermission permission) {
|
void setPermission(FsPermission permission) {
|
||||||
updatePermissionStatus(PermissionStatusFormat.MODE, permission.toShort());
|
updatePermissionStatus(PermissionStatusFormat.MODE, permission.toShort());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether it's a directory
|
* Check whether it's a directory
|
||||||
*/
|
*/
|
||||||
public abstract boolean isDirectory();
|
abstract boolean isDirectory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collect all the blocks in all children of this INode.
|
* Collect all the blocks in all children of this INode.
|
||||||
|
|
|
@ -41,9 +41,9 @@ public class INodeFile extends INode implements BlockCollection {
|
||||||
//Format: [16 bits for replication][48 bits for PreferredBlockSize]
|
//Format: [16 bits for replication][48 bits for PreferredBlockSize]
|
||||||
static final long HEADERMASK = 0xffffL << BLOCKBITS;
|
static final long HEADERMASK = 0xffffL << BLOCKBITS;
|
||||||
|
|
||||||
protected long header;
|
private long header;
|
||||||
|
|
||||||
protected BlockInfo blocks[] = null;
|
BlockInfo blocks[] = null;
|
||||||
|
|
||||||
INodeFile(PermissionStatus permissions,
|
INodeFile(PermissionStatus permissions,
|
||||||
int nrBlocks, short replication, long modificationTime,
|
int nrBlocks, short replication, long modificationTime,
|
||||||
|
@ -52,12 +52,7 @@ public class INodeFile extends INode implements BlockCollection {
|
||||||
modificationTime, atime, preferredBlockSize);
|
modificationTime, atime, preferredBlockSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected INodeFile() {
|
INodeFile(PermissionStatus permissions, BlockInfo[] blklist,
|
||||||
blocks = null;
|
|
||||||
header = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected INodeFile(PermissionStatus permissions, BlockInfo[] blklist,
|
|
||||||
short replication, long modificationTime,
|
short replication, long modificationTime,
|
||||||
long atime, long preferredBlockSize) {
|
long atime, long preferredBlockSize) {
|
||||||
super(permissions, modificationTime, atime);
|
super(permissions, modificationTime, atime);
|
||||||
|
@ -71,47 +66,40 @@ public class INodeFile extends INode implements BlockCollection {
|
||||||
* Since this is a file,
|
* Since this is a file,
|
||||||
* the {@link FsAction#EXECUTE} action, if any, is ignored.
|
* the {@link FsAction#EXECUTE} action, if any, is ignored.
|
||||||
*/
|
*/
|
||||||
protected void setPermission(FsPermission permission) {
|
void setPermission(FsPermission permission) {
|
||||||
super.setPermission(permission.applyUMask(UMASK));
|
super.setPermission(permission.applyUMask(UMASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDirectory() {
|
boolean isDirectory() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @return the replication factor of the file. */
|
||||||
* Get block replication for the file
|
@Override
|
||||||
* @return block replication value
|
|
||||||
*/
|
|
||||||
public short getReplication() {
|
public short getReplication() {
|
||||||
return (short) ((header & HEADERMASK) >> BLOCKBITS);
|
return (short) ((header & HEADERMASK) >> BLOCKBITS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReplication(short replication) {
|
void setReplication(short replication) {
|
||||||
if(replication <= 0)
|
if(replication <= 0)
|
||||||
throw new IllegalArgumentException("Unexpected value for the replication");
|
throw new IllegalArgumentException("Unexpected value for the replication");
|
||||||
header = ((long)replication << BLOCKBITS) | (header & ~HEADERMASK);
|
header = ((long)replication << BLOCKBITS) | (header & ~HEADERMASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @return preferred block size (in bytes) of the file. */
|
||||||
* Get preferred block size for the file
|
@Override
|
||||||
* @return preferred block size in bytes
|
|
||||||
*/
|
|
||||||
public long getPreferredBlockSize() {
|
public long getPreferredBlockSize() {
|
||||||
return header & ~HEADERMASK;
|
return header & ~HEADERMASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreferredBlockSize(long preferredBlkSize)
|
private void setPreferredBlockSize(long preferredBlkSize) {
|
||||||
{
|
|
||||||
if((preferredBlkSize < 0) || (preferredBlkSize > ~HEADERMASK ))
|
if((preferredBlkSize < 0) || (preferredBlkSize > ~HEADERMASK ))
|
||||||
throw new IllegalArgumentException("Unexpected value for the block size");
|
throw new IllegalArgumentException("Unexpected value for the block size");
|
||||||
header = (header & HEADERMASK) | (preferredBlkSize & ~HEADERMASK);
|
header = (header & HEADERMASK) | (preferredBlkSize & ~HEADERMASK);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** @return the blocks of the file. */
|
||||||
* Get file blocks
|
@Override
|
||||||
* @return file blocks
|
|
||||||
*/
|
|
||||||
public BlockInfo[] getBlocks() {
|
public BlockInfo[] getBlocks() {
|
||||||
return this.blocks;
|
return this.blocks;
|
||||||
}
|
}
|
||||||
|
@ -152,9 +140,7 @@ public class INodeFile extends INode implements BlockCollection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Set the block of the file at the given index. */
|
||||||
* Set file block
|
|
||||||
*/
|
|
||||||
public void setBlock(int idx, BlockInfo blk) {
|
public void setBlock(int idx, BlockInfo blk) {
|
||||||
this.blocks[idx] = blk;
|
this.blocks[idx] = blk;
|
||||||
}
|
}
|
||||||
|
@ -171,6 +157,7 @@ public class INodeFile extends INode implements BlockCollection {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
// Get the full path name of this inode.
|
// Get the full path name of this inode.
|
||||||
return getFullPathName();
|
return getFullPathName();
|
||||||
|
@ -215,7 +202,7 @@ public class INodeFile extends INode implements BlockCollection {
|
||||||
return diskspaceConsumed(blocks);
|
return diskspaceConsumed(blocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
long diskspaceConsumed(Block[] blkArr) {
|
private long diskspaceConsumed(Block[] blkArr) {
|
||||||
long size = 0;
|
long size = 0;
|
||||||
if(blkArr == null)
|
if(blkArr == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -245,26 +232,12 @@ public class INodeFile extends INode implements BlockCollection {
|
||||||
return blocks[blocks.length - 2];
|
return blocks[blocks.length - 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Get the last block of the file.
|
public BlockInfo getLastBlock() throws IOException {
|
||||||
* Make sure it has the right type.
|
return blocks == null || blocks.length == 0? null: blocks[blocks.length-1];
|
||||||
*/
|
|
||||||
public <T extends BlockInfo> T getLastBlock() throws IOException {
|
|
||||||
if (blocks == null || blocks.length == 0)
|
|
||||||
return null;
|
|
||||||
T returnBlock = null;
|
|
||||||
try {
|
|
||||||
@SuppressWarnings("unchecked") // ClassCastException is caught below
|
|
||||||
T tBlock = (T)blocks[blocks.length - 1];
|
|
||||||
returnBlock = tBlock;
|
|
||||||
} catch(ClassCastException cce) {
|
|
||||||
throw new IOException("Unexpected last block type: "
|
|
||||||
+ blocks[blocks.length - 1].getClass().getSimpleName());
|
|
||||||
}
|
|
||||||
return returnBlock;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return the number of blocks */
|
@Override
|
||||||
public int numBlocks() {
|
public int numBlocks() {
|
||||||
return blocks == null ? 0 : blocks.length;
|
return blocks == null ? 0 : blocks.length;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue