Skip to content

Commit

Permalink
HDFS-7829. Code clean up for LocatedBlock. Contributed by Takanobu As…
Browse files Browse the repository at this point in the history
…anuma.
  • Loading branch information
Jing9 committed Mar 20, 2015
1 parent 6bc7710 commit a6a5aae
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 24 deletions.
2 changes: 2 additions & 0 deletions hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -170,11 +162,11 @@ public long getBlockSize() {
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public FileEncryptionInfo getFileEncryptionInfo() {
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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3292,7 +3292,7 @@ LocatedBlock getAdditionalDatanode(String src, long fileId,
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static class RecoveringBlock extends LocatedBlock {
* 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;
}
Expand All @@ -71,7 +71,7 @@ public RecoveringBlock(ExtendedBlock b, DatanodeInfo[] locs, long newGS) {
*/
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,8 @@ private LocatedBlocks makeBadBlockList(LocatedBlocks goodBlockList) {
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>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,15 @@ public void testLocatedBlocks2Locations() {

// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,11 @@ private LocatedBlock createLocatedBlockNoStorageMedia() {
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;
}

Expand Down

0 comments on commit a6a5aae

Please sign in to comment.