public void transitionToFollower(int epoch, int leaderId, Endpoints endpoints) {
        int currentEpoch = state.epoch();
        if (endpoints.isEmpty()) {
            throw new IllegalArgumentException(
                String.format(
                    "Cannot transition to Follower with leader %s and epoch %s without a leader endpoint",
                    leaderId,
                    epoch
                )
            );
        } else if (localId.isPresent() && leaderId == localId.getAsInt()) {
            throw new IllegalStateException(
                String.format(
                    "Cannot transition to Follower with leader %s and epoch %s since it matches the local node.id %s",
                    leaderId,
                    epoch,
                    localId
                )
            );
        } else if (epoch < currentEpoch) {
            throw new IllegalStateException(
                String.format(
                    "Cannot transition to Follower with leader %s and epoch %s since the current epoch %s is larger",
                    leaderId,
                    epoch,
                    currentEpoch
                )
            );
        } else if (epoch == currentEpoch) {
            if (isFollower() && state.leaderEndpoints().size() >= endpoints.size()) {
                throw new IllegalStateException(
                    String.format(
                        "Cannot transition to Follower with leader %s, epoch %s and endpoints %s from state %s",
                        leaderId,
                        epoch,
                        endpoints,
                        state
                    )
                );
            } else if (isLeader()) {
                throw new IllegalStateException(
                    String.format(
                        "Cannot transition to Follower with leader %s and epoch %s from state %s",
                        leaderId,
                        epoch,
                        state
                    )
                );
            }
        }

        durableTransitionTo(
            new FollowerState(
                time,
                epoch,
                leaderId,
                endpoints,
                partitionState.lastVoterSet().voterIds(),
                state.highWatermark(),
                fetchTimeoutMs,
                logContext
            )
        );
    }
Become a follower of an elected leader so that we can begin fetching.
raft/src/main/java/org/apache/kafka/raft/QuorumState.java