use of com.twitter.distributedlog.selector.LogRecordSelector in project distributedlog by twitter.
the class ReadUtils method asyncReadFirstUserRecord.
/**
* Read first record from a ledger with a DLSN larger than that given.
*
* @param streamName
* fully qualified stream name (used for logging)
* @param l
* ledger descriptor.
* @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 dlsn
* threshold dlsn
* @return a future with last record.
*/
public static Future<LogRecordWithDLSN> asyncReadFirstUserRecord(final String streamName, final LogSegmentMetadata l, final int scanStartBatchSize, final int scanMaxBatchSize, final AtomicInteger numRecordsScanned, final ExecutorService executorService, final LedgerHandleCache handleCache, 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, handleCache, selector, false, /* backward */
startEntryId);
}
use of com.twitter.distributedlog.selector.LogRecordSelector in project distributedlog by twitter.
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 handleCache
* handle cache
* @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 LedgerDescriptor ld, final LogSegmentMetadata segment, final long transactionId, final ExecutorService executorService, final LedgerHandleCache handleCache, final List<Long> entriesToSearch, final int nWays, final Optional<LogRecordWithDLSN> prevFoundRecord, final Promise<Optional<LogRecordWithDLSN>> promise) {
final List<Future<LogRecordWithDLSN>> searchResults = Lists.newArrayListWithExpectedSize(entriesToSearch.size());
for (Long entryId : entriesToSearch) {
LogRecordSelector selector = new FirstTxIdNotLessThanSelector(transactionId);
Future<LogRecordWithDLSN> searchResult = asyncReadRecordFromEntries(logName, ld, handleCache, 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, ld, segment, transactionId, executorService, handleCache, resultList, nWays, prevFoundRecord, promise);
}
@Override
public void onFailure(Throwable cause) {
promise.setException(cause);
}
};
Future.collect(searchResults).addEventListener(FutureEventListenerRunnable.of(processSearchResultsListener, executorService));
}
Aggregations