Skip to content

Commit

Permalink
Cosmos DB: perform read for consistency when deleting state which is …
Browse files Browse the repository at this point in the history
…expected to not exist (#8700)

* Cosmos DB: perform read for consistency when deleting state which is expected to not exist

* Update src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs
  • Loading branch information
ReubenBond authored Nov 3, 2023
1 parent 2a0996c commit 938dde3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Azure/Orleans.Persistence.Cosmos/CosmosGrainStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,17 @@ public async Task ClearStateAsync<T>(string grainType, GrainId grainId, IGrainSt
if (_options.DeleteStateOnClear)
{
if (string.IsNullOrWhiteSpace(grainState.ETag))
return; //state not written
{
await ReadStateAsync<T>(grainType, grainId, grainState);
if (grainState.RecordExists)
{
// State exists but the current activation has not observed state creation. Therefore, we have inconsistent state and should throw to give the grain a chance to deactivate and recover.
throw new CosmosConditionNotSatisfiedException(grainType, grainId, _options.ContainerName, grainState.ETag, "None");
}

// State does not exist.
return;
}

await _executor.ExecuteOperation(static args =>
{
Expand Down

0 comments on commit 938dde3

Please sign in to comment.