924060929 commented on code in PR #70708:
URL: https://github.com/apache/doris/pull/70708#discussion_r4690974771
##########
fe/fe-connector/fe-connector-mongodb/src/main/java/org/apache/doris/connector/mongodb/MongoDriverCatalogClient.java:
##########
@@ -158,33 +172,206 @@ public BsonTimestamp selectSnapshot(String database,
String collection, String p
// with limit=1/batchSize=1, to discover T without transferring a
potentially large source row.
// The driver may request an extra wire batch slot to exhaust a
limit-one cursor.
try (ClientSession session =
client.startSession(ClientSessionOptions.builder()
- .causallyConsistent(false).snapshot(true).build());
- MongoCursor<Document> cursor = snapshotDatabase(database,
deadline).getCollection(collection)
-
.withReadPreference(properties.readPreferenceForSnapshot(preference)).find(session)
- .projection(new Document("_id", 0)
- .append("__doris_snapshot_probe__", new
Document("$literal", 1)))
- .limit(1).batchSize(1).iterator()) {
- cursor.hasNext();
- // This is cursor.atClusterTime captured by the driver's
snapshot-session protocol;
- // operationTime, $clusterTime and the local wall clock are not
substitutes for T.
- BsonTimestamp timestamp = session.getSnapshotTimestamp();
- if (timestamp == null) {
- throw new DorisConnectorException("MongoDB snapshot probe did
not return a snapshot timestamp");
+ .causallyConsistent(false).snapshot(true).build())) {
+ // Each blocking step must observe scan cancellation before
starting the next one;
+ // an in-flight synchronous driver call still uses the original
CSOT deadline.
+ try (MongoCursor<Document> cursor = snapshotDatabase(database,
deadline, checkCancelled)
+
.getCollection(collection).withReadPreference(properties.readPreferenceForSnapshot(preference))
+ .find(session).projection(new Document("_id", 0)
+ .append("__doris_snapshot_probe__", new
Document("$literal", 1)))
+ .limit(1).batchSize(1).iterator()) {
+ checkSnapshot(deadline, checkCancelled);
+ cursor.hasNext();
+ checkSnapshot(deadline, checkCancelled);
+ // This is cursor.atClusterTime captured by the driver's
snapshot-session protocol;
+ // operationTime, $clusterTime and the local wall clock are
not substitutes for T.
+ BsonTimestamp timestamp = session.getSnapshotTimestamp();
+ if (timestamp == null) {
+ throw new DorisConnectorException("MongoDB snapshot probe
did not return a snapshot timestamp");
+ }
+ return timestamp;
}
- return timestamp;
} catch (MongoException failure) {
throw failure(failure);
}
}
- private MongoDatabase snapshotDatabase(String database, long deadline) {
- long remaining = deadline - System.nanoTime();
- if (remaining <= 0) {
+ @Override
+ public MongoSplitProbe probeSplits(MongoTableHandle table, String field,
String preference,
+ TMongoSnapshot snapshot, int rows, long timeoutMs,
+ LongPredicate shouldSample, LongConsumer accountBytes, Runnable
checkCancelled) {
+ long deadline = System.nanoTime() +
TimeUnit.MILLISECONDS.toNanos(timeoutMs);
+ String index = null;
+ long bytes = 0;
+ try {
+ var collection = probeDatabase(table.getDatabase(), deadline,
checkCancelled)
+ .getCollection(table.getName());
+ // Fetch the bounded index inventory together: one RTT per index
can exhaust the
+ // optional probe deadline before a later qualifying ordinary
index is reached.
+ try (MongoCursor<Document> indexes =
collection.listIndexes().batchSize(128)
+ .timeoutMode(TimeoutMode.CURSOR_LIFETIME).iterator()) {
+ int count = 0;
+ while (true) {
+ // hasNext may issue getMore. Cancellation must be checked
before that request,
+ // not only after it returns; the lifetime timeout also
covers all cursor batches.
+ checkProbe(deadline, checkCancelled);
Review Comment:
**[P2] Charge the buffered `listIndexes` batch before checking the probe
deadline.** `iterator()` can already have received the first batch when
execution reaches this line. On MongoDB 8.0.20 I paused the Java driver's
`commandSucceeded` callback for 2.15 seconds after a successful `listIndexes`
reply. With the default 2-second probe deadline, the reply contained 75,135
bytes of index specifications, but `checkProbe` threw here before
`accountBytes` ran. The statement was charged **0 bytes**, so later scans can
keep spending the 16 MiB probe budget after those bytes have been received.
Could we account for the locally buffered batch before taking the timeout
fallback, while keeping the cancellation/deadline check before any `getMore`? A
regression can expire the deadline immediately after the first reply and assert
that its bytes are charged and no further command is issued.
--
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]