private void collectAbortedTransactions(long startOffset,
                                            long upperBoundOffset,
                                            RemoteLogSegmentMetadata segmentMetadata,
                                            Consumer<List<AbortedTxn>> accumulator,
                                            UnifiedLog log) throws RemoteStorageException {
        // Search in remote segments first.
        Optional<RemoteLogSegmentMetadata> nextSegmentMetadataOpt = Optional.of(segmentMetadata);
        while (nextSegmentMetadataOpt.isPresent()) {
            Optional<TransactionIndex> txnIndexOpt = nextSegmentMetadataOpt.map(metadata -> indexCache.getIndexEntry(metadata).txnIndex());
            if (txnIndexOpt.isPresent()) {
                TxnIndexSearchResult searchResult = txnIndexOpt.get().collectAbortedTxns(startOffset, upperBoundOffset);
                accumulator.accept(searchResult.abortedTransactions);
                if (searchResult.isComplete) {
                    // Return immediately when the search result is complete, it does not need to go through local log segments.
                    return;
                }
            }

            nextSegmentMetadataOpt = findNextSegmentMetadata(nextSegmentMetadataOpt.get(), log.leaderEpochCache());
        }

        // Search in local segments
        collectAbortedTransactionInLocalSegments(startOffset, upperBoundOffset, accumulator, log.logSegments().iterator());
    }
Returns a map containing the epoch vs start-offset for the given leader epoch map by filtering the epochs that
does not contain any messages/records associated with them.
For ex:
<pre>
{@code
 <epoch - start offset>
 0 - 0
 1 - 10
 2 - 20
 3 - 30
 4 - 40
 5 - 60  // epoch 5 does not have records or messages associated with it
 6 - 60
 7 - 70
}
</pre>
When the above leaderEpochMap is passed to this method, it returns the following map:
<pre>
{@code
 <epoch - start offset>
 0 - 0
 1 - 10
 2 - 20
 3 - 30
 4 - 40
 6 - 60
 7 - 70
}
</pre>
@param leaderEpochs The leader epoch map to be refined.
core/src/main/java/kafka/log/remote/RemoteLogManager.java