Skip to content

Commit

Permalink
fix: check capacity before cached read
Browse files Browse the repository at this point in the history
Signed-off-by: Ning Yu <[email protected]>
  • Loading branch information
Chillax-0v0 committed Jan 30, 2024
1 parent 6e60a47 commit 55d7432
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import io.netty.buffer.ByteBuf;
import java.io.IOException;

import static com.automq.stream.s3.Constants.CAPACITY_NOT_SET;

/**
* A wrapper of {@link WALChannel} that caches for read to reduce I/O.
*/
Expand Down Expand Up @@ -52,6 +54,10 @@ public static WALCachedChannel of(WALChannel channel, int cacheSize) {
*/
@Override
public synchronized int read(ByteBuf dst, long position, int length) throws IOException {
if (CAPACITY_NOT_SET == channel.capacity()) {
// If we don't know the capacity now, we can't cache.
return channel.read(dst, position, length);
}
long start = position;
length = Math.min(length, dst.writableBytes());
long end = position + length;
Expand Down

0 comments on commit 55d7432

Please sign in to comment.