Search in sources :

Example 11 with LogNotFoundException

use of org.apache.distributedlog.exceptions.LogNotFoundException 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 12 with LogNotFoundException

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

the class DLFileSystem method append.

private FSDataOutputStream append(Path path, int bufferSize, Optional<DistributedLogConfiguration> confLocal) throws IOException {
    try {
        DistributedLogManager dlm = namespace.openLog(getStreamName(path), confLocal, Optional.empty(), Optional.empty());
        AsyncLogWriter writer = Utils.ioResult(dlm.openAsyncLogWriter());
        return new FSDataOutputStream(new BufferedOutputStream(new DLOutputStream(dlm, writer), bufferSize), statistics, writer.getLastTxId() < 0L ? 0L : writer.getLastTxId());
    } catch (LogNotFoundException le) {
        throw new FileNotFoundException(path.toString());
    }
}
Also used : DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) FileNotFoundException(java.io.FileNotFoundException) AsyncLogWriter(org.apache.distributedlog.api.AsyncLogWriter) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 13 with LogNotFoundException

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

the class TestBKDistributedLogManager method deleteDuringRead.

@Test(timeout = 60000)
public void deleteDuringRead() throws Exception {
    String name = "distrlog-delete-with-reader";
    DistributedLogManager dlm = createNewDLM(conf, name);
    long txid = 1;
    for (long i = 0; i < 3; i++) {
        long start = txid;
        BKSyncLogWriter writer = (BKSyncLogWriter) dlm.startLogSegmentNonPartitioned();
        for (long j = 1; j <= DEFAULT_SEGMENT_SIZE; j++) {
            writer.write(DLMTestUtil.getLogRecordInstance(txid++));
        }
        BKLogSegmentWriter perStreamLogWriter = writer.getCachedLogWriter();
        writer.closeAndComplete();
        BKLogWriteHandler blplm = ((BKDistributedLogManager) (dlm)).createWriteHandler(true);
        assertNotNull(zkc.exists(blplm.completedLedgerZNode(start, txid - 1, perStreamLogWriter.getLogSegmentSequenceNumber()), false));
        Utils.ioResult(blplm.asyncClose());
    }
    LogReader reader = dlm.getInputStream(1);
    LogRecord record = reader.readNext(false);
    assert (null != record);
    DLMTestUtil.verifyLogRecord(record);
    long lastTxId = record.getTransactionId();
    dlm.delete();
    boolean exceptionEncountered;
    try {
        record = reader.readNext(false);
        while (null != record) {
            DLMTestUtil.verifyLogRecord(record);
            assert (lastTxId < record.getTransactionId());
            lastTxId = record.getTransactionId();
            record = reader.readNext(false);
        }
        // make sure the exception is thrown from readahead
        while (true) {
            reader.readNext(false);
        }
    } catch (LogReadException | LogNotFoundException | DLIllegalStateException e) {
        exceptionEncountered = true;
    }
    assertTrue(exceptionEncountered);
    reader.close();
}
Also used : LogReadException(org.apache.distributedlog.exceptions.LogReadException) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LogReader(org.apache.distributedlog.api.LogReader) AsyncLogReader(org.apache.distributedlog.api.AsyncLogReader) DLIllegalStateException(org.apache.distributedlog.exceptions.DLIllegalStateException) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException) Test(org.junit.Test)

Example 14 with LogNotFoundException

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

the class ZKLogSegmentMetadataStore method processResult.

@Override
@SuppressWarnings("unchecked")
public void processResult(int rc, String path, Object ctx, List<String> children, Stat stat) {
    CompletableFuture<Versioned<List<String>>> result = ((CompletableFuture<Versioned<List<String>>>) ctx);
    if (KeeperException.Code.OK.intValue() == rc) {
        /**
         * cversion: the number of changes to the children of this znode *
         */
        LongVersion zkVersion = new LongVersion(stat.getCversion());
        result.complete(new Versioned(children, zkVersion));
    } else if (KeeperException.Code.NONODE.intValue() == rc) {
        result.completeExceptionally(new LogNotFoundException("Log " + path + " not found"));
    } else {
        result.completeExceptionally(new ZKException("Failed to get log segments from " + path, KeeperException.Code.get(rc)));
    }
}
Also used : ZKException(org.apache.distributedlog.exceptions.ZKException) Versioned(org.apache.bookkeeper.versioning.Versioned) LongVersion(org.apache.bookkeeper.versioning.LongVersion) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException)

Example 15 with LogNotFoundException

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

the class TestBKLogReadHandler method testGetLogRecordCountEmptyLedger.

@Test(timeout = 60000)
public void testGetLogRecordCountEmptyLedger() throws Exception {
    String dlName = runtime.getMethodName();
    DistributedLogManager dlm = createNewDLM(conf, dlName);
    BKLogReadHandler readHandler = ((BKDistributedLogManager) dlm).createReadHandler();
    CompletableFuture<Long> count = null;
    count = readHandler.asyncGetLogRecordCount(DLSN.InitialDLSN);
    try {
        Utils.ioResult(count);
        fail("log is empty, should have returned log empty ex");
    } catch (LogNotFoundException ex) {
    }
}
Also used : DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) LogNotFoundException(org.apache.distributedlog.exceptions.LogNotFoundException) Test(org.junit.Test)

Aggregations

LogNotFoundException (org.apache.distributedlog.exceptions.LogNotFoundException)17 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)8 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 LogReader (org.apache.distributedlog.api.LogReader)4 DLInterruptedException (org.apache.distributedlog.exceptions.DLInterruptedException)4 LogEmptyException (org.apache.distributedlog.exceptions.LogEmptyException)4 List (java.util.List)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ZooKeeperConnectionException (org.apache.distributedlog.ZooKeeperClient.ZooKeeperConnectionException)3 ZKException (org.apache.distributedlog.exceptions.ZKException)3 BufferedOutputStream (java.io.BufferedOutputStream)2 URI (java.net.URI)2 LinkedList (java.util.LinkedList)2 DLSN (org.apache.distributedlog.DLSN)2 ZooKeeperClient (org.apache.distributedlog.ZooKeeperClient)2 AsyncLogWriter (org.apache.distributedlog.api.AsyncLogWriter)2 DLIllegalStateException (org.apache.distributedlog.exceptions.DLIllegalStateException)2 BufferedFSInputStream (org.apache.hadoop.fs.BufferedFSInputStream)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2