HDFS-7829. Code clean up for LocatedBlock. Contributed by Takanobu Asanuma.

This commit is contained in:
Jing Zhao 2015-03-20 10:50:03 -07:00
parent 6bc7710ec7
commit a6a5aae472
8 changed files with 22 additions and 24 deletions

View File

@ -326,6 +326,8 @@ Release 2.8.0 - UNRELEASED
HDFS-7835. make initial sleeptime in locateFollowingBlock configurable for HDFS-7835. make initial sleeptime in locateFollowingBlock configurable for
DFSClient. (Zhihai Xu via Yongjun Zhang) DFSClient. (Zhihai Xu via Yongjun Zhang)
HDFS-7829. Code clean up for LocatedBlock. (Takanobu Asanuma via jing9)
OPTIMIZATIONS OPTIMIZATIONS
BUG FIXES BUG FIXES

View File

@ -44,9 +44,9 @@ public class LocatedBlock {
private long offset; // offset of the first byte of the block in the file private long offset; // offset of the first byte of the block in the file
private final DatanodeInfoWithStorage[] locs; private final DatanodeInfoWithStorage[] locs;
/** Cached storage ID for each replica */ /** Cached storage ID for each replica */
private String[] storageIDs; private final String[] storageIDs;
/** Cached storage type for each replica, if reported. */ /** Cached storage type for each replica, if reported. */
private StorageType[] storageTypes; private final StorageType[] storageTypes;
// corrupt flag is true if all of the replicas of a block are corrupt. // corrupt flag is true if all of the replicas of a block are corrupt.
// else false. If block has few corrupt replicas, they are filtered and // else false. If block has few corrupt replicas, they are filtered and
// their locations are not part of this object // their locations are not part of this object
@ -62,16 +62,8 @@ public class LocatedBlock {
new DatanodeInfoWithStorage[0]; new DatanodeInfoWithStorage[0];
public LocatedBlock(ExtendedBlock b, DatanodeInfo[] locs) { public LocatedBlock(ExtendedBlock b, DatanodeInfo[] locs) {
this(b, locs, -1, false); // startOffset is unknown // By default, startOffset is unknown(-1) and corrupt is false.
} this(b, locs, null, null, -1, false, EMPTY_LOCS);
public LocatedBlock(ExtendedBlock b, DatanodeInfo[] locs, long startOffset,
boolean corrupt) {
this(b, locs, null, null, startOffset, corrupt, EMPTY_LOCS);
}
public LocatedBlock(ExtendedBlock b, DatanodeStorageInfo[] storages) {
this(b, storages, -1, false); // startOffset is unknown
} }
public LocatedBlock(ExtendedBlock b, DatanodeInfo[] locs, public LocatedBlock(ExtendedBlock b, DatanodeInfo[] locs,
@ -170,11 +162,11 @@ public class LocatedBlock {
return b.getNumBytes(); return b.getNumBytes();
} }
void setStartOffset(long value) { public void setStartOffset(long value) {
this.offset = value; this.offset = value;
} }
void setCorrupt(boolean corrupt) { public void setCorrupt(boolean corrupt) {
this.corrupt = corrupt; this.corrupt = corrupt;
} }

View File

@ -119,7 +119,7 @@ public class LocatedBlocks {
public int findBlock(long offset) { public int findBlock(long offset) {
// create fake block of size 0 as a key // create fake block of size 0 as a key
LocatedBlock key = new LocatedBlock( LocatedBlock key = new LocatedBlock(
new ExtendedBlock(), new DatanodeInfo[0], 0L, false); new ExtendedBlock(), new DatanodeInfo[0]);
key.setStartOffset(offset); key.setStartOffset(offset);
key.getBlock().setNumBytes(1); key.getBlock().setNumBytes(1);
Comparator<LocatedBlock> comp = Comparator<LocatedBlock> comp =

View File

@ -3292,7 +3292,7 @@ public class FSNamesystem implements Namesystem, FSNamesystemMBean,
final DatanodeStorageInfo[] targets = blockManager.chooseTarget4AdditionalDatanode( final DatanodeStorageInfo[] targets = blockManager.chooseTarget4AdditionalDatanode(
src, numAdditionalNodes, clientnode, chosen, src, numAdditionalNodes, clientnode, chosen,
excludes, preferredblocksize, storagePolicyID); excludes, preferredblocksize, storagePolicyID);
final LocatedBlock lb = new LocatedBlock(blk, targets); final LocatedBlock lb = new LocatedBlock(blk, targets, -1, false);
blockManager.setBlockToken(lb, AccessMode.COPY); blockManager.setBlockToken(lb, AccessMode.COPY);
return lb; return lb;
} }

View File

@ -61,7 +61,7 @@ public class BlockRecoveryCommand extends DatanodeCommand {
* Create RecoveringBlock. * Create RecoveringBlock.
*/ */
public RecoveringBlock(ExtendedBlock b, DatanodeInfo[] locs, long newGS) { public RecoveringBlock(ExtendedBlock b, DatanodeInfo[] locs, long newGS) {
super(b, locs, -1, false); // startOffset is unknown super(b, locs); // startOffset is unknown
this.newGenerationStamp = newGS; this.newGenerationStamp = newGS;
this.recoveryBlock = null; this.recoveryBlock = null;
} }
@ -71,7 +71,7 @@ public class BlockRecoveryCommand extends DatanodeCommand {
*/ */
public RecoveringBlock(ExtendedBlock b, DatanodeInfo[] locs, public RecoveringBlock(ExtendedBlock b, DatanodeInfo[] locs,
Block recoveryBlock) { Block recoveryBlock) {
super(b, locs, -1, false); // startOffset is unknown super(b, locs); // startOffset is unknown
this.newGenerationStamp = recoveryBlock.getGenerationStamp(); this.newGenerationStamp = recoveryBlock.getGenerationStamp();
this.recoveryBlock = recoveryBlock; this.recoveryBlock = recoveryBlock;
} }

View File

@ -489,9 +489,8 @@ public class TestDFSClientRetries {
goodLocatedBlock.getBlock(), goodLocatedBlock.getBlock(),
new DatanodeInfo[] { new DatanodeInfo[] {
DFSTestUtil.getDatanodeInfo("1.2.3.4", "bogus", 1234) DFSTestUtil.getDatanodeInfo("1.2.3.4", "bogus", 1234)
}, });
goodLocatedBlock.getStartOffset(), badLocatedBlock.setStartOffset(goodLocatedBlock.getStartOffset());
false);
List<LocatedBlock> badBlocks = new ArrayList<LocatedBlock>(); List<LocatedBlock> badBlocks = new ArrayList<LocatedBlock>();

View File

@ -99,11 +99,15 @@ public class TestDFSUtil {
// ok // ok
ExtendedBlock b1 = new ExtendedBlock("bpid", 1, 1, 1); ExtendedBlock b1 = new ExtendedBlock("bpid", 1, 1, 1);
LocatedBlock l1 = new LocatedBlock(b1, ds, 0, false); LocatedBlock l1 = new LocatedBlock(b1, ds);
l1.setStartOffset(0);
l1.setCorrupt(false);
// corrupt // corrupt
ExtendedBlock b2 = new ExtendedBlock("bpid", 2, 1, 1); ExtendedBlock b2 = new ExtendedBlock("bpid", 2, 1, 1);
LocatedBlock l2 = new LocatedBlock(b2, ds, 0, true); LocatedBlock l2 = new LocatedBlock(b2, ds);
l2.setStartOffset(0);
l2.setCorrupt(true);
List<LocatedBlock> ls = Arrays.asList(l1, l2); List<LocatedBlock> ls = Arrays.asList(l1, l2);
LocatedBlocks lbs = new LocatedBlocks(10, false, ls, l2, true, null); LocatedBlocks lbs = new LocatedBlocks(10, false, ls, l2, true, null);

View File

@ -478,10 +478,11 @@ public class TestPBHelper {
AdminStates.NORMAL) AdminStates.NORMAL)
}; };
LocatedBlock lb = new LocatedBlock( LocatedBlock lb = new LocatedBlock(
new ExtendedBlock("bp12", 12345, 10, 53), dnInfos, 5, false); new ExtendedBlock("bp12", 12345, 10, 53), dnInfos);
lb.setBlockToken(new Token<BlockTokenIdentifier>( lb.setBlockToken(new Token<BlockTokenIdentifier>(
"identifier".getBytes(), "password".getBytes(), new Text("kind"), "identifier".getBytes(), "password".getBytes(), new Text("kind"),
new Text("service"))); new Text("service")));
lb.setStartOffset(5);
return lb; return lb;
} }