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));
}
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());
}
}
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();
}
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)));
}
}
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) {
}
}
Aggregations