Skip to content

Commit

Permalink
Fix blob cache testGetMultiThreaded
Browse files Browse the repository at this point in the history
The verification that we always find a free region could fail due to racing
against incRef'ers (which is not locked).

Closes elastic#104997
  • Loading branch information
henningandersen committed Feb 1, 2024
1 parent 4c44633 commit 0f4d623
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,15 @@ public void testMassiveDecay() throws IOException {
* @throws IOException
*/
public void testGetMultiThreaded() throws IOException {
int threads = between(2, 10);
int regionCount = between(1, 20);
final int threads = between(2, 10);
final int regionCount = between(1, 20);
final boolean incRef = randomBoolean();
// if we have enough regions, a get should always have a result (except for explicit evict interference)
final boolean allowAlreadyClosed = regionCount < threads;
// if we incRef, we risk the eviction racing against that, leading to no available region, so allow
// the already closed exception in that case.
final boolean allowAlreadyClosed = regionCount < threads || incRef;

logger.info("{} {} {}", threads, regionCount, allowAlreadyClosed);
Settings settings = Settings.builder()
.put(NODE_NAME_SETTING.getKey(), "node")
.put(SharedBlobCacheService.SHARED_CACHE_SIZE_SETTING.getKey(), ByteSizeValue.ofBytes(size(regionCount * 100L)).getStringRep())
Expand Down Expand Up @@ -466,7 +471,7 @@ public void testGetMultiThreaded() throws IOException {
assert allowAlreadyClosed || e.getMessage().equals("evicted during free region allocation") : e;
throw e;
}
if (cacheFileRegion.tryIncRef()) {
if (incRef && cacheFileRegion.tryIncRef()) {
if (yield[i] == 0) {
Thread.yield();
}
Expand Down

0 comments on commit 0f4d623

Please sign in to comment.