FrankChen021 commented on code in PR #20319:
URL: https://github.com/apache/druid/pull/20319#discussion_r3989093013
##########
services/src/test/java/org/apache/druid/testing/embedded/EmbeddedClusterApis.java:
##########
@@ -332,6 +332,62 @@ 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",
Review Comment:
[P2] Escape datasource before embedding it in SQL
`dataSource` is interpolated directly inside a single-quoted SQL literal
here (and again in the TABLES query below). Druid's datasource ID validation
permits apostrophes, so a valid datasource such as `a'b` produces malformed or
changed SQL and this waiter will time out or poll the wrong rows. Escape single
quotes (`'` to `''`) or use a parameterized query before passing the value to
`runSql`; the current random-name call path happens to be safe, but the new
public helper is not.
--
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]