Skip to content

Commit

Permalink
Fix try-read.
Browse files Browse the repository at this point in the history
  • Loading branch information
henningandersen committed Jan 24, 2024
1 parent c2ad2c6 commit 5d406c4
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -745,13 +745,23 @@ private static void throwAlreadyEvicted() {
throwAlreadyClosed("File chunk is evicted");
}

/**
* Optimistically try to read from the region
* @return true if successful, i.e., not evicted and data available, false if evicted
*/
boolean tryRead(ByteBuffer buf, long offset) throws IOException {
int readBytes = io.read(buf, getRegionRelativePosition(offset));
if (isEvicted()) {
buf.position(buf.position() - readBytes);
SharedBytes.IO io = this.io;
if (io != null) {
int readBytes = io.read(buf, getRegionRelativePosition(offset));
if (isEvicted()) {
buf.position(buf.position() - readBytes);
return false;
}
return true;
} else {
// taken by someone else
return false;
}
return true;
}

/**
Expand Down

0 comments on commit 5d406c4

Please sign in to comment.