public boolean hasUndrained() {
        for (TopicInfo topicInfo : topicInfoMap.values()) {
            for (Deque<ProducerBatch> deque : topicInfo.batches.values()) {
                synchronized (deque) {
                    if (!deque.isEmpty())
                        return true;
                }
            }
        }
        return false;
    }
Check whether there are any batches which haven't been drained
clients/src/main/java/org/apache/kafka/clients/producer/internals/RecordAccumulator.java