Skip to content

Commit

Permalink
Assert IO is still owned by the region after read and write (elastic#…
Browse files Browse the repository at this point in the history
…103100)

When the code path goes to CacheFile#populateAndRead, both the read and
write are performed when holding the reference of the file region
(elastic#102843). Therefore we should be able to assert that the region
ownership throughout the processes.
  • Loading branch information
ywangd authored Dec 7, 2023
1 parent 37d6690 commit a245fdc
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,8 @@ private RangeMissingHandler writerWithOffset(RangeMissingHandler writer, CacheFi
return (channel, channelPos, relativePos, len, progressUpdater) -> {
assert assertValidRegionAndLength(fileRegion, channelPos, len);
adjustedWriter.fillCacheRange(channel, channelPos, relativePos, len, progressUpdater);
assert regionOwners.get(fileRegion.io) == fileRegion
: "File chunk [" + fileRegion.regionKey + "] no longer owns IO [" + fileRegion.io + "]";
};
}
return adjustedWriter;
Expand All @@ -932,7 +934,10 @@ private RangeAvailableHandler readerWithOffset(RangeAvailableHandler reader, Cac
if (Assertions.ENABLED) {
return (channel, channelPos, relativePos, len) -> {
assert assertValidRegionAndLength(fileRegion, channelPos, len);
return adjustedReader.onRangeAvailable(channel, channelPos, relativePos, len);
final int bytesRead = adjustedReader.onRangeAvailable(channel, channelPos, relativePos, len);
assert regionOwners.get(fileRegion.io) == fileRegion
: "File chunk [" + fileRegion.regionKey + "] no longer owns IO [" + fileRegion.io + "]";
return bytesRead;
};
}
return adjustedReader;
Expand Down

0 comments on commit a245fdc

Please sign in to comment.