zhijiangW commented on a change in pull request #9993: 
[FLINK-14498][runtime]Introduce NetworkBufferPool#isAvailable() for interacting 
with LocalBufferPool.
URL: https://github.com/apache/flink/pull/9993#discussion_r338962572
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/buffer/NetworkBufferPool.java
 ##########
 @@ -142,14 +147,33 @@ public NetworkBufferPool(
 
        @Nullable
        public MemorySegment requestMemorySegment() {
-               return availableMemorySegments.poll();
+               synchronized (availabilityHelper) {
+                       final MemorySegment segment = 
availableMemorySegments.poll();
+                       if (availableMemorySegments.isEmpty() && segment != 
null) {
+                               availabilityHelper.resetUnavailable();
+                       }
+                       return segment;
+               }
        }
 
        public void recycle(MemorySegment segment) {
                // Adds the segment back to the queue, which does not 
immediately free the memory
                // however, since this happens when references to the global 
pool are also released,
                // making the availableMemorySegments queue and its contained 
object reclaimable
-               availableMemorySegments.add(checkNotNull(segment));
+               checkNotNull(segment);
+               CompletableFuture<?> toNotify = null;
 
 Review comment:
   If possible we need to consider deduplicating codes with below 
`recycleMemorySegments(Collection<MemorySegment> segments, int size)`. There is 
only `availableMemorySegments.add(segment);` different.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to