[SERVER-34903] Allow killCursors within a transaction Created: 08/May/18  Updated: 29/Oct/23  Resolved: 15/May/18

Status: Closed
Project: Core Server
Component/s: Replication
Affects Version/s: None
Fix Version/s: 4.0.0-rc0

Type: Task Priority: Major - P3
Reporter: Spencer Brody (Inactive) Assignee: Tess Avitabile (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Backwards Compatibility: Fully Compatible
Sprint: Repl 2018-05-21
Participants:

 Description   

Drivers will attach transaction options (lsid, txnNumber, autocommit) whenever they kill a cursor as part of an open transaction.  The server needs to support this, thus killCursors needs to be in the transaction command whitelist.



 Comments   
Comment by Githook User [ 15/May/18 ]

Author:

{'email': 'tess.avitabile@mongodb.com', 'username': 'tessavitabile', 'name': 'Tess Avitabile'}

Message: SERVER-34903 Allow killCursors within a transaction
Branch: master
https://github.com/mongodb/mongo/commit/bae37257c81b34327db93208d31d4963ff6a8cc6

Comment by A. Jesse Jiryu Davis [ 09/May/18 ]

Oh, sorry I went off half-cocked. Shane's got a great point as usual. Given that we don't even require drivers to use the cursor's original lsid for killCursors, we shouldn't now require the original txnNumber.

Comment by Tess Avitabile (Inactive) [ 09/May/18 ]

Yes, that is the case we're discussing. I see, if drivers ignore errors from killCursors, then doing this validation on the server would not send any helpful feedback to drivers and would just potentially leave open cursors on the server unnecessarily.

Comment by Shane Harvey [ 09/May/18 ]

Is this the case we're discussing?

with client.start_session() as s:
  cur = client.test.test.find({}, batch_size=1, session=s)
  next(cur)
  with s.start_transaction():
    txn_cur = client.test.test.find({}, batch_size=1, session=s)
    next(txn_cur)
    txn_cur.close()  # sends killCursors in a transaction, succeeds because txn_cur was opened in this transaction.
    cur.close()      # sends killCursors in a transaction, fails because cur was opened outside this transaction.

This would silently leave open cursors on the server because driver ignores errors from killCursors. Perhaps drivers should not add txnNumber to getMore/killCursors commands that were created outside of a transaction? Jesse, do you think drivers should support this?

with client.start_session() as s:
  cur = client.test.test.find({}, batch_size=1, session=s)
  next(cur)
  with s.start_transaction():
    client.test.test.insert_one({}, session=s)
    next(cur)  # OperationFailure: Cannot run getMore on cursor 50326308902, which was not created in a transaction, in transaction 2

Comment by A. Jesse Jiryu Davis [ 09/May/18 ]

SGTM2. cc shane.harvey

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

Makes sense to me!

FYI jesse

Comment by Tess Avitabile (Inactive) [ 09/May/18 ]

Should we require that a killCursors run in a transaction only kill cursors that were opened in that transaction? I don't think it's important for the server, but it would be easy to do, and it would be a check for drivers, if that is their expected behavior.

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