第三章:小朱笔记hadoop之conf分析 -Reconfigurable相关
集群运行过程中有时会需要对配置进行修改,而通常需要重启才能生效,如该HDFS Namenode的一个配置,需要重启NN才能生效。而对于规模较大的系统,重启的成本较高。所以引入了一个reconfigurable机制。
为了便于完成配置项变更,还提供了一个ReconfigurationServlet工具便于从web端变更配置。使用时只需要将该servelt加入到相应节点的httpserver中,并在context中加入conf.servlet.reconfigurable.$P的参数,值为对应的Reconfigurable实现(一般为节点自身实现),其中$P表示的是ReconfigurationServlet在httpServer中对应的path。
(1)Reconfigurable,该接口定义了可变配置的基本操作
* Change a configuration property on this object to the value specified.
*
* Change a configuration property on this object to the value specified
* and return the previous value that the configuration property was set to
* (or null if it was not previously set). If newVal is null, set the property
* to its default value;
*
* If the property cannot be changed, throw a
* {@link ReconfigurationException}.
*/
public String reconfigureProperty(String property, String newVal)
throws ReconfigurationException;
/**
* Return whether a given property is changeable at run time.
*
* If isPropertyReconfigurable returns true for a property,
* then changeConf should not throw an exception when changing
* this property.
*/
public boolean isPropertyReconfigurable(String property);
(2)ReconfigurableBase,该基类有两个抽象方法,所有想要实现动态配置的节点,都需要实现这两个方法:
* {@inheritDoc}
*
* 定义该节点上所有可以进行动态配置的属性集合
*
* Subclasses must override this.
*/
@Override
public abstract Collection<String> getReconfigurableProperties();
/**
* Change a configuration property.
* 某个可以动态配置的属性变化时需要进行的处理
* Subclasses must override this. This method applies the change to
* all internal data structures derived from the configuration property
* that is being changed. If this object owns other Reconfigurable objects
* reconfigureProperty should be called recursively to make sure that
* to make sure that the configuration of these objects is updated.
*/
protected abstract void reconfigurePropertyImpl(String property, String newVal)
throws ReconfigurationException;
(3)ReconfigurationServlet 用于配置动态管理
注意:该模块在2.2版本中并未用到。