Skip to content
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

Improve DefaultEntryLogger read performance. #4038

Merged
merged 13 commits into from
Feb 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class BufferedReadChannel extends BufferedChannelBase {

long invocationCount = 0;
long cacheHitCount = 0;
private long fileSize = -1;

public BufferedReadChannel(FileChannel fileChannel, int readCapacity) {
super(fileChannel);
Expand All @@ -64,10 +65,18 @@ public int read(ByteBuf dest, long pos) throws IOException {
return read(dest, pos, dest.writableBytes());
}

@Override
public long size() throws IOException {
if (fileSize == -1) {
fileSize = validateAndGetFileChannel().size();
}
return fileSize;
}

public synchronized int read(ByteBuf dest, long pos, int length) throws IOException {
invocationCount++;
long currentPosition = pos;
long eof = validateAndGetFileChannel().size();
long eof = size();
// return -1 if the given position is greater than or equal to the file's current size.
if (pos >= eof) {
return -1;
Expand Down
Loading