public boolean setIf(T newState, Predicate<T> predicate) {
    checkState(!Thread.holdsLock(lock), LOCK_HELD_ERROR_MSG);
    requireNonNull(newState, STATE_IS_NULL);

    while (true) {
      // check if the current state passes the predicate
      T currentState = get();

      // change to same state is not a change, and does not notify the notify listeners
      if (currentState.equals(newState)) {
        return false;
      }

      // do not call predicate while holding the lock
      if (!predicate.test(currentState)) {
        return false;
      }

      // if state did not change while, checking the predicate, apply the new state
      if (compareAndSet(currentState, newState)) {
        return true;
      }
    }
  }
Sets the state if the current state satisfies the specified predicate. If the new state does
not {@code .equals()} the current state, listeners and waiters will be notified.

@return true if the state is set
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/StateMachine.java