From d69985d90b9349228ab30622073c388dba296698 Mon Sep 17 00:00:00 2001 From: Tsz-wo Sze Date: Wed, 19 Feb 2014 21:40:42 +0000 Subject: [PATCH] HDFS-5974. Fix compilation error, NameNodeLayoutVersion and DataNodeLayoutVersion after merge from trunk. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-5535@1569931 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-hdfs/CHANGES_HDFS-5535.txt | 3 +++ .../hadoop/hdfs/protocol/LayoutVersion.java | 14 +++++++----- .../datanode/DataNodeLayoutVersion.java | 4 ++-- .../hdfs/server/namenode/FSEditLogOp.java | 3 ++- .../namenode/NameNodeLayoutVersion.java | 4 ++-- .../hdfs/protocol/TestLayoutVersion.java | 22 +++++++++++++++---- 6 files changed, 35 insertions(+), 15 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt index 3d76beed9c..a34668d162 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES_HDFS-5535.txt @@ -49,3 +49,6 @@ HDFS-5535 subtasks: HDFS-5966. Fix rollback of rolling upgrade in NameNode HA setup. (jing9 via szetszwo) + + HDFS-5974. Fix compilation error, NameNodeLayoutVersion and + DataNodeLayoutVersion after merge from trunk. (szetszwo) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/LayoutVersion.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/LayoutVersion.java index e15c32deb2..760db980d9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/LayoutVersion.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/protocol/LayoutVersion.java @@ -44,7 +44,6 @@ */ @InterfaceAudience.Private public class LayoutVersion { - /** * Version in which HDFS-2991 was fixed. This bug caused OP_ADD to * sometimes be skipped for append() calls. If we see such a case when @@ -279,12 +278,15 @@ public static boolean supports(Map> map, /** * Get the current layout version */ - public static int getCurrentLayoutVersion( - Map> map, LayoutFeature[] values) { - for (int i = values.length -1; i >= 0; i--) { - final FeatureInfo info = values[i].getInfo(); + public static int getCurrentLayoutVersion(LayoutFeature[] features) { + return getLastNonReservedFeature(features).getInfo().getLayoutVersion(); + } + + static LayoutFeature getLastNonReservedFeature(LayoutFeature[] features) { + for (int i = features.length -1; i >= 0; i--) { + final FeatureInfo info = features[i].getInfo(); if (!info.isReservedForOldRelease()) { - return info.getLayoutVersion(); + return features[i]; } } throw new AssertionError("All layout versions are reserved."); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNodeLayoutVersion.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNodeLayoutVersion.java index e09bc08983..ee0999e0be 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNodeLayoutVersion.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNodeLayoutVersion.java @@ -33,7 +33,7 @@ public class DataNodeLayoutVersion { new HashMap>(); public static final int CURRENT_LAYOUT_VERSION - = LayoutVersion.getCurrentLayoutVersion(FEATURES, Feature.values()); + = LayoutVersion.getCurrentLayoutVersion(Feature.values()); static{ LayoutVersion.updateMap(FEATURES, LayoutVersion.Feature.values()); @@ -62,7 +62,7 @@ public static boolean supports(final LayoutFeature f, final int lv) { * */ public static enum Feature implements LayoutFeature { - FIRST_LAYOUT(-52, "First datenode layout"); + FIRST_LAYOUT(-55, -53, "First datenode layout", false); private final FeatureInfo info; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java index f4cc2f499d..43a725ccfb 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java @@ -93,6 +93,7 @@ import org.apache.hadoop.hdfs.protocol.ClientProtocol; import org.apache.hadoop.hdfs.protocol.HdfsConstants; import org.apache.hadoop.hdfs.protocol.LayoutVersion; +import org.apache.hadoop.hdfs.protocol.LayoutVersion.Feature; import org.apache.hadoop.hdfs.protocol.proto.AclProtos.AclEditLogProto; import org.apache.hadoop.hdfs.protocolPB.PBHelper; import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier; @@ -319,7 +320,7 @@ private static final class AclEditLogUtil { private static List read(DataInputStream in, int logVersion) throws IOException { - if (!LayoutVersion.supports(Feature.EXTENDED_ACL, logVersion)) { + if (!NameNodeLayoutVersion.supports(Feature.EXTENDED_ACL, logVersion)) { return null; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeLayoutVersion.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeLayoutVersion.java index 6970f7cda4..0dac520d27 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeLayoutVersion.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeLayoutVersion.java @@ -34,7 +34,7 @@ public class NameNodeLayoutVersion { = new HashMap>(); public static final int CURRENT_LAYOUT_VERSION - = LayoutVersion.getCurrentLayoutVersion(FEATURES, Feature.values()); + = LayoutVersion.getCurrentLayoutVersion(Feature.values()); static { LayoutVersion.updateMap(FEATURES, LayoutVersion.Feature.values()); @@ -63,7 +63,7 @@ public static boolean supports(final LayoutFeature f, final int lv) { * */ public static enum Feature implements LayoutFeature { - ROLLING_UPGRADE(-52, "Support rolling upgrade"); + ROLLING_UPGRADE(-55, -53, "Support rolling upgrade", false); private final FeatureInfo info; diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/TestLayoutVersion.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/TestLayoutVersion.java index e6e05ad44d..dbd96bb610 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/TestLayoutVersion.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/protocol/TestLayoutVersion.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; import java.util.SortedSet; @@ -33,6 +34,13 @@ * Test for {@link LayoutVersion} */ public class TestLayoutVersion { + public static final LayoutFeature LAST_NON_RESERVED_COMMON_FEATURE; + public static final LayoutFeature LAST_COMMON_FEATURE; + static { + final Feature[] features = Feature.values(); + LAST_COMMON_FEATURE = features[features.length - 1]; + LAST_NON_RESERVED_COMMON_FEATURE = LayoutVersion.getLastNonReservedFeature(features); + } /** * Tests to make sure a given layout version supports all the @@ -77,8 +85,11 @@ public void testRelease1_2_0() { */ @Test public void testNameNodeFeature() { - assertTrue(NameNodeLayoutVersion.supports(LayoutVersion.Feature.CACHING, - NameNodeLayoutVersion.Feature.ROLLING_UPGRADE.getInfo().getLayoutVersion())); + final LayoutFeature first = NameNodeLayoutVersion.Feature.ROLLING_UPGRADE; + assertTrue(NameNodeLayoutVersion.supports(LAST_NON_RESERVED_COMMON_FEATURE, + first.getInfo().getLayoutVersion())); + assertEquals(LAST_COMMON_FEATURE.getInfo().getLayoutVersion() - 1, + first.getInfo().getLayoutVersion()); } /** @@ -86,8 +97,11 @@ public void testNameNodeFeature() { */ @Test public void testDataNodeFeature() { - assertTrue(DataNodeLayoutVersion.supports(LayoutVersion.Feature.CACHING, - DataNodeLayoutVersion.Feature.FIRST_LAYOUT.getInfo().getLayoutVersion())); + final LayoutFeature first = DataNodeLayoutVersion.Feature.FIRST_LAYOUT; + assertTrue(DataNodeLayoutVersion.supports(LAST_NON_RESERVED_COMMON_FEATURE, + first.getInfo().getLayoutVersion())); + assertEquals(LAST_COMMON_FEATURE.getInfo().getLayoutVersion() - 1, + first.getInfo().getLayoutVersion()); } /**