github-advanced-security[bot] commented on code in PR #20073:
URL: https://github.com/apache/druid/pull/20073#discussion_r3810167815
##########
server/src/test/java/org/apache/druid/segment/loading/SegmentLocalCacheManagerPartialAcquireTest.java:
##########
@@ -915,6 +916,107 @@
);
}
+ @Test
+ void
testAcquireMountsALingeringNeverMountedEntryRatherThanRegisteringAnotherOne()
+ throws ExecutionException, InterruptedException, IOException
+ {
+ final StorageLocation location = manager.getLocations().get(0);
+ final SegmentCacheEntryIdentifier id = new
SegmentCacheEntryIdentifier(SEGMENT_ID);
+
+ // Two acquires holding the same freshly reserved entry, neither of which
resolves its future, so nothing mounts
+ // it. The acquire that created the entry gives up first, so the entry
outlives the hold that would have removed
+ // it, and once the second lets go too it is left registered, unmounted
and unheld.
+ final AcquireSegmentAction creator =
manager.acquireSegment(partialSegment, AcquireMode.PARTIAL);
+ final AcquireSegmentAction other = manager.acquireSegment(partialSegment,
AcquireMode.PARTIAL);
+ final PartialSegmentMetadataCacheEntry lingering =
+ Assertions.assertInstanceOf(PartialSegmentMetadataCacheEntry.class,
location.getCacheEntry(id));
+ Assertions.assertFalse(lingering.isMounted());
+
+ creator.close();
+ Assertions.assertSame(lingering, location.getCacheEntry(id), "an entry
another acquire holds must survive");
+ other.close();
+ Assertions.assertSame(lingering, location.getCacheEntry(id));
+ Assertions.assertFalse(lingering.isMounted());
+
+ // A later acquire mounts that same entry and serves the segment from it,
rather than registering a second entry
+ // for this id (two entries would fight over the on-disk state they share).
+ try (AcquireSegmentAction action = manager.acquireSegment(partialSegment,
AcquireMode.PARTIAL)) {
+ final AcquireSegmentResult result = action.getSegmentFuture().get();
+ try (Segment segment =
result.getReferenceProvider().acquireReference().orElseThrow()) {
+ Assertions.assertEquals(SEGMENT_ID, segment.getId());
+ final TimeBoundaryInspector inspector =
segment.as(TimeBoundaryInspector.class);
+ Assertions.assertNotNull(inspector);
+ Assertions.assertEquals(TIME, inspector.getMinTime());
+ Assertions.assertEquals(TIME.plusMinutes(3), inspector.getMaxTime());
+ }
+ Assertions.assertSame(lingering, location.getCacheEntry(id));
+ Assertions.assertTrue(lingering.isMounted());
+ }
+ }
+
+ @Test
+ void testAbandonedAcquireResolvesToAnUnavailableSegmentRatherThanFailing()
throws Exception
+ {
+ // One fixed loading thread, so the test can hold the load task at a gate
while it abandons the acquire.
+ final File gatedCacheRoot = new File(perTestTempDir, "gated_cache");
+ FileUtils.mkdirp(gatedCacheRoot);
+ final SegmentLoaderConfig gatedConfig = SegmentLoaderConfig.builder()
+ .locations(new StorageLocationConfig(gatedCacheRoot, 1024L * 1024L *
1024L, null))
+ .virtualStorage(true)
+ .virtualStoragePartialDownloadsEnabled(true)
+ .virtualStorageUseVirtualThreads(false)
+ .virtualStorageLoadThreads(1)
+ .build();
+ final List<StorageLocation> storageLocations =
gatedConfig.toStorageLocations();
+ final StorageLoadingThreadPool gatedPool =
StorageLoadingThreadPool.createFromConfig(gatedConfig);
+ final SegmentLocalCacheManager gatedManager = new SegmentLocalCacheManager(
+ storageLocations,
+ gatedConfig,
+ gatedPool,
+ new LeastBytesUsedStorageLocationSelectorStrategy(storageLocations),
+ TestHelper.getTestIndexIO(jsonMapper, ColumnConfig.DEFAULT),
+ jsonMapper
+ );
+
+ final CountDownLatch atGate = new CountDownLatch(1);
+ final CountDownLatch openGate = new CountDownLatch(1);
+ try {
+ @SuppressWarnings("unused")
+ ListenableFuture<?> unused = gatedPool.getExecutorService().submit(() ->
{
+ atGate.countDown();
+ return openGate.await(30, TimeUnit.SECONDS);
+ });
Review Comment:
## CodeQL / Unread local variable
Variable 'ListenableFuture<?> unused' is never read.
[Show more
details](https://github.com/apache/druid/security/code-scanning/11881)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]