GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(transactions): isolate failed storage writes (#10375) · dotnet/orleans@a30ffe6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/Orleans.Transactions/State
    • TransactionalStateStorageProviderWrapper.cs
  • test/Transactions/Orleans.Transactions.Tests
    • TransactionalStateStorageProviderWrapperTests.cs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/Orleans.Transactions/State/TransactionalStateStorageProviderWrapper.cs‎

Copy file name to clipboardExpand all lines: src/Orleans.Transactions/State/TransactionalStateStorageProviderWrapper.cs
+26-4Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ public async Task<string> Store(string? expectedETag, TransactionalStateMetaData
3838
{
3939
if (this.StateStorage.Etag != expectedETag)
4040
throw new ArgumentException(nameof(expectedETag), "Etag does not match");
41-
var state = stateStorage!.State!; // StateStorage access above initializes the field and ReadStateAsync has populated its state.
42-
state.Metadata = metadata;
41+
var storedState = stateStorage!.State!; // StateStorage access above initializes the field and ReadStateAsync has populated its state.
42+
var storedETag = stateStorage.Etag;
43+
var state = new TransactionalStateRecord<TState>
44+
{
45+
CommittedState = storedState.CommittedState,
46+
CommittedSequenceId = storedState.CommittedSequenceId,
47+
Metadata = metadata,
48+
PendingStates = new List<PendingTransactionState<TState>>(storedState.PendingStates),
49+
};
4350

4451
var pendinglist = state.PendingStates;
4552

@@ -91,8 +98,23 @@ public async Task<string> Store(string? expectedETag, TransactionalStateMetaData
9198
}
9299
}
93100

94-
await stateStorage.WriteStateAsync();
95-
return stateStorage.Etag ?? throw new InvalidOperationException("The grain storage provider did not supply an ETag after writing transactional state.");
101+
stateStorage.State = state;
102+
var writeSucceeded = false;
103+
try
104+
{
105+
await stateStorage.WriteStateAsync();
106+
var result = stateStorage.Etag ?? throw new InvalidOperationException("The grain storage provider did not supply an ETag after writing transactional state.");
107+
writeSucceeded = true;
108+
return result;
109+
}
110+
finally
111+
{
112+
if (!writeSucceeded)
113+
{
114+
stateStorage.State = storedState;
115+
stateStorage.Etag = storedETag;
116+
}
117+
}
96118
}
97119

98120
private StateStorageBridge<TransactionalStateRecord<TState>> GetStateStorage()

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.