FrankChen021 commented on code in PR #20319:
URL: https://github.com/apache/druid/pull/20319#discussion_r3981021959


##########
services/src/test/java/org/apache/druid/testing/embedded/EmbeddedClusterApis.java:
##########
@@ -332,6 +332,48 @@ public void waitForAllSegmentsToBeAvailable(String 
dataSource, EmbeddedCoordinat
     );
   }
 
+  /**
+   * Waits for all non-tombstone used segments of the given datasource to be
+   * reported as available in {@code sys.segments} and for the datasource to be
+   * present in the Broker SQL schema, by polling the Broker.
+   * <p>
+   * Unlike {@link #waitForAllSegmentsToBeAvailable}, this method does not 
depend
+   * on schema refresh metrics being emitted by the Broker and verifies the 
state
+   * that SQL queries actually observe.
+   *
+   * @param timeoutMillis maximum time to wait
+   */
+  public void waitForAllSegmentsToBeQueryable(
+      String dataSource,
+      EmbeddedCoordinator coordinator,
+      long timeoutMillis
+  )
+  {
+    final int numSegments = (int) coordinator
+        .bindings()
+        .segmentsMetadataStorage()
+        .retrieveAllUsedSegments(dataSource, Segments.INCLUDING_OVERSHADOWED)
+        .stream()
+        .filter(segment -> !segment.isTombstone())
+        .count();
+
+    waitForResult(
+        () -> runSql(
+            "SELECT COUNT(*) FROM sys.segments WHERE datasource='%s' AND 
is_available = 1",
+            dataSource
+        ),
+        result -> Integer.parseInt(result.trim()) >= numSegments
+    ).withTimeoutMillis(timeoutMillis).go();
+
+    waitForResult(
+        () -> runSql(
+            "SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA 
= 'druid' AND TABLE_NAME = '%s'",
+            dataSource
+        ),
+        result -> "1".equals(result.trim())
+    ).withTimeoutMillis(timeoutMillis).go();

Review Comment:
   Keeping the datasource interpolation and `int` semantics as is: this is 
test-only code, datasource names come from `createTestDatasourceName()`, and 
every other SQL helper in this class formats the datasource the same way. The 
embedded cluster can never hold anywhere near `Integer.MAX_VALUE` segments.
   
   What is worth fixing is that a non-numeric or empty result (which is exactly 
what the compaction flake returned) would have thrown `NumberFormatException` 
inside the waiter and aborted the poll instead of retrying. The matcher now 
treats such results as zero and keeps polling.



-- 
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]

Reply via email to