Search in sources :

Example 1 with LogEmptyException

use of org.apache.distributedlog.exceptions.LogEmptyException in project bookkeeper by apache.

the class TestBKDistributedLogManager method testGetLastDLSN.

@Test(timeout = 60000)
public void testGetLastDLSN() throws Exception {
    String name = "distrlog-get-last-dlsn";
    DistributedLogConfiguration confLocal = new DistributedLogConfiguration();
    confLocal.loadConf(conf);
    confLocal.setFirstNumEntriesPerReadLastRecordScan(2);
    confLocal.setMaxNumEntriesPerReadLastRecordScan(4);
    confLocal.setImmediateFlushEnabled(true);
    confLocal.setOutputBufferSize(0);
    DistributedLogManager dlm = createNewDLM(confLocal, name);
    BKAsyncLogWriter writer = (BKAsyncLogWriter) dlm.startAsyncLogSegmentNonPartitioned();
    long txid = 1;
    LOG.info("Writing 10 control records");
    for (int i = 0; i < 10; i++) {
        LogRecord record = DLMTestUtil.getLogRecordInstance(txid++);
        record.setControl();
        Utils.ioResult(writer.writeControlRecord(record));
    }
    LOG.info("10 control records are written");
    try {
        dlm.getLastDLSN();
        fail("Should fail on getting last dlsn from an empty log.");
    } catch (LogEmptyException lee) {
    // expected
    }
    writer.closeAndComplete();
    LOG.info("Completed first log segment");
    writer = (BKAsyncLogWriter) dlm.startAsyncLogSegmentNonPartitioned();
    Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(txid++)));
    LOG.info("Completed second log segment");
    LOG.info("Writing another 10 control records");
    for (int i = 1; i < 10; i++) {
        LogRecord record = DLMTestUtil.getLogRecordInstance(txid++);
        record.setControl();
        Utils.ioResult(writer.write(record));
    }
    assertEquals(new DLSN(2, 0, 0), dlm.getLastDLSN());
    writer.closeAndComplete();
    LOG.info("Completed third log segment");
    assertEquals(new DLSN(2, 0, 0), dlm.getLastDLSN());
    writer.close();
    dlm.close();
}
Also used : LogEmptyException(org.apache.distributedlog.exceptions.LogEmptyException) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) Test(org.junit.Test)

Example 2 with LogEmptyException

use of org.apache.distributedlog.exceptions.LogEmptyException in project bookkeeper by apache.

the class DLFileSystem method open.

@Override
public FSDataInputStream open(Path path, int bufferSize) throws IOException {
    try {
        DistributedLogManager dlm = namespace.openLog(getStreamName(path));
        LogReader reader;
        try {
            reader = dlm.openLogReader(DLSN.InitialDLSN);
        } catch (LogNotFoundException lnfe) {
            throw new FileNotFoundException(path.toString());
        } catch (LogEmptyException lee) {
            throw new FileNotFoundException(path.toString());
        }
        return new FSDataInputStream(new BufferedFSInputStream(new DLInputStream(dlm, reader, 0L), bufferSize));
    } catch (LogNotFoundException e) {
        throw new FileNotFoundException(path.toString());
    }
}
Also used : LogEmptyException(org.apache.distributedlog.exceptions.LogEmptyException) BufferedFSInputStream(org.apache.hadoop.fs.BufferedFSInputStream) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LogReader(org.apache.distributedlog.api.LogReader) FileNotFoundException(java.io.FileNotFoundException) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException)

Example 3 with LogEmptyException

use of org.apache.distributedlog.exceptions.LogEmptyException in project bookkeeper by apache.

the class AbstractStateStoreWithJournal method getLastDLSN.

private CompletableFuture<DLSN> getLastDLSN(StateStoreSpec spec) {
    synchronized (this) {
        if (null != closeFuture) {
            return FutureUtils.exception(new StateStoreClosedException(name()));
        }
    }
    try {
        logManager = logNamespace.openLog(spec.getStream());
    } catch (IOException e) {
        return FutureUtils.exception(e);
    }
    CompletableFuture<DLSN> future = FutureUtils.createFuture();
    logManager.getLastDLSNAsync().whenCompleteAsync(new FutureEventListener<DLSN>() {

        @Override
        public void onSuccess(DLSN dlsn) {
            future.complete(dlsn);
        }

        @Override
        public void onFailure(Throwable throwable) {
            if (throwable instanceof LogEmptyException || throwable instanceof LogNotFoundException) {
                FutureUtils.proxyTo(writeCatchUpMarker(), future);
            } else {
                future.completeExceptionally(throwable);
            }
        }
    });
    return future;
}
Also used : LogEmptyException(org.apache.distributedlog.exceptions.LogEmptyException) StateStoreClosedException(org.apache.bookkeeper.statelib.api.exceptions.StateStoreClosedException) LogRecordWithDLSN(org.apache.distributedlog.LogRecordWithDLSN) DLSN(org.apache.distributedlog.DLSN) IOException(java.io.IOException) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException)

Example 4 with LogEmptyException

use of org.apache.distributedlog.exceptions.LogEmptyException in project bookkeeper by apache.

the class DLFileSystem method getFileStatus.

@Override
public FileStatus getFileStatus(Path path) throws IOException {
    String logName = getStreamName(path);
    boolean exists = namespace.logExists(logName);
    if (!exists) {
        throw new FileNotFoundException(path.toString());
    }
    long endPos;
    try {
        DistributedLogManager dlm = namespace.openLog(logName);
        endPos = dlm.getLastTxId();
    } catch (LogNotFoundException e) {
        throw new FileNotFoundException(path.toString());
    } catch (LogEmptyException e) {
        endPos = 0L;
    }
    // we need to store more metadata information on logs for supporting filesystem-like use cases
    return new FileStatus(endPos, false, 3, dlConf.getMaxLogSegmentBytes(), 0L, makeAbsolute(path));
}
Also used : LogEmptyException(org.apache.distributedlog.exceptions.LogEmptyException) FileStatus(org.apache.hadoop.fs.FileStatus) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) FileNotFoundException(java.io.FileNotFoundException) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException)

Example 5 with LogEmptyException

use of org.apache.distributedlog.exceptions.LogEmptyException in project bookkeeper by apache.

the class BKLogHandler method getLastLogRecordAsync.

public CompletableFuture<LogRecordWithDLSN> getLastLogRecordAsync(final boolean recover, final boolean includeEndOfStream) {
    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.DESC_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;
                    }
                    asyncGetLastLogRecord(ledgerList.getValue().iterator(), promise, recover, false, includeEndOfStream);
                }

                @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