Example #1
0
  private void common(HBRefData refData, HBResult result, boolean putOpinion)
      throws MgmtZooKeeperException, NodeExistsException {
    HBRefData.ZKData zkData = refData.getZkData();

    if (zkData.state.equals(result.getState()) && refData.isSubmitMyOpinion()) {
      if (putOpinion) {
        removeMyOpinion(refData, result, result.getState());
      } else {
        workflowExecutor.perform(OPINION_PUBLISH, result);
      }
    } else if (!result.getState().equals(refData.getLastState())
        && !result.getState().equals(zkData.state)) {
      if (putOpinion) {
        if (refData.isSubmitMyOpinion()) removeMyOpinion(refData, result, result.getState());
        putMyOpinion(0, refData, result, result.getState());
      } else {
        workflowExecutor.perform(OPINION_PUBLISH, result);
      }
    }
  }
Example #2
0
  private void pgs(HBRefData refData, HBResult result, boolean putOpinion)
      throws MgmtZooKeeperException, NodeExistsException {
    String newState = result.getState();
    long stateTimestamp = Constant.DEFAULT_STATE_TIMESTAMP;
    HBRefData.ZKData zkData = refData.getZkData();

    if (result.getState().equals(Constant.SERVER_STATE_NORMAL)) {
      String[] resAry = result.getResponse().split(" ");
      if (resAry.length < 3) {
        Logger.error(
            "Invalid response. from: {}, response: {}",
            result.getRemoteIP() + ":" + result.getRemoteIP(),
            result.getResponse());
        newState = Constant.SERVER_STATE_FAILURE;
      }

      if (resAry[1].equals("1")) {
        newState = Constant.SERVER_STATE_LCONN;
      } else if (resAry[1].equals("0")) {
        newState = Constant.SERVER_STATE_FAILURE;
      }

      stateTimestamp = Long.parseLong(resAry[2]);
    } else if (result.getState().equals(Constant.SERVER_STATE_FAILURE)) {
      stateTimestamp = zkData.stateTimestamp + 1;
    }

    if (stateTimestamp == zkData.stateTimestamp && newState.equals(zkData.state)) {
      if (refData.isSubmitMyOpinion()) {
        if (putOpinion) {
          removeMyOpinion(refData, result, newState);
        } else {
          workflowExecutor.perform(OPINION_PUBLISH, result);
        }
      }
    } else if (newState.equals(zkData.state)
        && newState.equals(Constant.SERVER_STATE_FAILURE)
        && stateTimestamp - 1 == zkData.stateTimestamp) {
      if (refData.isSubmitMyOpinion()) {
        if (putOpinion) {
          removeMyOpinion(refData, result, newState);
        } else {
          workflowExecutor.perform(OPINION_PUBLISH, result);
        }
      }
    }
    /**
     * HBC assumes that dead PGS`s version is zk_version + 1, because Dead PGS`s version(timestamp)
     * is 0. so this routine is located at the bottom of these conditional statements. Otherwise, if
     * PGS was in dead, then this function increases PGS`s version and puts an opinion to the
     * ZooKeeper repeatedly.
     */
    else if (!newState.equals(refData.getLastState())
        || stateTimestamp != refData.getLastStateTimestamp()) {
      if (putOpinion) {
        if (refData.isSubmitMyOpinion()) {
          removeMyOpinion(refData, result, newState);
        }
        putMyOpinion(stateTimestamp, refData, result, newState);
      } else {
        workflowExecutor.perform(OPINION_PUBLISH, result);
      }
    }
  }