Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore CacheFileRegion refcounting for writes (elastic#102843)
In elastic#98241 we removed the refcounting around write handler in SharedBytes.IO. But recently we saw wrong bytes being read from the snapshot file under heavy evictions and investigation shows that the bytes belonged to another cached file. Low level logging (hard to reproduce) shows that writes and reads using the same SharedBytes.IO instance but for different cache file region could be interleaved, so that bytes in shared cache could be overwritten and the last read would read (and store in internal index input buffers) bytes from a different file: Thread[elasticsearch[node_t0][stateless_shard][T#4],5,TGRP-IndexCorruptionIT]: 10485760 bytes written using SharedBytes$IO@dc07632 (230716978) for FileCacheKey[shardId=[index-0][0], primaryTerm=1, fileName=stateless_commit_26] Thread[elasticsearch[node_t0][stateless_shard][T#3],5,TGRP-IndexCorruptionIT]: 10485760 bytes written using SharedBytes$IO@dc07632 (230716978) for FileCacheKey[shardId=[index-0][0], primaryTerm=1, fileName=stateless_commit_16] Thread[elasticsearch[node_t0][stateless_shard][T#4],5,TGRP-IndexCorruptionIT]: 375 bytes read using SharedBytes$IO@dc07632 (230716978) for key FileCacheKey[shardId=[index-0][0], primaryTerm=1, fileName=stateless_commit_26] This change fixes resfcounting around the write handler so that the IO instance is decref after bytes are fully written. Relates elastic#98241
- Loading branch information