HDFS-4306. PBHelper.convertLocatedBlock miss convert BlockToken. Contributed by Binglin Chang.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1431117 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3cd17b614e
commit
3555e7c574
|
@ -679,6 +679,9 @@ Release 2.0.3-alpha - Unreleased
|
||||||
HDFS-3970. Fix bug causing rollback of HDFS upgrade to result in bad
|
HDFS-3970. Fix bug causing rollback of HDFS upgrade to result in bad
|
||||||
VERSION file. (Vinay and Andrew Wang via atm)
|
VERSION file. (Vinay and Andrew Wang via atm)
|
||||||
|
|
||||||
|
HDFS-4306. PBHelper.convertLocatedBlock miss convert BlockToken. (Binglin
|
||||||
|
Chang via atm)
|
||||||
|
|
||||||
BREAKDOWN OF HDFS-3077 SUBTASKS
|
BREAKDOWN OF HDFS-3077 SUBTASKS
|
||||||
|
|
||||||
HDFS-3077. Quorum-based protocol for reading and writing edit logs.
|
HDFS-3077. Quorum-based protocol for reading and writing edit logs.
|
||||||
|
|
|
@ -884,25 +884,14 @@ public class PBHelper {
|
||||||
// Located Block Arrays and Lists
|
// Located Block Arrays and Lists
|
||||||
public static LocatedBlockProto[] convertLocatedBlock(LocatedBlock[] lb) {
|
public static LocatedBlockProto[] convertLocatedBlock(LocatedBlock[] lb) {
|
||||||
if (lb == null) return null;
|
if (lb == null) return null;
|
||||||
final int len = lb.length;
|
return convertLocatedBlock2(Arrays.asList(lb)).toArray(
|
||||||
LocatedBlockProto[] result = new LocatedBlockProto[len];
|
new LocatedBlockProto[lb.length]);
|
||||||
for (int i = 0; i < len; ++i) {
|
|
||||||
result[i] = PBHelper.convert(lb[i]);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LocatedBlock[] convertLocatedBlock(LocatedBlockProto[] lb) {
|
public static LocatedBlock[] convertLocatedBlock(LocatedBlockProto[] lb) {
|
||||||
if (lb == null) return null;
|
if (lb == null) return null;
|
||||||
final int len = lb.length;
|
return convertLocatedBlock(Arrays.asList(lb)).toArray(
|
||||||
LocatedBlock[] result = new LocatedBlock[len];
|
new LocatedBlock[lb.length]);
|
||||||
for (int i = 0; i < len; ++i) {
|
|
||||||
result[i] = new LocatedBlock(
|
|
||||||
PBHelper.convert(lb[i].getB()),
|
|
||||||
PBHelper.convert(lb[i].getLocsList()),
|
|
||||||
lb[i].getOffset(), lb[i].getCorrupt());
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<LocatedBlock> convertLocatedBlock(
|
public static List<LocatedBlock> convertLocatedBlock(
|
||||||
|
|
|
@ -406,25 +406,69 @@ public class TestPBHelper {
|
||||||
assertEquals(expected.getService(), actual.getService());
|
assertEquals(expected.getService(), actual.getService());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private void compare(LocatedBlock expected, LocatedBlock actual) {
|
||||||
public void testConvertLocatedBlock() {
|
assertEquals(expected.getBlock(), actual.getBlock());
|
||||||
DatanodeInfo [] dnInfos = {
|
compare(expected.getBlockToken(), actual.getBlockToken());
|
||||||
DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h1", AdminStates.DECOMMISSION_INPROGRESS),
|
assertEquals(expected.getStartOffset(), actual.getStartOffset());
|
||||||
DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h2", AdminStates.DECOMMISSIONED),
|
assertEquals(expected.isCorrupt(), actual.isCorrupt());
|
||||||
DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h3", AdminStates.NORMAL)
|
DatanodeInfo [] ei = expected.getLocations();
|
||||||
|
DatanodeInfo [] ai = actual.getLocations();
|
||||||
|
assertEquals(ei.length, ai.length);
|
||||||
|
for (int i = 0; i < ei.length ; i++) {
|
||||||
|
compare(ei[i], ai[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private LocatedBlock createLocatedBlock() {
|
||||||
|
DatanodeInfo[] dnInfos = {
|
||||||
|
DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h1",
|
||||||
|
AdminStates.DECOMMISSION_INPROGRESS),
|
||||||
|
DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h2",
|
||||||
|
AdminStates.DECOMMISSIONED),
|
||||||
|
DFSTestUtil.getLocalDatanodeInfo("127.0.0.1", "h3",
|
||||||
|
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, 5, false);
|
||||||
|
lb.setBlockToken(new Token<BlockTokenIdentifier>(
|
||||||
|
"identifier".getBytes(), "password".getBytes(), new Text("kind"),
|
||||||
|
new Text("service")));
|
||||||
|
return lb;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConvertLocatedBlock() {
|
||||||
|
LocatedBlock lb = createLocatedBlock();
|
||||||
LocatedBlockProto lbProto = PBHelper.convert(lb);
|
LocatedBlockProto lbProto = PBHelper.convert(lb);
|
||||||
LocatedBlock lb2 = PBHelper.convert(lbProto);
|
LocatedBlock lb2 = PBHelper.convert(lbProto);
|
||||||
assertEquals(lb.getBlock(), lb2.getBlock());
|
compare(lb,lb2);
|
||||||
compare(lb.getBlockToken(), lb2.getBlockToken());
|
}
|
||||||
assertEquals(lb.getStartOffset(), lb2.getStartOffset());
|
|
||||||
assertEquals(lb.isCorrupt(), lb2.isCorrupt());
|
@Test
|
||||||
DatanodeInfo [] dnInfos2 = lb2.getLocations();
|
public void testConvertLocatedBlockList() {
|
||||||
assertEquals(dnInfos.length, dnInfos2.length);
|
ArrayList<LocatedBlock> lbl = new ArrayList<LocatedBlock>();
|
||||||
for (int i = 0; i < dnInfos.length ; i++) {
|
for (int i=0;i<3;i++) {
|
||||||
compare(dnInfos[i], dnInfos2[i]);
|
lbl.add(createLocatedBlock());
|
||||||
|
}
|
||||||
|
List<LocatedBlockProto> lbpl = PBHelper.convertLocatedBlock2(lbl);
|
||||||
|
List<LocatedBlock> lbl2 = PBHelper.convertLocatedBlock(lbpl);
|
||||||
|
assertEquals(lbl.size(), lbl2.size());
|
||||||
|
for (int i=0;i<lbl.size();i++) {
|
||||||
|
compare(lbl.get(i), lbl2.get(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConvertLocatedBlockArray() {
|
||||||
|
LocatedBlock [] lbl = new LocatedBlock[3];
|
||||||
|
for (int i=0;i<3;i++) {
|
||||||
|
lbl[i] = createLocatedBlock();
|
||||||
|
}
|
||||||
|
LocatedBlockProto [] lbpl = PBHelper.convertLocatedBlock(lbl);
|
||||||
|
LocatedBlock [] lbl2 = PBHelper.convertLocatedBlock(lbpl);
|
||||||
|
assertEquals(lbl.length, lbl2.length);
|
||||||
|
for (int i=0;i<lbl.length;i++) {
|
||||||
|
compare(lbl[i], lbl2[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue