[SERVER-34868] A cursor with the "exhaust" option does not return documents inserted in the same txn Created: 07/May/18  Updated: 29/Oct/23  Resolved: 17/May/18

Status: Closed
Project: Core Server
Component/s: Querying, Replication
Affects Version/s: 3.7.9
Fix Version/s: 3.6.9, 4.0.0-rc0

Type: Bug Priority: Major - P3
Reporter: Robert Guo (Inactive) Assignee: William Schultz (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File exhaust_in_session.js    
Issue Links:
Backports
Related
related to SERVER-35007 Ensure that transactions fail when ru... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v3.6
Steps To Reproduce:

/*
 * Setup cluster.
 */
var r = new ReplSetTest({nodes:2});
r.startSet();r.initiate();
 
var dbName = 'test';
var collName = 'test';
 
const sessionOptions = {causalConsistency: false};
const session = r.getPrimary().startSession(sessionOptions);
const sessionDb = session.getDatabase(dbName);
const sessionColl = sessionDb.getCollection(collName);
 
assert.commandWorked(sessionDb.runCommand({create: collName, writeConcern: {w: "majority"}}));
r.awaitLastOpCommitted();
 
/*
 * Repro
 */
 
session.startTransaction();
 
assert.writeOK(sessionColl.insert({a: 1}));
assert.eq(sessionColl.find().addOption(DBQuery.Option.exhaust).itcount(), 1);
 
session.commitTransaction();
session.endSession();

Sprint: Repl 2018-05-21
Participants:

 Description   

The batch size, number of inserted documents, and whether there are existing documents in the collection do not seem to matter. See repro for more detail.



 Comments   
Comment by Githook User [ 28/Sep/18 ]

Author:

{'name': 'William Schultz', 'email': 'william.schultz@mongodb.com', 'username': 'will62794'}

Message: SERVER-34868 Prohibit legacy queries from running on sessions in shell

(cherry picked from commit b188d762b8920f791906c80570f770dd9fc09731)
Branch: v3.6
https://github.com/mongodb/mongo/commit/241515814f8bd5dbc7ad3a0682dd531a965537cb

Comment by Githook User [ 17/May/18 ]

Author:

{'username': 'will62794', 'name': 'William Schultz', 'email': 'william.schultz@mongodb.com'}

Message: SERVER-34868 Prohibit legacy queries from running on sessions in shell
Branch: master
https://github.com/mongodb/mongo/commit/b188d762b8920f791906c80570f770dd9fc09731

Comment by William Schultz (Inactive) [ 17/May/18 ]

Ok, I will make that the main task for this ticket.

Comment by Spencer Brody (Inactive) [ 16/May/18 ]

I think we should fix it now even if it was a bug with Sessions (or really with causal consistency) previously, because transactions makes it worse. I think we should just error in the shell if we're running against a Session and we try to set the exhaust option.

Comment by William Schultz (Inactive) [ 16/May/18 ]

Yeah, that may be reasonable. But this just doesn't really seem like a transactions bug. There's a more basic issue in that the shell doesn't actually run the find command on the session at all when you add the exhaust option. See this other script: exhaust_in_session.js. If you examine the logs you can see each find command execute. The exhaust cursor one doesn't attach the session information, presumably because it's run as an OP_QUERY message. If this shell behavior is already "broken" for normal sessions, should we bother fixing it specifically for transactions? We could file a ticket to improve the shell behavior in this case I guess.

Comment by Spencer Brody (Inactive) [ 15/May/18 ]

It'd probably be nice to return an error in the shell to the user if they ask for something we don't support, rather than silently changing their behavior to not use a transaction when they are expecting that they are inside a transaction.

Comment by William Schultz (Inactive) [ 15/May/18 ]

Specifying the exhaust option on a find command in the shell forces it execute as an OP_QUERY request, due to this check in mongo/shell/query.js. I believe this would cause the command to get sent to the server without any session information, so it clearly wouldn't execute as part of a transaction. robert.guo I think we can probably close this as "Works As Designed", if my understanding here is correct.

Comment by William Schultz (Inactive) [ 15/May/18 ]

According to the local snapshot reads design, we should explicitly forbid specifying readConcern:snapshot for OP_QUERY requests.

Comment by William Schultz (Inactive) [ 15/May/18 ]

I think this may be an issue with the shell as opposed to an issue with the server. It appears that for some reason, specifying the exhaust option on a find command causes it to execute differently in the shell, as an OP_QUERY request, which is handled via a different code path in the server, and wouldn't cause us to trigger the proper transaction related logic. The comment here seems to indicate that exhaust option for find commands is not supported. Need to investigate more to understand the full context here.

Generated at Thu Feb 08 04:38:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.