HDFS-7829. Code clean up for LocatedBlock. Contributed by Takanobu Asanuma.
This commit is contained in:
parent
6bc7710ec7
commit
a6a5aae472
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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>();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue