use of org.apache.distributedlog.exceptions.LogEmptyException in project bookkeeper by apache.
the class BKLogHandler method asyncGetLastLogRecord.
private void asyncGetLastLogRecord(final Iterator<LogSegmentMetadata> ledgerIter, final CompletableFuture<LogRecordWithDLSN> promise, final boolean fence, final boolean includeControlRecord, final boolean includeEndOfStream) {
if (ledgerIter.hasNext()) {
LogSegmentMetadata metadata = ledgerIter.next();
asyncReadLastRecord(metadata, fence, includeControlRecord, includeEndOfStream).whenComplete(new FutureEventListener<LogRecordWithDLSN>() {
@Override
public void onSuccess(LogRecordWithDLSN record) {
if (null == record) {
asyncGetLastLogRecord(ledgerIter, promise, fence, includeControlRecord, includeEndOfStream);
} else {
promise.complete(record);
}
}
@Override
public void onFailure(Throwable cause) {
promise.completeExceptionally(cause);
}
});
} else {
promise.completeExceptionally(new LogEmptyException("Log " + getFullyQualifiedName() + " has no records"));
}
}
use of org.apache.distributedlog.exceptions.LogEmptyException in project bookkeeper by apache.
the class BKLogHandler method asyncGetFirstLogRecord.
public CompletableFuture<LogRecordWithDLSN> asyncGetFirstLogRecord() {
final CompletableFuture<LogRecordWithDLSN> promise = new CompletableFuture<LogRecordWithDLSN>();
streamMetadataStore.logExists(logMetadata.getUri(), logMetadata.getLogName()).whenComplete(new FutureEventListener<Void>() {
@Override
public void onSuccess(Void value) {
readLogSegmentsFromStore(LogSegmentMetadata.COMPARATOR, LogSegmentFilter.DEFAULT_FILTER, null).whenComplete(new FutureEventListener<Versioned<List<LogSegmentMetadata>>>() {
@Override
public void onSuccess(Versioned<List<LogSegmentMetadata>> ledgerList) {
if (ledgerList.getValue().isEmpty()) {
promise.completeExceptionally(new LogEmptyException("Log " + getFullyQualifiedName() + " has no records"));
return;
}
CompletableFuture<LogRecordWithDLSN> firstRecord = null;
for (LogSegmentMetadata ledger : ledgerList.getValue()) {
if (!ledger.isTruncated() && (ledger.getRecordCount() > 0 || ledger.isInProgress())) {
firstRecord = asyncReadFirstUserRecord(ledger, DLSN.InitialDLSN);
break;
}
}
if (null != firstRecord) {
FutureUtils.proxyTo(firstRecord, promise);
} else {
promise.completeExceptionally(new LogEmptyException("Log " + getFullyQualifiedName() + " has no records"));
}
}
@Override
public void onFailure(Throwable cause) {
promise.completeExceptionally(cause);
}
});
}
@Override
public void onFailure(Throwable cause) {
promise.completeExceptionally(cause);
}
});
return promise;
}
Aggregations