From bf5f4630161b9705b2ee0c0875e55db9a7ccd2cb Mon Sep 17 00:00:00 2001 From: maheshrijal <62394512+maheshrijal@users.noreply.github.com> Date: Tue, 24 Nov 2026 16:18:31 +0000 Subject: [PATCH 1/2] fix: flaky IngestionSmokeTest.test_runIndexTask_andKillData KubernetesClusterDockerTest runs two Brokers. The test waited for one Broker metadata sync event and then checked sys.segments once. The query can go to the other Broker, which may still list the unused segments. Poll sys.segments until it is empty instead. Fixes #20909. --- .../embedded/indexing/IngestionSmokeTest.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexing/IngestionSmokeTest.java b/embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexing/IngestionSmokeTest.java index 132c06c20aa1..8cb1eeb47f8d 100644 --- a/embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexing/IngestionSmokeTest.java +++ b/embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexing/IngestionSmokeTest.java @@ -243,9 +243,13 @@ public void test_runIndexTask_andKillData() ); waitForNextCoordinatorCacheSync(); - waitForNextBrokerCacheSync(); - cluster.callApi().verifySqlQuery("SELECT * FROM sys.segments WHERE datasource='%s'", dataSource, ""); + // sys.segments may be answered by a Broker that has not yet synced with the Coordinator, + // so poll until it is empty instead of waiting for a single Broker sync event. + cluster.callApi().waitForResult( + () -> cluster.runSql("SELECT * FROM sys.segments WHERE datasource='%s'", dataSource), + String::isEmpty + ).withTimeoutMillis(60_000).go(); // Kill all unused segments final String killTaskId = cluster.callApi().onLeaderOverlord( @@ -541,14 +545,6 @@ protected void waitForNextCoordinatorCacheSync() ); } - protected void waitForNextBrokerCacheSync() - { - eventCollector.latchableEmitter().waitForNextEvent( - event -> event.hasMetricName("segment/metadataCache/sync/time") - .hasService("druid/broker") - ); - } - /** * Verifies the total number of used segments in {@link #dataSource}. */ From 3010107e0ab252c3b6e2375ee06cc88da06bd64a Mon Sep 17 00:00:00 2001 From: maheshrijal <62394512+maheshrijal@users.noreply.github.com> Date: Fri, 27 Nov 2026 09:51:46 +0000 Subject: [PATCH 2/2] test: wait for the metadata sync of every Broker Replace the sys.segments polling with a wait for the next segment/metadataCache/sync/time event from each Broker found through node discovery, matched by host, as suggested in review. Skip syncs that started before the wait, since the HTTP emitter can deliver them late. --- .../embedded/indexing/IngestionSmokeTest.java | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexing/IngestionSmokeTest.java b/embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexing/IngestionSmokeTest.java index 8cb1eeb47f8d..327fdd9f043e 100644 --- a/embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexing/IngestionSmokeTest.java +++ b/embedded-tests/src/test/java/org/apache/druid/testing/embedded/indexing/IngestionSmokeTest.java @@ -23,6 +23,8 @@ import org.apache.druid.common.utils.IdUtils; import org.apache.druid.data.input.impl.CsvInputFormat; import org.apache.druid.data.input.impl.TimestampSpec; +import org.apache.druid.discovery.DiscoveryDruidNode; +import org.apache.druid.discovery.NodeRole; import org.apache.druid.indexer.TaskStatusPlus; import org.apache.druid.indexing.common.task.CompactionTask; import org.apache.druid.indexing.common.task.IndexTask; @@ -40,6 +42,7 @@ import org.apache.druid.java.util.common.DateTimes; import org.apache.druid.java.util.common.Intervals; import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.java.util.emitter.service.ServiceMetricEvent; import org.apache.druid.metadata.storage.postgresql.PostgreSQLMetadataStorageModule; import org.apache.druid.query.DruidMetrics; import org.apache.druid.query.http.SqlTaskStatus; @@ -72,6 +75,7 @@ import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -243,13 +247,9 @@ public void test_runIndexTask_andKillData() ); waitForNextCoordinatorCacheSync(); + waitForNextBrokerCacheSync(); - // sys.segments may be answered by a Broker that has not yet synced with the Coordinator, - // so poll until it is empty instead of waiting for a single Broker sync event. - cluster.callApi().waitForResult( - () -> cluster.runSql("SELECT * FROM sys.segments WHERE datasource='%s'", dataSource), - String::isEmpty - ).withTimeoutMillis(60_000).go(); + cluster.callApi().verifySqlQuery("SELECT * FROM sys.segments WHERE datasource='%s'", dataSource, ""); // Kill all unused segments final String killTaskId = cluster.callApi().onLeaderOverlord( @@ -545,6 +545,27 @@ protected void waitForNextCoordinatorCacheSync() ); } + /** + * Waits, for each Broker, for a metadata cache sync that began after this method was called, since a SQL query + * may be served by any of them. Earlier syncs are skipped because the HTTP emitter can deliver their events late. + */ + protected void waitForNextBrokerCacheSync() + { + final DateTime waitStart = DateTimes.nowUtc(); + final Collection brokers = + broker.bindings().nodeDiscovery().getForNodeRole(NodeRole.BROKER).getAllNodes(); + for (final DiscoveryDruidNode brokerNode : brokers) { + ServiceMetricEvent syncEvent; + do { + syncEvent = eventCollector.latchableEmitter().waitForNextEvent( + event -> event.hasMetricName("segment/metadataCache/sync/time") + .hasService("druid/broker") + .hasHost(brokerNode.getDruidNode().getHostAndPortToUse()) + ); + } while (!syncEvent.getCreatedTime().minus(syncEvent.getValue().longValue()).isAfter(waitStart)); + } + } + /** * Verifies the total number of used segments in {@link #dataSource}. */