private void transitionTo(MemberState nextState) {
        if (!state.equals(nextState) && !nextState.getPreviousValidStates().contains(state)) {
            throw new IllegalStateException(String.format("Invalid state transition from %s to %s",
                    state, nextState));
        }

        if (isCompletingRebalance(state, nextState)) {
            metricsManager.recordRebalanceEnded(time.milliseconds());
        }
        if (isStartingRebalance(state, nextState)) {
            metricsManager.recordRebalanceStarted(time.milliseconds());
        }

        log.trace("Member {} with epoch {} transitioned from {} to {}.", memberId, memberEpoch, state, nextState);
        this.state = nextState;
    }
Update the member state, setting it to the nextState only if it is a valid transition.

@throws IllegalStateException If transitioning from the member {@link #state} to the
                              nextState is not allowed as defined in {@link MemberState}.
clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareMembershipManager.java