[SERVER-33477] Update session entry with _id upsert Created: 24/Feb/18  Updated: 29/Oct/23  Resolved: 26/Feb/18

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 3.7.3

Type: Bug Priority: Major - P3
Reporter: Siyuan Zhou Assignee: Siyuan Zhou
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-33215 Stash txn state when finishing an ope... Closed
related to SERVER-33430 Do not update in-memory Session state... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

When migration thread updates the session table while the session has been checked out by a retryable write, only one of them will succeed due to the write conflict on the same _id (session id). Compare-and-swap style update and generating WCE manually seems unnecessary because storage engine should be able to generate those WriteConflictExceptions.

This issue makes more than one write with snapshot isolation throw WCE because the in-memory _lastWrittenSessionRecord will be updated at the commit time of the transaction and is out of sync after the first write. CAS update cannot find the expected (stale) original doc.

When multi-statement transaction is implemented this won't be a problem since we don't support retryable writes for operations during a transaction. But I still think it's an opportunity to improve the code. Another benefit is to use idHack in query planning, which doesn't have the CAS update performance issue in SERVER-31845 and keeps the code clearer.



 Comments   
Comment by Githook User [ 26/Feb/18 ]

Author:

{'email': 'siyuan.zhou@mongodb.com', 'name': 'Siyuan Zhou', 'username': 'visualzhou'}

Message: SERVER-33477 Always use upsert with _id for session update.

Transactions stash the writes so the in-memory state of transaction
table is out of sync during transaction. Two threads (write and chunk
migration) will not update the same session entry due to the WCE
generated by storage engine.
Branch: master
https://github.com/mongodb/mongo/commit/84da063a67fee56e7e088891dc170fd8dee4147e

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