001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hdfs.server.datanode; 019 020import java.util.HashMap; 021import java.util.Map; 022import java.util.SortedSet; 023 024import org.apache.hadoop.classification.InterfaceAudience; 025import org.apache.hadoop.hdfs.protocol.LayoutVersion; 026import org.apache.hadoop.hdfs.protocol.LayoutVersion.FeatureInfo; 027import org.apache.hadoop.hdfs.protocol.LayoutVersion.LayoutFeature; 028 029@InterfaceAudience.Private 030public class DataNodeLayoutVersion { 031 /** Build layout version and corresponding feature matrix */ 032 public final static Map<Integer, SortedSet<LayoutFeature>> FEATURES = 033 new HashMap<Integer, SortedSet<LayoutFeature>>(); 034 035 public static final int CURRENT_LAYOUT_VERSION 036 = LayoutVersion.getCurrentLayoutVersion(Feature.values()); 037 038 static{ 039 LayoutVersion.updateMap(FEATURES, LayoutVersion.Feature.values()); 040 LayoutVersion.updateMap(FEATURES, DataNodeLayoutVersion.Feature.values()); 041 } 042 043 public static SortedSet<LayoutFeature> getFeatures(int lv) { 044 return FEATURES.get(lv); 045 } 046 047 public static boolean supports(final LayoutFeature f, final int lv) { 048 return LayoutVersion.supports(FEATURES, f, lv); 049 } 050 051 /** 052 * Enums for features that change the layout version. 053 * <br><br> 054 * To add a new layout version: 055 * <ul> 056 * <li>Define a new enum constant with a short enum name, the new layout version 057 * and description of the added feature.</li> 058 * <li>When adding a layout version with an ancestor that is not same as 059 * its immediate predecessor, use the constructor where a specific ancestor 060 * can be passed. 061 * </li> 062 * </ul> 063 */ 064 public static enum Feature implements LayoutFeature { 065 FIRST_LAYOUT(-55, -53, "First datanode layout", false), 066 BLOCKID_BASED_LAYOUT(-56, 067 "The block ID of a finalized block uniquely determines its position " + 068 "in the directory structure"), 069 BLOCKID_BASED_LAYOUT_32_by_32(-57, 070 "Identical to the block id based layout (-56) except it uses a smaller" 071 + " directory structure (32x32)"); 072 073 private final FeatureInfo info; 074 075 /** 076 * DataNodeFeature that is added at layout version {@code lv} - 1. 077 * @param lv new layout version with the addition of this feature 078 * @param description description of the feature 079 */ 080 Feature(final int lv, final String description) { 081 this(lv, lv + 1, description, false); 082 } 083 084 /** 085 * DataNode feature that is added at layout version {@code ancestoryLV}. 086 * @param lv new layout version with the addition of this feature 087 * @param ancestorLV layout version from which the new lv is derived from. 088 * @param description description of the feature 089 * @param reserved true when this is a layout version reserved for previous 090 * version 091 * @param features set of features that are to be enabled for this version 092 */ 093 Feature(final int lv, final int ancestorLV, final String description, 094 boolean reserved, Feature... features) { 095 info = new FeatureInfo(lv, ancestorLV, description, reserved, features); 096 } 097 098 @Override 099 public FeatureInfo getInfo() { 100 return info; 101 } 102 } 103}