public T set(T newState) {
    T oldState = trySet(newState);
    checkState(
        oldState.equals(newState) || !isTerminalState(oldState),
        "%s cannot transition from %s to %s",
        name,
        state,
        newState);
    return oldState;
  }
Sets the state. If the new state does not {@code .equals()} the current state, listeners and
waiters will be notified.

@return the old state
@throws IllegalStateException if state change would cause a transition from a terminal state
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/StateMachine.java