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);
}
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);
}
Aggregations