Github user NicoK commented on a diff in the pull request:
https://github.com/apache/flink/pull/4559#discussion_r153564859
--- Diff:
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/ResultSubpartitionView.java
---
@@ -22,32 +22,52 @@
import java.io.IOException;
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
/**
* A view to consume a {@link ResultSubpartition} instance.
*/
-public interface ResultSubpartitionView {
+public abstract class ResultSubpartitionView {
+
+ /** The parent subpartition this view belongs to. */
+ private final ResultSubpartition parent;
+
+ public ResultSubpartitionView(ResultSubpartition parent) {
+ this.parent = checkNotNull(parent);
+ }
/**
* Returns the next {@link Buffer} instance of this queue iterator.
- * <p>
- * If there is currently no instance available, it will return
<code>null</code>.
+ *
+ * <p>If there is currently no instance available, it will return
<code>null</code>.
* This might happen for example when a pipelined queue producer is
slower
* than the consumer or a spilled queue needs to read in more data.
- * <p>
- * <strong>Important</strong>: The consumer has to make sure that each
+ *
+ * <p><strong>Important</strong>: The consumer has to make sure that
each
* buffer instance will eventually be recycled with {@link
Buffer#recycle()}
* after it has been consumed.
*/
- Buffer getNextBuffer() throws IOException, InterruptedException;
+ public Buffer getNextBuffer() throws IOException, InterruptedException {
+ Buffer buffer = getNextBufferInternal();
+ if (buffer != null) {
+ parent.decreaseStatistics(buffer);
+ }
+ return buffer;
+ }
+
+ public int getBuffersInBacklog() {
+ return parent.getBuffersInBacklog();
+ }
- void notifyBuffersAvailable(long buffers) throws IOException;
+ protected abstract Buffer getNextBufferInternal() throws IOException,
InterruptedException;
--- End diff --
please add a javadoc with the intended relation to `getNextBuffer`
---