xumanbu commented on code in PR #1659:
URL:
https://github.com/apache/incubator-uniffle/pull/1659#discussion_r1582582820
##########
common/src/main/java/org/apache/uniffle/common/netty/buffer/FileSegmentManagedBuffer.java:
##########
@@ -58,27 +60,32 @@ 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;
} catch (IOException e) {
- String errorMessage = "Error in reading " + this;
+ String errorMessage = "Error in reading file " + file + " " + this;
try {
if (channel != null) {
long size = channel.size();
- errorMessage = "Error in reading " + this + " (actual file length "
+ size + ")";
+ errorMessage =
Review Comment:
fixed.
--
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]