reswqa commented on code in PR #24688:
URL: https://github.com/apache/flink/pull/24688#discussion_r1572088653
##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/hybrid/tiered/storage/SortBufferAccumulator.java:
##########
@@ -338,11 +365,22 @@ private Buffer requestBuffer() {
}
private void releaseFreeBuffers() {
- freeSegments.forEach(this::recycleBuffer);
- freeSegments.clear();
+ synchronized (lock) {
+ isDataBufferReleased = true;
+ freeSegments.forEach(this::recycleBuffer);
+ freeSegments.clear();
+ }
}
private void recycleBuffer(MemorySegment memorySegment) {
- checkNotNull(bufferRecycler).recycle(memorySegment);
+ synchronized (lock) {
+ if (!isDataBufferReleased
+ && currentDataBuffer != null
+ && !currentDataBuffer.isReleased()) {
+ freeSegments.add(memorySegment);
Review Comment:
We have multiple threads touching `freeSegement`, and it does need to be
protected by a lock. This is the protocol of this class, in case another
developer makes a mistake.
I know we can ensure that some methods are safe enough, and for the
performance reason, we can leave it unlocked. We could introduce a
`@SuppressWarnings` mark and explain clearly why it is safe with comment.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]