Gabriel39 commented on code in PR #70708:
URL: https://github.com/apache/doris/pull/70708#discussion_r4691148470


##########
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:
   Fixed in d69f2d4489 after completing local self-review before the commit.
   
   The loop now checks whether index documents are already buffered. That batch 
is consumed and charged before optional deadline fallback. When no buffered 
data is available, cancellation/deadline is still checked before hasNext() can 
issue getMore. Per-document cancellation and try-with-resources cleanup remain 
intact.
   
   The new baseline regression fails with expected 75141 charged bytes versus 
0. Five added tests cover the delayed first reply, expiry before an unbuffered 
getMore, delayed getMore accounting, and cancellation with either empty or 
populated buffers. They assert exact byte totals, no later statistics/sample 
command, getMore counts and one cursor close. All 192 MongoDB connector tests, 
166 connector SPI tests and full FE Checkstyle pass. The full two-file diff and 
related driver/caller paths were locally self-reviewed with no unresolved issue.
   
   The source changes are pushed and standard build and review requests are 
posted. Fresh remote CI is pending; no new live MongoDB qualification is 
claimed by these recording-driver tests.
   



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