[SERVER-85918] Better APIs for locking mode within/outside transactions Created: 30/Jan/24  Updated: 01/Feb/24

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Pierlauro Sciarelli Assignee: Backlog - Catalog and Routing
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Catalog and Routing
Participants:
Story Points: 1

 Description   

There is a recurring pattern across the codebase when having to choose the lock mode for acquisitions happening outside/within a transaction: we often manually check if the operation context is flagged as inMultiDocumentTransaction in order to use either intent shared mode or exclusive.

Purpose of this ticket is to investigate whether there is a better way to do so without having to continuously manually check, for example automatically "promote" intent shared mode to exclusive based on the operation context flags.

Some examples of manual checks spottable through a simple grep:

$ git grep '? MODE_IX : MODE_IS' src/
src/mongo/db/s/ddl_lock_manager.cpp:    const auto lockMode = opCtx->inMultiDocumentTransaction() ? MODE_IX : MODE_IS;
src/mongo/db/s/ddl_lock_manager.cpp:        const auto lockMode = opCtx->inMultiDocumentTransaction() ? MODE_IX : MODE_IS;
src/mongo/db/shard_role.cpp:        const auto lockMode = opCtx->inMultiDocumentTransaction() ? MODE_IX : MODE_IS;
src/mongo/db/transaction/transaction_participant.cpp:    Lock::GlobalLock lk(opCtx, opCtx->inMultiDocumentTransaction() ? MODE_IX : MODE_IS);


Generated at Thu Feb 08 06:58:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.