You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2019/03/04 16:01:51 UTC
[GitHub] [bookkeeper] ivankelly commented on a change in pull request #1973:
[DLOG] Avoid double read in readahead
ivankelly commented on a change in pull request #1973: [DLOG] Avoid double read in readahead
URL: https://github.com/apache/bookkeeper/pull/1973#discussion_r262125139
##########
File path: stream/distributedlog/core/src/main/java/org/apache/distributedlog/ReadAheadEntryReader.java
##########
@@ -942,25 +948,60 @@ private void unsafeMoveToNextLogSegment() {
readHandler.getFullyQualifiedName());
isCatchingUp = false;
}
- pauseReadAheadOnNoMoreLogSegments();
}
+
+ scheduleRead();
}
- void scheduleReadNext() {
+ void completeRead() {
orderedSubmit(new CloseableRunnable() {
- @Override
- public void safeRun() {
- if (null == currentSegmentReader) {
- pauseReadAheadOnNoMoreLogSegments();
- return;
+ @Override
+ public void safeRun() {
+ if (logger.isDebugEnabled()) {
+ logger.debug("[{}][state:{}] Read completed", streamName, state);
+ }
+ if (state == State.READING) {
+ state = State.IDLE;
+ }
}
- unsafeReadNext(currentSegmentReader);
- }
- });
+ });
}
- private void unsafeReadNext(SegmentReader reader) {
- reader.readNext().whenComplete(this);
+ void scheduleRead() {
+ orderedSubmit(new CloseableRunnable() {
+ @Override
+ public void safeRun() {
+
+ boolean cacheFull = isCacheFull();
+ SegmentReader reader = currentSegmentReader;
+ boolean hasMoreSegments = reader != null;
+ if (logger.isDebugEnabled()) {
+ logger.debug("[{}][state:{}] scheduling read, cacheFull {}, hasMoreSegments {}",
+ streamName, state, cacheFull, hasMoreSegments);
+ }
+ switch (state) {
+ case IDLE:
+ if (cacheFull || !hasMoreSegments) {
+ state = State.PAUSED;
+ } else {
+ reader.readNext().whenComplete(ReadAheadEntryReader.this);
+ state = State.READING;
+ }
+ break;
+ case PAUSED:
+ if (!cacheFull && hasMoreSegments) {
+ reader.readNext().whenComplete(ReadAheadEntryReader.this);
+ state = State.READING;
+ }
+ break;
+ case READING:
+ case ERROR:
+ case CLOSED:
+ // do nothing
Review comment:
nah, we already know if we're going to hit this branch from the debug log above.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services