static boolean flag(ProduceRequest request, Predicate<RecordBatch> predicate) {
        for (ProduceRequestData.TopicProduceData tp : request.data().topicData()) {
            for (ProduceRequestData.PartitionProduceData p : tp.partitionData()) {
                if (p.records() instanceof Records) {
                    Iterator<? extends RecordBatch> iter = (((Records) p.records())).batchIterator();
                    if (iter.hasNext() && predicate.test(iter.next())) return true;
                }
            }
        }
        return false;
    }
find a flag from all records of a produce request.
@param request produce request
@param predicate used to predicate the record
@return true if there is any matched flag in the produce request. Otherwise, false
clients/src/main/java/org/apache/kafka/common/requests/RequestUtils.java