vlei 发表于 2018-10-29 11:31:33

Hadoop之安全模式

this.safeMode = new SafeModeInfo(conf);  
在启动时创建SafeModeInfo实例时,其参数如下:
  
this.threshold =conf.getFloat("dfs.safemode.threshold.pct", 0.95f);
  
    this.extension =conf.getInt("dfs.safemode.extension", 0);
  
this.safeReplication =conf.getInt("dfs.replication.min", 1);
  
//namenode启动时创建SafeModeInfo实例
  
    SafeModeInfo(Configuration conf) {
  
      this.threshold =conf.getFloat("dfs.safemode.threshold.pct", 0.95f);
  
      this.extension =conf.getInt("dfs.safemode.extension", 0);
  
      this.safeReplication =conf.getInt("dfs.replication.min", 1);
  
      this.blockTotal = 0;
  
      this.blockSafe = 0;
  
    }
  
//手动进入安全模式的实例构造方法
  
    private SafeModeInfo() {
  
      this.threshold = 1.5f;//this threshold can never be reached
  
      this.extension = Integer.MAX_VALUE;
  
      this.safeReplication = Short.MAX_VALUE +1; // more than maxReplication
  
      this.blockTotal = -1;
  
      this.blockSafe = -1;
  
      this.reached = -1;
  
      enter();
  
      reportStatus("STATE* Safe mode isON.", true);
  
    }
  
//手动触发的方法入口如下:
  
synchronized void enterSafeMode() throws IOException {
  
    if (!isInSafeMode()) {
  
      safeMode = new SafeModeInfo();
  
      return;
  
    }
  
    safeMode.setManual();
  
    getEditLog().logSync();
  
    NameNode.stateChangeLog.info("STATE* Safe modeis ON. "
  
                              + safeMode.getTurnOffTip());
  
}
  
SafeModeMonitor安全模式监控类,1000毫秒监控状态。
  
核心代码:
  
public void run() {
  
      while (fsRunning && (safeMode !=null && !safeMode.canLeave())) {
  
      try {
  
         Thread.sleep(recheckInterval);
  
      } catch(InterruptedException ie) {
  
      }
  
      }
  
      // leave safe mode and stop the monitor
  
      try {
  
      leaveSafeMode(true);
  
      } catch(SafeModeException es) { //should never happen
  
      String msg ="SafeModeMonitor may not run during distributed upgrade.";
  
      assert false : msg;
  
      throw newRuntimeException(msg, es);
  
      }
  
      smmthread = null;
  
    }


页: [1]
查看完整版本: Hadoop之安全模式