private void replaceMember(
        List<CoordinatorRecord> records,
        ConsumerGroup group,
        ConsumerGroupMember oldMember,
        ConsumerGroupMember newMember
    ) {
        String groupId = group.groupId();

        // Remove the member without canceling its timers in case the change is reverted. If the
        // change is not reverted, the group validation will fail and the timer will do nothing.
        removeMember(records, groupId, oldMember.memberId());

        // Generate records.
        records.add(CoordinatorRecordHelpers.newMemberSubscriptionRecord(
            groupId,
            newMember
        ));
        records.add(CoordinatorRecordHelpers.newTargetAssignmentRecord(
            groupId,
            newMember.memberId(),
            group.targetAssignment(oldMember.memberId()).partitions()
        ));
        records.add(CoordinatorRecordHelpers.newCurrentAssignmentRecord(
            groupId,
            newMember
        ));
    }
Write records to replace the old member by the new member.

@param records   The list of records to append to.
@param group     The consumer group.
@param oldMember The old member.
@param newMember The new member.
group-coordinator/src/main/java/org/apache/kafka/coordinator/group/GroupMetadataManager.java