From 97e97348037b590485da7b9c0676483f1544f782 Mon Sep 17 00:00:00 2001 From: Abhishek Balaji Radhakrishnan Date: Fri, 14 Jun 2024 19:55:33 -0700 Subject: [PATCH] Add test for failure scenario and cleanup logs. --- .../coordination/SegmentLoadDropHandler.java | 11 +++---- .../druid/server/http/MetadataResource.java | 6 ---- .../SegmentLoadDropHandlerTest.java | 31 ++++++++++++++++--- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java b/server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java index 447cfe61bfe8..d78a52319122 100644 --- a/server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java +++ b/server/src/main/java/org/apache/druid/server/coordination/SegmentLoadDropHandler.java @@ -232,8 +232,6 @@ private void loadSegmentsOnStartup() throws IOException startupSegments.addAll(segmentManager.getCachedSegments()); startupSegments.addAll(getBootstrapSegments()); - log.info("Server type[%s]", serverTypeConfig.getServerType()); - final Stopwatch stopwatch = Stopwatch.createStarted(); // Start a temporary thread pool to load cachedSegments into page cache during bootstrap @@ -318,17 +316,18 @@ private void loadSegmentsOnStartup() throws IOException } } + /** + * @return a list of bootstrap segments. When bootstrap segments cannot be found, an empty list is returned. + */ private List getBootstrapSegments() { log.info("Fetching bootstrap segments from the coordinator."); final Stopwatch stopwatch = Stopwatch.createStarted(); - final ListenableFuture> bootstrapSegmentsFuture = - coordinatorClient.fetchBootstrapSegments(); - List bootstrapSegments = new ArrayList<>(); - try (CloseableIterator iterator = FutureUtils.getUnchecked(bootstrapSegmentsFuture, true)) { + try (final CloseableIterator iterator = + FutureUtils.getUnchecked(coordinatorClient.fetchBootstrapSegments(), true)) { bootstrapSegments = ImmutableList.copyOf(iterator); } catch (Exception e) { diff --git a/server/src/main/java/org/apache/druid/server/http/MetadataResource.java b/server/src/main/java/org/apache/druid/server/http/MetadataResource.java index 164896a1afb0..5f4c5432e46f 100644 --- a/server/src/main/java/org/apache/druid/server/http/MetadataResource.java +++ b/server/src/main/java/org/apache/druid/server/http/MetadataResource.java @@ -484,13 +484,7 @@ public Response getDataSourceInformation( public Response getBootstrapSegments() { try { - log.info("Hmm call to bootstrap segments.."); Set broadcastSegments = coordinator.getBroadcastSegments(); - log.info( - "Number of bootstrap segments coordinator is returning [%d] and they are [%s]", - broadcastSegments.size(), - broadcastSegments - ); return Response.status(Response.Status.OK).entity(broadcastSegments).build(); } catch (DruidException e) { diff --git a/server/src/test/java/org/apache/druid/server/coordination/SegmentLoadDropHandlerTest.java b/server/src/test/java/org/apache/druid/server/coordination/SegmentLoadDropHandlerTest.java index 41bdb4c79a1e..a935b2bff64e 100644 --- a/server/src/test/java/org/apache/druid/server/coordination/SegmentLoadDropHandlerTest.java +++ b/server/src/test/java/org/apache/druid/server/coordination/SegmentLoadDropHandlerTest.java @@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.util.concurrent.ListenableFuture; import org.apache.druid.client.coordinator.CoordinatorClient; +import org.apache.druid.client.coordinator.NoopCoordinatorClient; import org.apache.druid.guice.ServerTypeConfig; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.MapUtils; @@ -302,7 +303,7 @@ public void testLoadCache() throws Exception @Test public void testLoadBootstrapSegments() throws Exception { - Set segments = new HashSet<>(); + final Set segments = new HashSet<>(); for (int i = 0; i < COUNT; ++i) { segments.add(makeSegment("test" + i, "1", Intervals.of("P1d/2011-04-01"))); segments.add(makeSegment("test" + i, "1", Intervals.of("P1d/2011-04-02"))); @@ -334,9 +335,31 @@ public void testLoadBootstrapSegments() throws Exception Assert.assertEquals(expectedBootstrapSegments, cacheManager.observedBootstrapSegments); Assert.assertEquals(expectedBootstrapSegments, cacheManager.observedBootstrapSegmentsLoadedIntoPageCache); - Assert.assertEquals(ImmutableList.of(), cacheManager.observedSegments); - Assert.assertEquals(ImmutableList.of(), cacheManager.observedSegmentsLoadedIntoPageCache); + handler.stop(); + + Assert.assertEquals(0, serverAnnouncer.getObservedCount()); + Assert.assertEquals(1, cacheManager.observedShutdownBootstrapCount.get()); + } + + @Test + public void testLoadBootstrapSegmentsWhenExceptionThrown() throws Exception + { + final TestSegmentCacheManager cacheManager = new TestSegmentCacheManager(); + final SegmentManager segmentManager = new SegmentManager(cacheManager); + + final SegmentLoadDropHandler handler = initSegmentLoadDropHandler(segmentManager, new NoopCoordinatorClient()); + + Assert.assertTrue(segmentManager.getDataSourceCounts().isEmpty()); + + handler.start(); + + Assert.assertEquals(1, serverAnnouncer.getObservedCount()); + Assert.assertTrue(segmentManager.getDataSourceCounts().isEmpty()); + + Assert.assertEquals(ImmutableList.of(), segmentAnnouncer.getObservedSegments()); + Assert.assertEquals(ImmutableList.of(), cacheManager.observedBootstrapSegments); + Assert.assertEquals(ImmutableList.of(), cacheManager.observedBootstrapSegmentsLoadedIntoPageCache); handler.stop(); @@ -595,7 +618,7 @@ public int getDropSegmentDelayMillis() Assert.assertEquals(0, serverAnnouncer.getObservedCount()); } - private SegmentLoadDropHandler initSegmentLoadDropHandler(SegmentManager segmentManager, TestCoordinatorClient coordinatorClient) + private SegmentLoadDropHandler initSegmentLoadDropHandler(SegmentManager segmentManager, CoordinatorClient coordinatorClient) { return initSegmentLoadDropHandler(segmentLoaderConfig, segmentManager, coordinatorClient); }