Skip to content

Commit ded662b

Browse files
committed
Fix delete before write for ADO.NET providers
1 parent f080b00 commit ded662b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/AdoNet/Orleans.Persistence.AdoNet/Storage/Provider/AdoNetGrainStorage.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,15 @@ public async Task ClearStateAsync<T>(string grainType, GrainId grainReference, I
165165
grainState.ETag);
166166
}
167167

168+
if (!grainState.RecordExists)
169+
{
170+
await ReadStateAsync(grainType, grainReference, grainState).ConfigureAwait(false);
171+
if (!grainState.RecordExists)
172+
{
173+
return;
174+
}
175+
}
176+
168177
string storageVersion = null;
169178
try
170179
{
@@ -198,13 +207,10 @@ public async Task ClearStateAsync<T>(string grainType, GrainId grainReference, I
198207
}
199208

200209
const string OperationString = "ClearState";
201-
if (storageVersion != null)
210+
var inconsistentStateException = CheckVersionInconsistency(OperationString, serviceId, this.name, storageVersion, grainState.ETag, baseGrainType, grainId.ToString());
211+
if (inconsistentStateException != null)
202212
{
203-
var inconsistentStateException = CheckVersionInconsistency(OperationString, serviceId, this.name, storageVersion, grainState.ETag, baseGrainType, grainId.ToString());
204-
if (inconsistentStateException != null)
205-
{
206-
throw inconsistentStateException;
207-
}
213+
throw inconsistentStateException;
208214
}
209215

210216
//No errors found, the version of the state held by the grain can be updated and also the state.

0 commit comments

Comments
 (0)