From 3555e7c574de5a6d163c5375a31de290776b2ab0 Mon Sep 17 00:00:00 2001 From: Aaron Myers Date: Wed, 9 Jan 2013 22:29:41 +0000 Subject: [PATCH] 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 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 + .../hadoop/hdfs/protocolPB/PBHelper.java | 19 +---- .../hadoop/hdfs/protocolPB/TestPBHelper.java | 74 +++++++++++++++---- 3 files changed, 66 insertions(+), 30 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 24707fdcc75..8e381dd686a 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -679,6 +679,9 @@ Release 2.0.3-alpha - Unreleased HDFS-3970. Fix bug causing rollback of HDFS upgrade to result in bad VERSION file. (Vinay and Andrew Wang via atm) + HDFS-4306. PBHelper.convertLocatedBlock miss convert BlockToken. (Binglin + Chang via atm) + BREAKDOWN OF HDFS-3077 SUBTASKS HDFS-3077. Quorum-based protocol for reading and writing edit logs. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelper.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelper.java index 1ef79b52c37..eec66821653 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelper.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocolPB/PBHelper.java @@ -884,25 +884,14 @@ public class PBHelper { // Located Block Arrays and Lists public static LocatedBlockProto[] convertLocatedBlock(LocatedBlock[] lb) { if (lb == null) return null; - final int len = lb.length; - LocatedBlockProto[] result = new LocatedBlockProto[len]; - for (int i = 0; i < len; ++i) { - result[i] = PBHelper.convert(lb[i]); - } - return result; + return convertLocatedBlock2(Arrays.asList(lb)).toArray( + new LocatedBlockProto[lb.length]); } public static LocatedBlock[] convertLocatedBlock(LocatedBlockProto[] lb) { if (lb == null) return null; - final int len = lb.length; - LocatedBlock[] result = new LocatedBlock[len]; - 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; + return convertLocatedBlock(Arrays.asList(lb)).toArray( + new LocatedBlock[lb.length]); } public static List convertLocatedBlock( diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocolPB/TestPBHelper.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocolPB/TestPBHelper.java index 23cd46e7323..b6c2f6ec29e 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocolPB/TestPBHelper.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocolPB/TestPBHelper.java @@ -405,29 +405,73 @@ public class TestPBHelper { assertEquals(expected.getKind(), actual.getKind()); assertEquals(expected.getService(), actual.getService()); } - - @Test - public void testConvertLocatedBlock() { - 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) + + private void compare(LocatedBlock expected, LocatedBlock actual) { + assertEquals(expected.getBlock(), actual.getBlock()); + compare(expected.getBlockToken(), actual.getBlockToken()); + assertEquals(expected.getStartOffset(), actual.getStartOffset()); + assertEquals(expected.isCorrupt(), actual.isCorrupt()); + 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( new ExtendedBlock("bp12", 12345, 10, 53), dnInfos, 5, false); + lb.setBlockToken(new Token( + "identifier".getBytes(), "password".getBytes(), new Text("kind"), + new Text("service"))); + return lb; + } + + @Test + public void testConvertLocatedBlock() { + LocatedBlock lb = createLocatedBlock(); LocatedBlockProto lbProto = PBHelper.convert(lb); LocatedBlock lb2 = PBHelper.convert(lbProto); - assertEquals(lb.getBlock(), lb2.getBlock()); - compare(lb.getBlockToken(), lb2.getBlockToken()); - assertEquals(lb.getStartOffset(), lb2.getStartOffset()); - assertEquals(lb.isCorrupt(), lb2.isCorrupt()); - DatanodeInfo [] dnInfos2 = lb2.getLocations(); - assertEquals(dnInfos.length, dnInfos2.length); - for (int i = 0; i < dnInfos.length ; i++) { - compare(dnInfos[i], dnInfos2[i]); + compare(lb,lb2); + } + + @Test + public void testConvertLocatedBlockList() { + ArrayList lbl = new ArrayList(); + for (int i=0;i<3;i++) { + lbl.add(createLocatedBlock()); + } + List lbpl = PBHelper.convertLocatedBlock2(lbl); + List lbl2 = PBHelper.convertLocatedBlock(lbpl); + assertEquals(lbl.size(), lbl2.size()); + for (int i=0;i