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

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/buffer/NetworkBufferPool.java
 ##########
 @@ -170,9 +180,13 @@ public void recycle(MemorySegment segment) {
                                        throw new IllegalStateException("Buffer 
pool is destroyed.");
                                }
 
-                               final MemorySegment segment = 
availableMemorySegments.poll(2, TimeUnit.SECONDS);
-                               if (segment != null) {
-                                       segments.add(segment);
+                               synchronized (availabilityHelper) {
 
 Review comment:
   +1 for replacing the `ArrayBlockingQueue` with a custom lock here.
   
   But maybe we can go one step further, and unify this locking object with 
`synchronized (factoryLock)`? Instead of taking two locks separately, we might 
be able to have just one? This would both simplify the code and improve the 
performance, however performance here probably doesn't matter that much, but 
looking at one method that synchronizes on two different objects is a bit 
confusing and triggers the question "why?"
   
   For example, I think this particular method could be just wrapped as a whole 
in the `synchronized (availabilityHelper) {` block.
   
   While doing so it might be possible to simplify the concurrency model even 
further, and replace `private volatile boolean isDestroyed;` with just `private 
boolean isDestroyed;`.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to