flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [flink] zhijiangW commented on a change in pull request #7911: [FLINK-11082][network] Fix the logic of getting backlog in sub partition
Date Tue, 12 Mar 2019 02:36:57 GMT
zhijiangW commented on a change in pull request #7911: [FLINK-11082][network] Fix the logic
of getting backlog in sub partition
URL: https://github.com/apache/flink/pull/7911#discussion_r264501442
 
 

 ##########
 File path: flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/ResultSubpartition.java
 ##########
 @@ -116,52 +115,58 @@ protected Throwable getFailureCause() {
 
 	public abstract boolean isReleased();
 
-	/**
-	 * Gets the number of non-event buffers in this subpartition.
-	 *
-	 * <p><strong>Beware:</strong> This method should only be used in tests
in non-concurrent access
-	 * scenarios since it does not make any concurrency guarantees.
-	 */
-	@VisibleForTesting
-	public int getBuffersInBacklog() {
-		return buffersInBacklog;
-	}
-
 	/**
 	 * Makes a best effort to get the current size of the queue.
 	 * This method must not acquire locks or interfere with the task and network threads in
 	 * any way.
 	 */
 	public abstract int unsynchronizedGetNumberOfQueuedBuffers();
 
+	/**
+	 * Gets the number of non-event buffers in this subpartition.
+	 */
+	public abstract int getBuffersInBacklog();
+
+	/**
+	 * @param lastBufferAvailable whether the last buffer in this subpartition is available
for consumption
+	 * @return the number of non-event buffers in this subpartition
+	 */
+	protected int getBuffersInBacklog(boolean lastBufferAvailable) {
+		assert Thread.holdsLock(buffers);
+
+		if (lastBufferAvailable) {
+			return buffersInBacklog;
+		} else {
+			return Math.max(buffersInBacklog - 1, 0);
+		}
+	}
+
 	/**
 	 * Decreases the number of non-event buffers by one after fetching a non-event
 	 * buffer from this subpartition (for access by the subpartition views).
-	 *
-	 * @return backlog after the operation
 	 */
-	public int decreaseBuffersInBacklog(Buffer buffer) {
+	public void decreaseBuffersInBacklogUnsafe(boolean isBuffer) {
 		synchronized (buffers) {
-			return decreaseBuffersInBacklogUnsafe(buffer != null && buffer.isBuffer());
+			decreaseBuffersInBacklog(isBuffer);
 		}
 	}
 
-	protected int decreaseBuffersInBacklogUnsafe(boolean isBuffer) {
+	protected void decreaseBuffersInBacklog(boolean isBuffer) {
 		assert Thread.holdsLock(buffers);
+
 		if (isBuffer) {
 			buffersInBacklog--;
 		}
-		return buffersInBacklog;
 	}
 
 	/**
 	 * Increases the number of non-event buffers by one after adding a non-event
 	 * buffer into this subpartition.
 	 */
-	protected void increaseBuffersInBacklog(BufferConsumer buffer) {
+	protected void increaseBuffersInBacklog(boolean isBuffer) {
 
 Review comment:
   Yes, I try to keep it consistent with another method. I should make it in a separate commit.

----------------------------------------------------------------
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

Mime
View raw message