Skip to content

Add an option to exclusively lock Transactional State#9970

Merged
ReubenBond merged 8 commits intodotnet:mainfrom
scalalang2:transaction-exclusive-lock
Apr 4, 2026
Merged

Add an option to exclusively lock Transactional State#9970
ReubenBond merged 8 commits intodotnet:mainfrom
scalalang2:transaction-exclusive-lock

Conversation

@scalalang2
Copy link
Copy Markdown
Contributor

@scalalang2 scalalang2 commented Mar 23, 2026

Motivation

The detailed motivation is described in #9898.

Changes.

The core idea in this PR is to change how isRead param is propagated when an exclusive lock is requested, in the ReaderWriterLock.cs

  • Find(..., isRead, ...) -> Find(..., isRead && !exclusiveLock, ...)
  • HasConflict(isRead, ...) -> HasConflict(isRead && !exclusiveLock, ...)

All other changes are made to support this behavior.

Example

Users attach UseExclusiveLockAttribute to acquire an exclusive lock.

[UseExclusiveLock]
[Transaction(TransactionOption.CreateOrJoin)]
Task<uint> GetBalance();

Since default value of UseExclusiveLock is false, this this change is backward-compatible, and existing code paths remain unaffected unless the attribute is explicitly attached.

DIsclamer

This change has not been fully tested and should not be merged into the main branch.

Microsoft Reviewers: Open in CodeFlow

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR proposes an opt-in mechanism to acquire exclusive locks for transactional state even during read operations, aiming to reduce lock upgrade conflicts under high contention in Orleans Transactions.

Changes:

  • Introduces [UseExclusiveLock] and propagates a UseExclusiveLock flag through transactional request/TransactionInfo.
  • Adds useExclusiveLock overloads to ITransactionClient.RunTransaction(...) and plumbs the flag through TransactionClient.
  • Updates ReaderWriterLock.EnterLock(...) call sites and adjusts conflict detection to treat reads as exclusive when requested.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Orleans.Transactions/TransactionAttribute.cs Adds [UseExclusiveLock] and request-side propagation into TransactionInfo.
src/Orleans.Transactions/TOC/TransactionCommitter.cs Passes UseExclusiveLock into lock acquisition during commit/write path.
src/Orleans.Transactions/State/TransactionalState.cs Passes UseExclusiveLock into lock acquisition for reads/updates.
src/Orleans.Transactions/State/ReaderWriterLock.cs Adds exclusiveLock parameter and modifies how conflicts are computed.
src/Orleans.Transactions/ITransactionClient.cs Adds RunTransaction(..., useExclusiveLock) overloads.
src/Orleans.Transactions/DistributedTM/TransactionInfo.cs Adds UseExclusiveLock flag to serialized transaction context and copies it on fork.
src/Orleans.Transactions/DistributedTM/TransactionClient.cs Implements new overloads and sets UseExclusiveLock when requested.

@ReubenBond
Copy link
Copy Markdown
Member

ReubenBond commented Mar 31, 2026

The idea sounds good to me. I am not entirely sure of the benefit to using PerformRead+ExclusiveLock vs using PerformUpdate (other than avoiding the state copy + storage write). EDIT: I see you answered that in the issue thread.

@scalalang2 scalalang2 changed the title [Proposal] WIP: Add an option to exclusively lock Transactional State [Proposal] Add an option to exclusively lock Transactional State Apr 3, 2026
@scalalang2 scalalang2 force-pushed the transaction-exclusive-lock branch from bb7cdbb to 9bb5842 Compare April 3, 2026 02:45
@scalalang2
Copy link
Copy Markdown
Contributor Author

scalalang2 commented Apr 3, 2026

I’ve added test code to verify that this proposal works as expected.

@scalalang2
Copy link
Copy Markdown
Contributor Author

@copilot, please review again

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

scalalang2 and others added 2 commits April 4, 2026 06:13
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@ReubenBond ReubenBond added this pull request to the merge queue Apr 4, 2026
@ReubenBond ReubenBond removed this pull request from the merge queue due to a manual request Apr 4, 2026
@ReubenBond ReubenBond changed the title [Proposal] Add an option to exclusively lock Transactional State Add an option to exclusively lock Transactional State Apr 4, 2026
@ReubenBond ReubenBond added this pull request to the merge queue Apr 4, 2026
@ReubenBond ReubenBond linked an issue Apr 4, 2026 that may be closed by this pull request
Merged via the queue into dotnet:main with commit 9d0d111 Apr 4, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Proposal] Add an option to exclusively lock Transactional State

3 participants