Search in sources :

Example 1 with LayoutFeature

use of org.apache.hadoop.hdfs.protocol.LayoutVersion.LayoutFeature in project hadoop by apache.

the class TestLayoutVersion method testNameNodeFeatureMinimumCompatibleLayoutVersions.

/**
   * Tests expected values for minimum compatible layout version in NameNode
   * features.  TRUNCATE, APPEND_NEW_BLOCK and QUOTA_BY_STORAGE_TYPE are all
   * features that launched in the same release.  TRUNCATE was added first, so
   * we expect all 3 features to have a minimum compatible layout version equal
   * to TRUNCATE's layout version.  All features older than that existed prior
   * to the concept of a minimum compatible layout version, so for each one, the
   * minimum compatible layout version must be equal to itself.
   */
@Test
public void testNameNodeFeatureMinimumCompatibleLayoutVersions() {
    int baseLV = NameNodeLayoutVersion.Feature.TRUNCATE.getInfo().getLayoutVersion();
    EnumSet<NameNodeLayoutVersion.Feature> compatibleFeatures = EnumSet.of(NameNodeLayoutVersion.Feature.TRUNCATE, NameNodeLayoutVersion.Feature.APPEND_NEW_BLOCK, NameNodeLayoutVersion.Feature.QUOTA_BY_STORAGE_TYPE, NameNodeLayoutVersion.Feature.ERASURE_CODING);
    for (LayoutFeature f : compatibleFeatures) {
        assertEquals(String.format("Expected minimum compatible layout version " + "%d for feature %s.", baseLV, f), baseLV, f.getInfo().getMinimumCompatibleLayoutVersion());
    }
    List<LayoutFeature> features = new ArrayList<>();
    features.addAll(EnumSet.allOf(LayoutVersion.Feature.class));
    features.addAll(EnumSet.allOf(NameNodeLayoutVersion.Feature.class));
    for (LayoutFeature f : features) {
        if (!compatibleFeatures.contains(f)) {
            assertEquals(String.format("Expected feature %s to have minimum " + "compatible layout version set to itself.", f), f.getInfo().getLayoutVersion(), f.getInfo().getMinimumCompatibleLayoutVersion());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) LayoutFeature(org.apache.hadoop.hdfs.protocol.LayoutVersion.LayoutFeature) Feature(org.apache.hadoop.hdfs.protocol.LayoutVersion.Feature) LayoutFeature(org.apache.hadoop.hdfs.protocol.LayoutVersion.LayoutFeature) Test(org.junit.Test)

Example 2 with LayoutFeature

use of org.apache.hadoop.hdfs.protocol.LayoutVersion.LayoutFeature in project hadoop by apache.

the class TestLayoutVersion method testNameNodeFeature.

/**
   * Test to make sure NameNode.Feature support previous features
   */
@Test
public void testNameNodeFeature() {
    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());
}
Also used : LayoutFeature(org.apache.hadoop.hdfs.protocol.LayoutVersion.LayoutFeature) Test(org.junit.Test)

Example 3 with LayoutFeature

use of org.apache.hadoop.hdfs.protocol.LayoutVersion.LayoutFeature in project hadoop by apache.

the class TestLayoutVersion method testNameNodeFeatureMinimumCompatibleLayoutVersionOutOfOrder.

/**
   * Tests that attempting to add a new NameNode feature out of order with
   * respect to minimum compatible layout version will fail fast.
   */
@Test(expected = AssertionError.class)
public void testNameNodeFeatureMinimumCompatibleLayoutVersionOutOfOrder() {
    FeatureInfo ancestorF = LayoutVersion.Feature.RESERVED_REL2_4_0.getInfo();
    LayoutFeature f = mock(LayoutFeature.class);
    when(f.getInfo()).thenReturn(new FeatureInfo(ancestorF.getLayoutVersion() - 1, ancestorF.getLayoutVersion(), ancestorF.getMinimumCompatibleLayoutVersion() + 1, "Invalid feature.", false));
    Map<Integer, SortedSet<LayoutFeature>> features = new HashMap<>();
    LayoutVersion.updateMap(features, LayoutVersion.Feature.values());
    LayoutVersion.updateMap(features, new LayoutFeature[] { f });
}
Also used : HashMap(java.util.HashMap) FeatureInfo(org.apache.hadoop.hdfs.protocol.LayoutVersion.FeatureInfo) LayoutFeature(org.apache.hadoop.hdfs.protocol.LayoutVersion.LayoutFeature) SortedSet(java.util.SortedSet) Test(org.junit.Test)

Example 4 with LayoutFeature

use of org.apache.hadoop.hdfs.protocol.LayoutVersion.LayoutFeature in project hadoop by apache.

the class TestLayoutVersion method validateFeatureList.

/**
   * Given feature {@code f}, ensures the layout version of that feature
   * supports all the features supported by it's ancestor.
   */
private void validateFeatureList(LayoutFeature f) {
    final FeatureInfo info = f.getInfo();
    int lv = info.getLayoutVersion();
    int ancestorLV = info.getAncestorLayoutVersion();
    SortedSet<LayoutFeature> ancestorSet = NameNodeLayoutVersion.getFeatures(ancestorLV);
    assertNotNull(ancestorSet);
    for (LayoutFeature feature : ancestorSet) {
        assertTrue("LV " + lv + " does nto support " + feature + " supported by the ancestor LV " + info.getAncestorLayoutVersion(), NameNodeLayoutVersion.supports(feature, lv));
    }
}
Also used : FeatureInfo(org.apache.hadoop.hdfs.protocol.LayoutVersion.FeatureInfo) LayoutFeature(org.apache.hadoop.hdfs.protocol.LayoutVersion.LayoutFeature)

Example 5 with LayoutFeature

use of org.apache.hadoop.hdfs.protocol.LayoutVersion.LayoutFeature in project hadoop by apache.

the class TestLayoutVersion method testDataNodeFeature.

/**
   * Test to make sure DataNode.Feature support previous features
   */
@Test
public void testDataNodeFeature() {
    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());
}
Also used : LayoutFeature(org.apache.hadoop.hdfs.protocol.LayoutVersion.LayoutFeature) Test(org.junit.Test)

Aggregations

LayoutFeature (org.apache.hadoop.hdfs.protocol.LayoutVersion.LayoutFeature)5 Test (org.junit.Test)4 FeatureInfo (org.apache.hadoop.hdfs.protocol.LayoutVersion.FeatureInfo)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 SortedSet (java.util.SortedSet)1 Feature (org.apache.hadoop.hdfs.protocol.LayoutVersion.Feature)1