private void validateMetadataVersions(final int receivedAssignmentMetadataVersion,
                                          final int latestCommonlySupportedVersion) {

        if (receivedAssignmentMetadataVersion > usedSubscriptionMetadataVersion) {
            log.error("Leader sent back an assignment with version {} which was greater than our used version {}",
                receivedAssignmentMetadataVersion, usedSubscriptionMetadataVersion);
            throw new TaskAssignmentException(
                "Sent a version " + usedSubscriptionMetadataVersion
                    + " subscription but got an assignment with higher version "
                    + receivedAssignmentMetadataVersion + "."
            );
        }

        if (latestCommonlySupportedVersion > LATEST_SUPPORTED_VERSION) {
            log.error("Leader sent back assignment with commonly supported version {} that is greater than our "
                + "actual latest supported version {}", latestCommonlySupportedVersion, LATEST_SUPPORTED_VERSION);
            throw new TaskAssignmentException("Can't upgrade to metadata version greater than we support");
        }
    }
Generate an assignment that tries to preserve thread-level stickiness for stateful tasks without violating
balance. The tasks are balanced across threads. Stateful tasks without previous owners will be interleaved by
group id to spread subtopologies across threads and further balance the workload.
Stateless tasks are simply spread across threads without taking into account previous ownership.
threadLoad is a map that keeps track of task load per thread across multiple calls so active and standby
tasks are evenly distributed
streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamsPartitionAssignor.java