zuston commented on code in PR #1659:
URL: 
https://github.com/apache/incubator-uniffle/pull/1659#discussion_r1582584069


##########
common/src/main/java/org/apache/uniffle/common/netty/buffer/FileSegmentManagedBuffer.java:
##########
@@ -58,33 +60,40 @@ public ByteBuf byteBuf() {
 
   @Override
   public ByteBuffer nioByteBuffer() {
+    if (isFilled) {
+      return readByteBuffer;
+    }
     FileChannel channel = null;
     try {
       channel = new RandomAccessFile(file, "r").getChannel();
-      ByteBuffer buf = ByteBuffer.allocate(length);
+      readByteBuffer = ByteBuffer.allocate(length);
       channel.position(offset);
-      while (buf.remaining() != 0) {
-        if (channel.read(buf) == -1) {
+      while (readByteBuffer.remaining() != 0) {
+        if (channel.read(readByteBuffer) == -1) {
           throw new IOException(
               String.format(
                   "Reached EOF before filling 
buffer.offset=%s,file=%s,buf.remaining=%s",
-                  offset, file.getAbsoluteFile(), buf.remaining()));
+                  offset, file.getAbsoluteFile(), readByteBuffer.remaining()));
         }
       }
-      buf.flip();
-      return buf;
+      readByteBuffer.flip();
+      isFilled = true;
+      return readByteBuffer;

Review Comment:
   Can we make this as readOnlyBuffer? `return buf.asReadOnlyBuffer();`



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to