-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Trivial - P5
-
None
-
Affects Version/s: None
-
Component/s: Querying
-
Query Execution
-
Minor Change
The behavior of mongos when resuming a change stream cursor changed in one of the later release candidates. Previously the first batch would contain the change stream document following the resumeAfter token. Now the first batch is empty, and the change stream document doesn't appear until the first getMore.
While this doesn't violate the specification of cursors (which allow empty batches), it's not clear that the change was intentional, and it does delay the delivery of the first change stream document to the application.
Here's the commands and responses sent to the server, demonstrating the issue. Note that the firstBatch in the response to the second aggregate command is empty.
{ "create" : "com.mongodb.operation.ChangeStreamOperationSpecification", "autoIndexId" : true, "capped" : false, "$db" : "JavaDriverTest", "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1512070041, "i" : 1 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } } { "note" : "the autoIndexId option is deprecated and will be removed in a future release", "ok" : 1.0, "operationTime" : { "$timestamp" : { "t" : 1512070050, "i" : 1 } }, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1512070050, "i" : 1 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } } { "aggregate" : "com.mongodb.operation.ChangeStreamOperationSpecification", "pipeline" : [{ "$changeStream" : { "fullDocument" : "default" } }, { "$match" : { "operationType" : "insert" } }], "cursor" : { }, "$db" : "JavaDriverTest", "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1512070050, "i" : 1 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } } { "cursor" : { "firstBatch" : [], "id" : { "$numberLong" : "7909579924173326890" }, "ns" : "JavaDriverTest.com.mongodb.operation.ChangeStreamOperationSpecification" }, "ok" : 1.0, "operationTime" : { "$timestamp" : { "t" : 1512070050, "i" : 1 } }, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1512070050, "i" : 1 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } } { "insert" : "com.mongodb.operation.ChangeStreamOperationSpecification", "ordered" : true, "writeConcern" : { "w" : "majority" }, "$db" : "JavaDriverTest", "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1512070050, "i" : 1 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } }, "documents" : [{ "_id" : 1, "a" : 1 }, { "_id" : 2, "a" : 2 }] } { "n" : 2, "opTime" : { "ts" : { "$timestamp" : { "t" : 1512070050, "i" : 3 } }, "t" : { "$numberLong" : "1" } }, "electionId" : { "$oid" : "7fffffff0000000000000001" }, "ok" : 1.0, "operationTime" : { "$timestamp" : { "t" : 1512070050, "i" : 3 } }, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1512070050, "i" : 3 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } } { "getMore" : { "$numberLong" : "7909579924173326890" }, "collection" : "com.mongodb.operation.ChangeStreamOperationSpecification", "$db" : "JavaDriverTest", "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1512070050, "i" : 3 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } } { "cursor" : { "nextBatch" : [{ "_id" : { "_data" : { "$binary" : "glogW6IAAAACRh5faWQAKwIAWhAE+t3/4MP1Sa2c7SEciCREogQ=", "$type" : "00" } }, "operationType" : "insert", "fullDocument" : { "_id" : 1, "a" : 1 }, "ns" : { "db" : "JavaDriverTest", "coll" : "com.mongodb.operation.ChangeStreamOperationSpecification" }, "documentKey" : { "_id" : 1 } }, { "_id" : { "_data" : { "$binary" : "glogW6IAAAADRh5faWQAKwQAWhAE+t3/4MP1Sa2c7SEciCREogQ=", "$type" : "00" } }, "operationType" : "insert", "fullDocument" : { "_id" : 2, "a" : 2 }, "ns" : { "db" : "JavaDriverTest", "coll" : "com.mongodb.operation.ChangeStreamOperationSpecification" }, "documentKey" : { "_id" : 2 } }], "id" : { "$numberLong" : "7909579924173326890" }, "ns" : "JavaDriverTest.com.mongodb.operation.ChangeStreamOperationSpecification" }, "ok" : 1.0, "operationTime" : { "$timestamp" : { "t" : 1512070050, "i" : 3 } }, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1512070050, "i" : 3 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } } { "killCursors" : "com.mongodb.operation.ChangeStreamOperationSpecification", "cursors" : [{ "$numberLong" : "7909579924173326890" }], "$db" : "JavaDriverTest", "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1512070050, "i" : 3 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } } { "cursorsKilled" : [{ "$numberLong" : "7909579924173326890" }], "cursorsNotFound" : [], "cursorsAlive" : [], "cursorsUnknown" : [], "ok" : 1.0, "operationTime" : { "$timestamp" : { "t" : 1512070050, "i" : 3 } }, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1512070050, "i" : 3 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } } { "aggregate" : "com.mongodb.operation.ChangeStreamOperationSpecification", "pipeline" : [{ "$changeStream" : { "fullDocument" : "default", "resumeAfter" : { "_data" : { "$binary" : "glogW6IAAAACRh5faWQAKwIAWhAE+t3/4MP1Sa2c7SEciCREogQ=", "$type" : "00" } } } }, { "$match" : { "operationType" : "insert" } }], "cursor" : { }, "$db" : "JavaDriverTest", "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1512070050, "i" : 3 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } } { "cursor" : { "firstBatch" : [], "id" : { "$numberLong" : "5745533492884672932" }, "ns" : "JavaDriverTest.com.mongodb.operation.ChangeStreamOperationSpecification" }, "ok" : 1.0, "operationTime" : { "$timestamp" : { "t" : 1512070050, "i" : 3 } }, "$clusterTime" : { "clusterTime" : { "$timestamp" : { "t" : 1512070050, "i" : 3 } }, "signature" : { "hash" : { "$binary" : "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "$type" : "00" }, "keyId" : { "$numberLong" : "0" } } } }