You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@celeborn.apache.org by "zhongqiangczq (via GitHub)" <gi...@apache.org> on 2023/03/16 01:51:59 UTC

[GitHub] [incubator-celeborn] zhongqiangczq commented on a diff in pull request #1352: [CELEBORN-428][FLINK] Remove unnecessary lock in PartitionSortedBuffer

zhongqiangczq commented on code in PR #1352:
URL: https://github.com/apache/incubator-celeborn/pull/1352#discussion_r1136652758


##########
client-flink/common/src/main/java/org/apache/celeborn/plugin/flink/buffer/PartitionSortedBuffer.java:
##########
@@ -201,18 +201,20 @@ private void writeRecord(ByteBuffer source) {
 
   private boolean allocateBuffersForRecord(int numRecordBytes) throws IOException {
     int numBytesRequired = INDEX_ENTRY_SIZE + numRecordBytes;
-    int availableBytes = writeSegmentIndex == buffers.size() ? 0 : bufferSize - writeSegmentOffset;
+    int currentBufferAvailableBytes =
+        writeSegmentIndex == buffers.size() ? 0 : bufferSize - writeSegmentOffset;
 
     // return directly if current available bytes is adequate
-    if (availableBytes >= numBytesRequired) {
+    if (currentBufferAvailableBytes >= numBytesRequired) {
       return true;
     }
 
     // skip the remaining free space if the available bytes is not enough for an index entry
-    if (availableBytes < INDEX_ENTRY_SIZE) {
-      updateWriteSegmentIndexAndOffset(availableBytes);
-      availableBytes = 0;
+    if (currentBufferAvailableBytes < INDEX_ENTRY_SIZE) {
+      updateWriteSegmentIndexAndOffset(currentBufferAvailableBytes);
     }
+    int totalAvailableBytes =
+        (buffers.size() - writeSegmentIndex) * bufferSize - writeSegmentOffset;

Review Comment:
   if currentBufferAvailableBytes < INDEX_ENTRY_SIZE then updateWriteSegmentIndexAndOffset, writeSegmentIndex will ++
    now writeSegmentIndex equals buffers.size(),so  totalAvailableBytes will be negative(-writeSegmentOffset)



-- 
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: issues-unsubscribe@celeborn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org