Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -559,31 +559,32 @@ protected int peekNextBufferSubpartitionIdInternal() throws IOException {
public Optional<BufferAndAvailability> getNextBuffer() throws IOException {
checkError();

// Read inRecovery and poll the recovered buffer under a single lock acquisition to avoid
// grabbing the monitor twice on the hot path.
boolean inRecovery;
Buffer recoveredBuf = null;
synchronized (recoveredBuffers) {
inRecovery = this.inRecovery;
if (inRecovery && !hasPendingPriorityEvent && !recoveredBuffers.isEmpty()) {
recoveredBuf = recoveredBuffers.poll();
if (needsRecovery) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: just wrap inRecovery with if (needsRecovery) {

// Read inRecovery and poll the recovered buffer under a single lock acquisition to
// avoid grabbing the monitor twice on the hot path.
boolean inRecovery;
Buffer recoveredBuf = null;
synchronized (recoveredBuffers) {
inRecovery = this.inRecovery;
if (inRecovery && !hasPendingPriorityEvent && !recoveredBuffers.isEmpty()) {
recoveredBuf = recoveredBuffers.poll();
}
}
}

if (inRecovery) {
// Always return an already-polled recovered buffer first: hasPendingPriorityEvent may
// be flipped to true by a concurrent notifyPriorityEvent() after the poll, and
// re-reading
// it here would otherwise drop this buffer. A pending priority event is served on the
// next getNextBuffer() call instead.
if (recoveredBuf != null) {
return wrapRecoveredBufferAsAvailability(recoveredBuf);
}
if (hasPendingPriorityEvent) {
return pullPriorityFromSubpartitionView();
if (inRecovery) {
// Always return an already-polled recovered buffer first: hasPendingPriorityEvent
// may be flipped to true by a concurrent notifyPriorityEvent() after the poll, and
// re-reading it here would otherwise drop this buffer. A pending priority event is
// served on the next getNextBuffer() call instead.
if (recoveredBuf != null) {
return wrapRecoveredBufferAsAvailability(recoveredBuf);
}
if (hasPendingPriorityEvent) {
return pullPriorityFromSubpartitionView();
}
// Drain not finished yet; block normal upstream data until delivery completes.
return Optional.empty();
}
// Drain not finished yet; block normal upstream data until delivery completes.
return Optional.empty();
}

if (!toBeConsumedBuffers.isEmpty()) {
Expand Down