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