Skip to content

Commit a245fdc

Browse files
authored
Assert IO is still owned by the region after read and write (#103100)
When the code path goes to CacheFile#populateAndRead, both the read and write are performed when holding the reference of the file region (#102843). Therefore we should be able to assert that the region ownership throughout the processes.
1 parent 37d6690 commit a245fdc

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

x-pack/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/shared/SharedBlobCacheService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,8 @@ private RangeMissingHandler writerWithOffset(RangeMissingHandler writer, CacheFi
917917
return (channel, channelPos, relativePos, len, progressUpdater) -> {
918918
assert assertValidRegionAndLength(fileRegion, channelPos, len);
919919
adjustedWriter.fillCacheRange(channel, channelPos, relativePos, len, progressUpdater);
920+
assert regionOwners.get(fileRegion.io) == fileRegion
921+
: "File chunk [" + fileRegion.regionKey + "] no longer owns IO [" + fileRegion.io + "]";
920922
};
921923
}
922924
return adjustedWriter;
@@ -932,7 +934,10 @@ private RangeAvailableHandler readerWithOffset(RangeAvailableHandler reader, Cac
932934
if (Assertions.ENABLED) {
933935
return (channel, channelPos, relativePos, len) -> {
934936
assert assertValidRegionAndLength(fileRegion, channelPos, len);
935-
return adjustedReader.onRangeAvailable(channel, channelPos, relativePos, len);
937+
final int bytesRead = adjustedReader.onRangeAvailable(channel, channelPos, relativePos, len);
938+
assert regionOwners.get(fileRegion.io) == fileRegion
939+
: "File chunk [" + fileRegion.regionKey + "] no longer owns IO [" + fileRegion.io + "]";
940+
return bytesRead;
936941
};
937942
}
938943
return adjustedReader;

0 commit comments

Comments
 (0)