private void remove(int brokerId, Uuid topicId, int removedPartition, boolean leader) {
        if (leader) {
            removedPartition = removedPartition | LEADER_FLAG;
        }
        TimelineHashMap<Uuid, int[]> topicMap = isrMembers.get(brokerId);
        if (topicMap == null) {
            throw new RuntimeException("Broker " + brokerId + " has no isrMembers " +
                "entry, so we can't remove " + topicId + ":" + removedPartition);
        }
        int[] partitions = topicMap.get(topicId);
        if (partitions == null) {
            throw new RuntimeException("Broker " + brokerId + " has no " +
                "entry in isrMembers for topic " + topicId);
        }
        if (partitions.length == 1) {
            if (partitions[0] != removedPartition) {
                throw new RuntimeException("Broker " + brokerId + " has no " +
                    "entry in isrMembers for " + topicId + ":" + removedPartition);
            }
            topicMap.remove(topicId);
            if (topicMap.isEmpty()) {
                isrMembers.remove(brokerId);
            }
        } else {
            int[] newPartitions = new int[partitions.length - 1];
            int i = 0;
            for (int partition : partitions) {
                if (partition != removedPartition) {
                    newPartitions[i++] = partition;
                }
            }
            topicMap.put(topicId, newPartitions);
        }
    }
Update our records of a partition's ISR.

@param topicId       The topic ID of the partition.
@param partitionId   The partition ID of the partition.
@param prevIsr       The previous ISR, or null if the partition is new.
@param nextIsr       The new ISR, or null if the partition is being removed.
@param prevLeader    The previous leader, or NO_LEADER if the partition had no leader.
@param nextLeader    The new leader, or NO_LEADER if the partition now has no leader.
metadata/src/main/java/org/apache/kafka/controller/BrokersToIsrs.java