use of com.twitter.distributedlog.exceptions.LogEmptyException in project distributedlog by twitter.
the class BKLogHandler method asyncGetLastLogRecord.
private void asyncGetLastLogRecord(final Iterator<LogSegmentMetadata> ledgerIter, final Promise<LogRecordWithDLSN> promise, final boolean fence, final boolean includeControlRecord, final boolean includeEndOfStream) {
if (ledgerIter.hasNext()) {
LogSegmentMetadata metadata = ledgerIter.next();
asyncReadLastRecord(metadata, fence, includeControlRecord, includeEndOfStream).addEventListener(new FutureEventListener<LogRecordWithDLSN>() {
@Override
public void onSuccess(LogRecordWithDLSN record) {
if (null == record) {
asyncGetLastLogRecord(ledgerIter, promise, fence, includeControlRecord, includeEndOfStream);
} else {
promise.setValue(record);
}
}
@Override
public void onFailure(Throwable cause) {
promise.setException(cause);
}
});
} else {
promise.setException(new LogEmptyException("Log " + getFullyQualifiedName() + " has no records"));
}
}
use of com.twitter.distributedlog.exceptions.LogEmptyException in project distributedlog by twitter.
the class BKLogHandler method forceGetLedgerList.
/**
* Get a list of all segments in the journal.
*/
protected List<LogSegmentMetadata> forceGetLedgerList(final Comparator<LogSegmentMetadata> comparator, final LogSegmentFilter segmentFilter, boolean throwOnEmpty) throws IOException {
final List<LogSegmentMetadata> ledgers = new ArrayList<LogSegmentMetadata>();
final AtomicInteger result = new AtomicInteger(-1);
final CountDownLatch latch = new CountDownLatch(1);
Stopwatch stopwatch = Stopwatch.createStarted();
asyncGetLedgerListInternal(comparator, segmentFilter, null, new GenericCallback<List<LogSegmentMetadata>>() {
@Override
public void operationComplete(int rc, List<LogSegmentMetadata> logSegmentMetadatas) {
result.set(rc);
if (KeeperException.Code.OK.intValue() == rc) {
ledgers.addAll(logSegmentMetadatas);
} else {
LOG.error("Failed to get ledger list for {} : with error {}", getFullyQualifiedName(), rc);
}
latch.countDown();
}
}, new AtomicInteger(conf.getZKNumRetries()), new AtomicLong(conf.getZKRetryBackoffStartMillis()));
try {
latch.await();
} catch (InterruptedException e) {
forceGetListStat.registerFailedEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS));
throw new DLInterruptedException("Interrupted on reading ledger list from zkfor " + getFullyQualifiedName(), e);
}
long elapsedMicros = stopwatch.stop().elapsed(TimeUnit.MICROSECONDS);
KeeperException.Code rc = KeeperException.Code.get(result.get());
if (rc == KeeperException.Code.OK) {
forceGetListStat.registerSuccessfulEvent(elapsedMicros);
} else {
forceGetListStat.registerFailedEvent(elapsedMicros);
if (KeeperException.Code.NONODE == rc) {
throw new LogNotFoundException("Log " + getFullyQualifiedName() + " is not found");
} else {
throw new IOException("ZK Exception " + rc + " reading ledger list for " + getFullyQualifiedName());
}
}
if (throwOnEmpty && ledgers.isEmpty()) {
throw new LogEmptyException("Log " + getFullyQualifiedName() + " is empty");
}
return ledgers;
}
use of com.twitter.distributedlog.exceptions.LogEmptyException in project distributedlog by twitter.
the class BKLogHandler method asyncForceGetLedgerList.
protected Future<List<LogSegmentMetadata>> asyncForceGetLedgerList(final Comparator<LogSegmentMetadata> comparator, final LogSegmentFilter segmentFilter, final boolean throwOnEmpty) {
final Promise<List<LogSegmentMetadata>> promise = new Promise<List<LogSegmentMetadata>>();
final Stopwatch stopwatch = Stopwatch.createStarted();
asyncGetLedgerListWithRetries(comparator, segmentFilter, null).addEventListener(new FutureEventListener<List<LogSegmentMetadata>>() {
@Override
public void onSuccess(List<LogSegmentMetadata> ledgers) {
forceGetListStat.registerSuccessfulEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS));
if (ledgers.isEmpty() && throwOnEmpty) {
promise.setException(new LogEmptyException("Log " + getFullyQualifiedName() + " is empty"));
} else {
promise.setValue(ledgers);
}
}
@Override
public void onFailure(Throwable cause) {
forceGetListStat.registerFailedEvent(stopwatch.stop().elapsed(TimeUnit.MICROSECONDS));
promise.setException(cause);
}
});
return promise;
}
Aggregations