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
DFSClient. (Zhihai Xu via Yongjun Zhang)
HDFS-7829. Code clean up for LocatedBlock. (Takanobu Asanuma via jing9)
OPTIMIZATIONS
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 final DatanodeInfoWithStorage[] locs;
/** Cached storage ID for each replica */
private String[] storageIDs;
private final String[] storageIDs;
/** 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.
// else false. If block has few corrupt replicas, they are filtered and
// their locations are not part of this object
@ -62,16 +62,8 @@ public class LocatedBlock {
new DatanodeInfoWithStorage[0];
public LocatedBlock(ExtendedBlock b, DatanodeInfo[] locs) {
this(b, locs, -1, false); // startOffset is unknown
}
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
// 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,
@ -170,11 +162,11 @@ public class LocatedBlock {
return b.getNumBytes();
}
void setStartOffset(long value) {
public void setStartOffset(long value) {
this.offset = value;
}
void setCorrupt(boolean corrupt) {
public void setCorrupt(boolean corrupt) {
this.corrupt = corrupt;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -99,11 +99,15 @@ public class TestDFSUtil {
// ok
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
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);
LocatedBlocks lbs = new LocatedBlocks(10, false, ls, l2, true, null);

View File

@ -478,10 +478,11 @@ public class TestPBHelper {
AdminStates.NORMAL)
};
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>(
"identifier".getBytes(), "password".getBytes(), new Text("kind"),
new Text("service")));
lb.setStartOffset(5);
return lb;
}