Add an option to exclusively lock Transactional State#9970
Merged
ReubenBond merged 8 commits intodotnet:mainfrom Apr 4, 2026
Merged
Add an option to exclusively lock Transactional State#9970ReubenBond merged 8 commits intodotnet:mainfrom
ReubenBond merged 8 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
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 aUseExclusiveLockflag through transactional request/TransactionInfo. - Adds
useExclusiveLockoverloads toITransactionClient.RunTransaction(...)and plumbs the flag throughTransactionClient. - 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. |
Member
|
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. |
bb7cdbb to
9bb5842
Compare
Contributor
Author
|
I’ve added test code to verify that this proposal works as expected. |
Contributor
Author
|
@copilot, please review again |
src/Orleans.Transactions.TestKit.Base/TestRunners/ExclusiveLockTransactionTestRunner.cs
Outdated
Show resolved
Hide resolved
src/Orleans.Transactions.TestKit.xUnit/ExclusiveLockTransactionTestRunner.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The detailed motivation is described in #9898.
Changes.
The core idea in this PR is to change how
isReadparam is propagated when an exclusive lock is requested, in theReaderWriterLock.csFind(..., isRead, ...)->Find(..., isRead && !exclusiveLock, ...)HasConflict(isRead, ...)->HasConflict(isRead && !exclusiveLock, ...)All other changes are made to support this behavior.
Example
Users attach
UseExclusiveLockAttributeto acquire an exclusive lock.Since default value of
UseExclusiveLockis 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