Search in sources :

Example 6 with LogEmptyException

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"));
    }
}
Also used : LogEmptyException(org.apache.distributedlog.exceptions.LogEmptyException)

Example 7 with LogEmptyException

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;
}
Also used : LogEmptyException(org.apache.distributedlog.exceptions.LogEmptyException) CompletableFuture(java.util.concurrent.CompletableFuture) Versioned(org.apache.bookkeeper.versioning.Versioned) FutureEventListener(org.apache.bookkeeper.common.concurrent.FutureEventListener) List(java.util.List)

Aggregations

LogEmptyException (org.apache.distributedlog.exceptions.LogEmptyException)7 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)3 LogNotFoundException (org.apache.distributedlog.exceptions.LogNotFoundException)3 FileNotFoundException (java.io.FileNotFoundException)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 FutureEventListener (org.apache.bookkeeper.common.concurrent.FutureEventListener)2 Versioned (org.apache.bookkeeper.versioning.Versioned)2 IOException (java.io.IOException)1 StateStoreClosedException (org.apache.bookkeeper.statelib.api.exceptions.StateStoreClosedException)1 DLSN (org.apache.distributedlog.DLSN)1 LogRecordWithDLSN (org.apache.distributedlog.LogRecordWithDLSN)1 LogReader (org.apache.distributedlog.api.LogReader)1 BufferedFSInputStream (org.apache.hadoop.fs.BufferedFSInputStream)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 FileStatus (org.apache.hadoop.fs.FileStatus)1 Test (org.junit.Test)1