-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#1658] fix(server): FileSegmentManagedBuffer#nioByteBuffer read result cacheable #1659
Conversation
PTAL. @dingshun3016 @zuston @jerqi |
Test Results 2 398 files +14 2 398 suites +14 4h 38m 33s ⏱️ + 6m 5s Results for commit 8740feb. ± Comparison against base commit 5ab625b. This pull request removes 1 and adds 3 tests. Note that renamed tests count towards both.
♻️ This comment has been updated with latest results. |
Could you help review this? @rickyma |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments. I'm OK with this patch. But you need to test it more carefully. Because this is used in gRPC mode. It won't be invoked in Netty mode. So I don't know how it actually performs in a production environment. Because I currently use Netty in my environment.
@@ -39,6 +39,8 @@ public class FileSegmentManagedBuffer extends ManagedBuffer { | |||
private final File file; | |||
private final long offset; | |||
private final int length; | |||
private boolean isFilled; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we don't need isFilled
at all. I think it can be replaced by readByteBuffer != null
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The readByteBuffer
may be allocated but not filled with bytes, indicating a failure to read the file. Therefore, I believe adding another state for reliability is necessary.
} catch (IOException e) { | ||
String errorMessage = "Error in reading " + this; | ||
String errorMessage = "Error in reading file " + file + " " + this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better if we use String.format
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. fixed.
try { | ||
if (channel != null) { | ||
long size = channel.size(); | ||
errorMessage = "Error in reading " + this + " (actual file length " + size + ")"; | ||
errorMessage = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
Oh I thought this is netty. I will take another look tomorrow. |
Could you add a ut if this is a fix? |
ok. added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late reply.
Nice improvement, this is useful for AQE skew tasks. Left minor comments. @xumanbu
return buf; | ||
readByteBuffer.flip(); | ||
isFilled = true; | ||
return readByteBuffer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this as readOnlyBuffer? return buf.asReadOnlyBuffer();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested it, but it doesn't work. ReadOnlyBuffer
will throw a ReadOnlyBufferException
when calling buffer.array()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pity. I want to ensure the readBuffer will not be changed after cached.
8740feb
to
08e7397
Compare
…d result cacheable
@jerqi mistakenly discarded changes before committing. I've recommitted them. Could you help me reopen this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for this. Thanks for your contribution. If no one reject this, I will merge this in the next 2 days.
@rickyma Do u have another suggestion? |
Nope. LGTM. But I did not test this. |
Ok. Let's merge this. |
What changes were proposed in this pull request?
FileSegmentManagedBuffer#nioByteBuffer add a buffer to hold read file result to avoid multiple read file
Why are the changes needed?
Fix: #1658
Does this PR introduce any user-facing change?
No.
How was this patch tested?
existed UT