Search in sources :

Example 1 with LogRecordSelector

use of org.apache.distributedlog.selector.LogRecordSelector in project bookkeeper by apache.

the class ReadUtils method getLogRecordNotLessThanTxIdFromEntries.

/**
 * Find the log record whose transaction id is not less than provided <code>transactionId</code> from
 * entries between <code>startEntryId</code> and <code>endEntryId</code>.
 *
 * @param logName
 *          name of the log
 * @param segment
 *          log segment
 * @param transactionId
 *          provided transaction id to search
 * @param executorService
 *          executor service
 * @param reader
 *          log segment random access reader
 * @param entriesToSearch
 *          list of entries to search
 * @param nWays
 *          how many entries to search in parallel
 * @param prevFoundRecord
 *          the log record found in previous search
 * @param promise
 *          promise to satisfy the result
 */
private static void getLogRecordNotLessThanTxIdFromEntries(final String logName, final LogSegmentMetadata segment, final long transactionId, final ExecutorService executorService, final LogSegmentRandomAccessEntryReader reader, final List<Long> entriesToSearch, final int nWays, final Optional<LogRecordWithDLSN> prevFoundRecord, final CompletableFuture<Optional<LogRecordWithDLSN>> promise) {
    final List<CompletableFuture<LogRecordWithDLSN>> searchResults = Lists.newArrayListWithExpectedSize(entriesToSearch.size());
    for (Long entryId : entriesToSearch) {
        LogRecordSelector selector = new FirstTxIdNotLessThanSelector(transactionId);
        CompletableFuture<LogRecordWithDLSN> searchResult = asyncReadRecordFromEntries(logName, reader, segment, executorService, new SingleEntryScanContext(entryId), selector);
        searchResults.add(searchResult);
    }
    FutureEventListener<List<LogRecordWithDLSN>> processSearchResultsListener = new FutureEventListener<List<LogRecordWithDLSN>>() {

        @Override
        public void onSuccess(List<LogRecordWithDLSN> resultList) {
            processSearchResults(logName, segment, transactionId, executorService, reader, resultList, nWays, prevFoundRecord, promise);
        }

        @Override
        public void onFailure(Throwable cause) {
            promise.completeExceptionally(cause);
        }
    };
    FutureUtils.collect(searchResults).whenCompleteAsync(processSearchResultsListener, executorService);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) AtomicLong(java.util.concurrent.atomic.AtomicLong) LogRecordSelector(org.apache.distributedlog.selector.LogRecordSelector) List(java.util.List) FutureEventListener(org.apache.bookkeeper.common.concurrent.FutureEventListener) FirstTxIdNotLessThanSelector(org.apache.distributedlog.selector.FirstTxIdNotLessThanSelector)

Example 2 with LogRecordSelector

use of org.apache.distributedlog.selector.LogRecordSelector in project bookkeeper by apache.

the class ReadUtils method asyncReadFirstUserRecord.

/**
 * Read first record from a log segment with a DLSN larger than that given.
 *
 * @param streamName
 *          fully qualified stream name (used for logging)
 * @param l
 *          log segment metadata.
 * @param scanStartBatchSize
 *          first num entries used for read last record scan
 * @param scanMaxBatchSize
 *          max num entries used for read last record scan
 * @param numRecordsScanned
 *          num of records scanned to get last record
 * @param executorService
 *          executor service used for processing entries
 * @param entryStore
 *          log segment entry store
 * @param dlsn
 *          threshold dlsn
 * @return a future with last record.
 */
public static CompletableFuture<LogRecordWithDLSN> asyncReadFirstUserRecord(final String streamName, final LogSegmentMetadata l, final int scanStartBatchSize, final int scanMaxBatchSize, final AtomicInteger numRecordsScanned, final ExecutorService executorService, final LogSegmentEntryStore entryStore, final DLSN dlsn) {
    long startEntryId = 0L;
    if (l.getLogSegmentSequenceNumber() == dlsn.getLogSegmentSequenceNo()) {
        startEntryId = dlsn.getEntryId();
    }
    final LogRecordSelector selector = new FirstDLSNNotLessThanSelector(dlsn);
    return asyncReadRecord(streamName, l, false, false, false, scanStartBatchSize, scanMaxBatchSize, numRecordsScanned, executorService, entryStore, selector, false, /* backward */
    startEntryId);
}
Also used : FirstDLSNNotLessThanSelector(org.apache.distributedlog.selector.FirstDLSNNotLessThanSelector) LogRecordSelector(org.apache.distributedlog.selector.LogRecordSelector)

Aggregations

LogRecordSelector (org.apache.distributedlog.selector.LogRecordSelector)2 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 FutureEventListener (org.apache.bookkeeper.common.concurrent.FutureEventListener)1 FirstDLSNNotLessThanSelector (org.apache.distributedlog.selector.FirstDLSNNotLessThanSelector)1 FirstTxIdNotLessThanSelector (org.apache.distributedlog.selector.FirstTxIdNotLessThanSelector)1