use of org.apache.distributedlog.exceptions.DLIllegalStateException in project bookkeeper by apache.
the class BKLogSegmentEntryReader method readEntriesFromReadAheadCache.
private void readEntriesFromReadAheadCache(PendingReadRequest nextRequest) {
while (!nextRequest.hasReadEnoughEntries()) {
CacheEntry entry;
boolean hitEndOfLogSegment;
synchronized (this) {
entry = readAheadEntries.peek();
hitEndOfLogSegment = (null == entry) && isEndOfLogSegment();
}
// reach end of log segment
if (hitEndOfLogSegment) {
completeExceptionally(new EndOfLogSegmentException(getSegment().getZNodeName()), false);
return;
}
if (null == entry) {
return;
}
// entry is not complete yet.
if (!entry.isDone()) {
// we already reached end of the log segment
if (isEndOfLogSegment(entry.getEntryId())) {
completeExceptionally(new EndOfLogSegmentException(getSegment().getZNodeName()), false);
}
return;
}
if (entry.isSuccess()) {
CacheEntry removedEntry = readAheadEntries.poll();
try {
if (entry != removedEntry) {
DLIllegalStateException ise = new DLIllegalStateException("Unexpected condition at reading from " + getSegment());
completeExceptionally(ise, false);
return;
}
try {
// the reference is retained on `entry.getEntry()`.
// Entry.Reader is responsible for releasing it.
nextRequest.addEntry(processReadEntry(entry.getEntry()));
} catch (IOException e) {
completeExceptionally(e, false);
return;
}
} finally {
removedEntry.release();
}
} else if (skipBrokenEntries && BKException.Code.DigestMatchException == entry.getRc()) {
// skip this entry and move forward
skippedBrokenEntriesCounter.inc();
CacheEntry removedEntry = readAheadEntries.poll();
removedEntry.release();
continue;
} else {
completeExceptionally(new BKTransmitException("Encountered issue on reading entry " + entry.getEntryId() + " @ log segment " + getSegment(), entry.getRc()), false);
return;
}
}
}
use of org.apache.distributedlog.exceptions.DLIllegalStateException in project bookkeeper by apache.
the class BKLogSegmentEntryReader method safeRun.
/**
* The core function to propagate fetched entries to read requests.
*/
@Override
public void safeRun() {
long scheduleCountLocal = scheduleCountUpdater.get(this);
while (true) {
PendingReadRequest nextRequest = null;
synchronized (readQueue) {
nextRequest = readQueue.peek();
}
// if read queue is empty, nothing to read, return
if (null == nextRequest) {
scheduleCountUpdater.set(this, 0L);
return;
}
// we don't know the last consumed read
if (null == lastExceptionUpdater.get(this)) {
if (nextRequest.getPromise().isCancelled()) {
completeExceptionally(new DLInterruptedException("Interrupted on reading log segment " + getSegment() + " : " + nextRequest.getPromise().isCancelled()), false);
}
}
// if the reader is in error state, stop read
if (checkClosedOrInError()) {
return;
}
// read entries from readahead cache to satisfy next read request
readEntriesFromReadAheadCache(nextRequest);
// check if we can satisfy the read request
if (nextRequest.hasReadEntries()) {
PendingReadRequest request;
synchronized (readQueue) {
request = readQueue.poll();
}
if (null != request && nextRequest == request) {
request.complete();
} else {
DLIllegalStateException ise = new DLIllegalStateException("Unexpected condition at reading from " + getSegment());
nextRequest.completeExceptionally(ise);
if (null != request) {
request.completeExceptionally(ise);
}
completeExceptionally(ise, false);
}
} else {
if (0 == scheduleCountLocal) {
return;
}
scheduleCountLocal = scheduleCountUpdater.decrementAndGet(this);
}
}
}
Aggregations