public static void addDataNodeLayoutVersion(final int lv, final String description) throws NoSuchFieldException, IllegalAccessException { Preconditions.checkState(lv < DataNodeLayoutVersion.CURRENT_LAYOUT_VERSION); // Override {@link DataNodeLayoutVersion#CURRENT_LAYOUT_VERSION} via reflection. Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); Field field = DataNodeLayoutVersion.class.getField("CURRENT_LAYOUT_VERSION"); field.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.setInt(null, lv); // Override {@link HdfsConstants#DATANODE_LAYOUT_VERSION} field = HdfsConstants.class.getField("DATANODE_LAYOUT_VERSION"); field.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.setInt(null, lv); // Inject the feature into the FEATURES map. final LayoutVersion.FeatureInfo featureInfo = new LayoutVersion.FeatureInfo(lv, lv + 1, description, false); final LayoutVersion.LayoutFeature feature = new LayoutVersion.LayoutFeature() { @Override public LayoutVersion.FeatureInfo getInfo() { return featureInfo; } }; // Update the FEATURES map with the new layout version. LayoutVersion.updateMap(DataNodeLayoutVersion.FEATURES, new LayoutVersion.LayoutFeature[] { feature }); }
/** * 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()); }
public static void createBlockPoolVersionFile(File bpDir, StorageInfo version, String bpid) throws IOException { // Create block pool version files if (DataNodeLayoutVersion.supports( LayoutVersion.Feature.FEDERATION, version.layoutVersion)) { File bpCurDir = new File(bpDir, Storage.STORAGE_DIR_CURRENT); BlockPoolSliceStorage bpStorage = new BlockPoolSliceStorage(version, bpid); File versionFile = new File(bpCurDir, "VERSION"); StorageDirectory sd = new StorageDirectory(bpDir); bpStorage.writeProperties(versionFile, sd); } }
public static void addDataNodeLayoutVersion(final int lv, final String description) throws NoSuchFieldException, IllegalAccessException { Preconditions.checkState(lv < DataNodeLayoutVersion.CURRENT_LAYOUT_VERSION); // Override {@link DataNodeLayoutVersion#CURRENT_LAYOUT_VERSION} via reflection. Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); Field field = DataNodeLayoutVersion.class.getField("CURRENT_LAYOUT_VERSION"); field.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.setInt(null, lv); field = HdfsServerConstants.class.getField("DATANODE_LAYOUT_VERSION"); field.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.setInt(null, lv); // Inject the feature into the FEATURES map. final LayoutVersion.FeatureInfo featureInfo = new LayoutVersion.FeatureInfo(lv, lv + 1, description, false); final LayoutVersion.LayoutFeature feature = new LayoutVersion.LayoutFeature() { @Override public LayoutVersion.FeatureInfo getInfo() { return featureInfo; } }; // Update the FEATURES map with the new layout version. LayoutVersion.updateMap(DataNodeLayoutVersion.FEATURES, new LayoutVersion.LayoutFeature[] { feature }); }
public Map<Integer, SortedSet<LayoutFeature>> getServiceLayoutFeatureMap() { return storageType == NodeType.DATA_NODE? DataNodeLayoutVersion.FEATURES : NameNodeLayoutVersion.FEATURES; }