From 2fd8481a3397e3e850278a9a7c9728fa20eb062c Mon Sep 17 00:00:00 2001 From: Yang Wang Date: Thu, 29 Aug 2024 11:54:41 +1000 Subject: [PATCH 1/2] [Test] Fix SharedBlobCacheServiceTests.testGetMultiThreaded A cacheFileRegion can be concurrently evicted while its being incref'd. See this comment https://github.com/elastic/elasticsearch/blob/98fe686da4c5cb82d4b03719977be428dc7934e7/x-pack/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/shared/SharedBlobCacheService.java#L1812-L1813 The tryRead method also performs null and eviction check for io before returing true. https://github.com/elastic/elasticsearch/blob/98fe686da4c5cb82d4b03719977be428dc7934e7/x-pack/plugin/blob-cache/src/main/java/org/elasticsearch/blobcache/shared/SharedBlobCacheService.java#L926-L931 Resolves: #112314 --- muted-tests.yml | 3 --- .../blobcache/shared/SharedBlobCacheServiceTests.java | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/muted-tests.yml b/muted-tests.yml index 7feefa1255f48..231b3e044379a 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -169,9 +169,6 @@ tests: - class: org.elasticsearch.search.retriever.rankdoc.RankDocsSortBuilderTests method: testEqualsAndHashcode issue: https://github.com/elastic/elasticsearch/issues/112312 -- class: org.elasticsearch.blobcache.shared.SharedBlobCacheServiceTests - method: testGetMultiThreaded - issue: https://github.com/elastic/elasticsearch/issues/112314 # Examples: # diff --git a/x-pack/plugin/blob-cache/src/test/java/org/elasticsearch/blobcache/shared/SharedBlobCacheServiceTests.java b/x-pack/plugin/blob-cache/src/test/java/org/elasticsearch/blobcache/shared/SharedBlobCacheServiceTests.java index 0f3804baef42b..5bbd819b81ab2 100644 --- a/x-pack/plugin/blob-cache/src/test/java/org/elasticsearch/blobcache/shared/SharedBlobCacheServiceTests.java +++ b/x-pack/plugin/blob-cache/src/test/java/org/elasticsearch/blobcache/shared/SharedBlobCacheServiceTests.java @@ -444,7 +444,6 @@ public void testMassiveDecay() throws IOException { * Exercise SharedBlobCacheService#get in multiple threads to trigger any assertion errors. * @throws IOException */ - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/112305") public void testGetMultiThreaded() throws IOException { final int threads = between(2, 10); final int regionCount = between(1, 20); @@ -498,7 +497,7 @@ public void testGetMultiThreaded() throws IOException { if (yield[i] == 0) { Thread.yield(); } - assertNotNull(cacheFileRegion.testOnlyNonVolatileIO()); + assertTrue(cacheFileRegion.testOnlyNonVolatileIO() != null || cacheFileRegion.isEvicted()); cacheFileRegion.decRef(); } if (evict[i] == 0) { From 7f50458a60ee5e48028bdb6d4bfd331ee708803a Mon Sep 17 00:00:00 2001 From: Yang Wang Date: Fri, 30 Aug 2024 11:08:57 +1000 Subject: [PATCH 2/2] move assertion --- .../blobcache/shared/SharedBlobCacheServiceTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/blob-cache/src/test/java/org/elasticsearch/blobcache/shared/SharedBlobCacheServiceTests.java b/x-pack/plugin/blob-cache/src/test/java/org/elasticsearch/blobcache/shared/SharedBlobCacheServiceTests.java index 5bbd819b81ab2..afcf8a3a55959 100644 --- a/x-pack/plugin/blob-cache/src/test/java/org/elasticsearch/blobcache/shared/SharedBlobCacheServiceTests.java +++ b/x-pack/plugin/blob-cache/src/test/java/org/elasticsearch/blobcache/shared/SharedBlobCacheServiceTests.java @@ -493,11 +493,11 @@ public void testGetMultiThreaded() throws IOException { assert allowAlreadyClosed || e.getMessage().equals("evicted during free region allocation") : e; throw e; } + assertTrue(cacheFileRegion.testOnlyNonVolatileIO() != null || cacheFileRegion.isEvicted()); if (incRef && cacheFileRegion.tryIncRef()) { if (yield[i] == 0) { Thread.yield(); } - assertTrue(cacheFileRegion.testOnlyNonVolatileIO() != null || cacheFileRegion.isEvicted()); cacheFileRegion.decRef(); } if (evict[i] == 0) {