final LockState doAcquireLock(TEnvironment env, ProcedureStore store) {
    if (waitInitialized(env)) {
      return LockState.LOCK_EVENT_WAIT;
    }
    if (lockedWhenLoading) {
      // reset it so we will not consider it anymore
      lockedWhenLoading = false;
      locked = true;
      // Here we return without persist the locked state, as lockedWhenLoading is true means
      // that the locked field of the procedure stored in procedure store is true, so we do not need
      // to store it again.
      return LockState.LOCK_ACQUIRED;
    }
    LockState state = acquireLock(env);
    if (state == LockState.LOCK_ACQUIRED) {
      locked = true;
      // persist that we have held the lock. This must be done before we actually execute the
      // procedure, otherwise when restarting, we may consider the procedure does not have a lock,
      // but it may have already done some changes as we have already executed it, and if another
      // procedure gets the lock, then the semantic will be broken if the holdLock is true, as we do
      // not expect that another procedure can be executed in the middle.
      store.update(this);
    }
    return state;
  }
Internal method called by the ProcedureExecutor that starts the user-level code acquireLock().
hbase-procedure/src/main/java/org/apache/hadoop/hbase/procedure2/Procedure.java