public TxnIndexSearchResult collectAbortedTxns(long fetchOffset, long upperBoundOffset) {
        List<AbortedTxn> abortedTransactions = new ArrayList<>();
        for (AbortedTxnWithPosition txnWithPosition : iterable()) {
            AbortedTxn abortedTxn = txnWithPosition.txn;
            if (abortedTxn.lastOffset() >= fetchOffset && abortedTxn.firstOffset() < upperBoundOffset)
                abortedTransactions.add(abortedTxn);

            if (abortedTxn.lastStableOffset() >= upperBoundOffset)
                return new TxnIndexSearchResult(abortedTransactions, true);
        }
        return new TxnIndexSearchResult(abortedTransactions, false);
    }
Collect all aborted transactions which overlap with a given fetch range.

@param fetchOffset Inclusive first offset of the fetch range
@param upperBoundOffset Exclusive last offset in the fetch range
@return An object containing the aborted transactions and whether the search needs to continue
        into the next log segment.
storage/src/main/java/org/apache/kafka/storage/internals/log/TransactionIndex.java