Skip to content

Commit f25e884

Browse files
committed
Postpone, Succeed, Fail state changes all reset owner to null
1 parent 16c7a2e commit f25e884

File tree

9 files changed

+208
-12
lines changed

9 files changed

+208
-12
lines changed

Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/StoreTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,20 @@ public override Task RestartExecutionWorksWithEmptyEffectsAndMessages()
231231
[TestMethod]
232232
public override Task FunctionOwnedByReplicaIsPostponedAfterRescheduleFunctionsInvocation()
233233
=> FunctionOwnedByReplicaIsPostponedAfterRescheduleFunctionsInvocation(FunctionStoreFactory.Create());
234+
235+
[TestMethod]
236+
public override Task SuspensionSetsOwnerToNull()
237+
=> SuspensionSetsOwnerToNull(FunctionStoreFactory.Create());
238+
239+
[TestMethod]
240+
public override Task FailureSetsOwnerToNull()
241+
=> FailureSetsOwnerToNull(FunctionStoreFactory.Create());
242+
243+
[TestMethod]
244+
public override Task PostponedSetsOwnerToNull()
245+
=> PostponedSetsOwnerToNull(FunctionStoreFactory.Create());
246+
247+
[TestMethod]
248+
public override Task SucceedSetsOwnerToNull()
249+
=> SucceedSetsOwnerToNull(FunctionStoreFactory.Create());
234250
}

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/StoreTests.cs

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,4 +1981,132 @@ await store.CreateFunction(
19811981
replicas.Count.ShouldBe(1);
19821982
replicas.Any(r => r == replicaId2).ShouldBeTrue();
19831983
}
1984+
1985+
public abstract Task SuspensionSetsOwnerToNull();
1986+
protected async Task SuspensionSetsOwnerToNull(Task<IFunctionStore> storeTask)
1987+
{
1988+
var functionId = TestStoredId.Create();
1989+
1990+
var store = await storeTask;
1991+
await store.CreateFunction(
1992+
functionId,
1993+
"humanInstanceId",
1994+
param: Test.SimpleStoredParameter,
1995+
leaseExpiration: DateTime.UtcNow.Ticks,
1996+
postponeUntil: null,
1997+
timestamp: DateTime.UtcNow.Ticks,
1998+
parent: null,
1999+
owner: ReplicaId.NewId()
2000+
).ShouldBeTrueAsync();
2001+
2002+
await store.SuspendFunction(
2003+
functionId,
2004+
timestamp: DateTime.UtcNow.Ticks,
2005+
expectedEpoch: 0,
2006+
effects: null,
2007+
messages: null,
2008+
complimentaryState: new ComplimentaryState(Test.SimpleStoredParameter.ToFunc(), LeaseLength: 0)
2009+
).ShouldBeTrueAsync();
2010+
2011+
var storedFunction = await store.GetFunction(functionId);
2012+
storedFunction.ShouldNotBeNull();
2013+
storedFunction.OwnerId.ShouldBeNull();
2014+
}
2015+
2016+
public abstract Task FailureSetsOwnerToNull();
2017+
protected async Task FailureSetsOwnerToNull(Task<IFunctionStore> storeTask)
2018+
{
2019+
var functionId = TestStoredId.Create();
2020+
2021+
var store = await storeTask;
2022+
await store.CreateFunction(
2023+
functionId,
2024+
"humanInstanceId",
2025+
param: Test.SimpleStoredParameter,
2026+
leaseExpiration: DateTime.UtcNow.Ticks,
2027+
postponeUntil: null,
2028+
timestamp: DateTime.UtcNow.Ticks,
2029+
parent: null,
2030+
owner: ReplicaId.NewId()
2031+
).ShouldBeTrueAsync();
2032+
2033+
await store.FailFunction(
2034+
functionId,
2035+
timestamp: DateTime.UtcNow.Ticks,
2036+
expectedEpoch: 0,
2037+
effects: null,
2038+
messages: null,
2039+
storedException: new StoredException("SomeMessage", ExceptionStackTrace: null, "SomeExceptionType"),
2040+
complimentaryState: new ComplimentaryState(Test.SimpleStoredParameter.ToFunc(), LeaseLength: 0)
2041+
).ShouldBeTrueAsync();
2042+
2043+
var storedFunction = await store.GetFunction(functionId);
2044+
storedFunction.ShouldNotBeNull();
2045+
storedFunction.OwnerId.ShouldBeNull();
2046+
}
2047+
2048+
public abstract Task PostponedSetsOwnerToNull();
2049+
protected async Task PostponedSetsOwnerToNull(Task<IFunctionStore> storeTask)
2050+
{
2051+
var functionId = TestStoredId.Create();
2052+
2053+
var store = await storeTask;
2054+
await store.CreateFunction(
2055+
functionId,
2056+
"humanInstanceId",
2057+
param: Test.SimpleStoredParameter,
2058+
leaseExpiration: DateTime.UtcNow.Ticks,
2059+
postponeUntil: null,
2060+
timestamp: DateTime.UtcNow.Ticks,
2061+
parent: null,
2062+
owner: ReplicaId.NewId()
2063+
).ShouldBeTrueAsync();
2064+
2065+
await store.PostponeFunction(
2066+
functionId,
2067+
postponeUntil: DateTime.UtcNow.Ticks,
2068+
ignoreInterrupted: false,
2069+
timestamp: DateTime.UtcNow.Ticks,
2070+
expectedEpoch: 0,
2071+
effects: null,
2072+
messages: null,
2073+
complimentaryState: new ComplimentaryState(Test.SimpleStoredParameter.ToFunc(), LeaseLength: 0)
2074+
).ShouldBeTrueAsync();
2075+
2076+
var storedFunction = await store.GetFunction(functionId);
2077+
storedFunction.ShouldNotBeNull();
2078+
storedFunction.OwnerId.ShouldBeNull();
2079+
}
2080+
2081+
public abstract Task SucceedSetsOwnerToNull();
2082+
protected async Task SucceedSetsOwnerToNull(Task<IFunctionStore> storeTask)
2083+
{
2084+
var functionId = TestStoredId.Create();
2085+
2086+
var store = await storeTask;
2087+
await store.CreateFunction(
2088+
functionId,
2089+
"humanInstanceId",
2090+
param: Test.SimpleStoredParameter,
2091+
leaseExpiration: DateTime.UtcNow.Ticks,
2092+
postponeUntil: null,
2093+
timestamp: DateTime.UtcNow.Ticks,
2094+
parent: null,
2095+
owner: ReplicaId.NewId()
2096+
).ShouldBeTrueAsync();
2097+
2098+
await store.SucceedFunction(
2099+
functionId,
2100+
result: null,
2101+
timestamp: DateTime.UtcNow.Ticks,
2102+
expectedEpoch: 0,
2103+
effects: null,
2104+
messages: null,
2105+
complimentaryState: new ComplimentaryState(Test.SimpleStoredParameter.ToFunc(), LeaseLength: 0)
2106+
).ShouldBeTrueAsync();
2107+
2108+
var storedFunction = await store.GetFunction(functionId);
2109+
storedFunction.ShouldNotBeNull();
2110+
storedFunction.OwnerId.ShouldBeNull();
2111+
}
19842112
}

Core/Cleipnir.ResilientFunctions/Storage/InMemoryFunctionStore.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ public Task<bool> SucceedFunction(
250250
state.Status = Status.Succeeded;
251251
state.Result = result;
252252
state.Timestamp = timestamp;
253+
state.Owner = null;
253254

254255
return true.ToTask();
255256
}
@@ -278,6 +279,7 @@ public Task<bool> PostponeFunction(
278279
state.Status = Status.Postponed;
279280
state.Expires = postponeUntil;
280281
state.Timestamp = timestamp;
282+
state.Owner = null;
281283

282284
return true.ToTask();
283285
}
@@ -302,6 +304,7 @@ public Task<bool> FailFunction(
302304
state.Status = Status.Failed;
303305
state.Exception = storedException;
304306
state.Timestamp = timestamp;
307+
state.Owner = null;
305308

306309
return true.ToTask();
307310
}
@@ -329,6 +332,7 @@ public Task<bool> SuspendFunction(
329332

330333
state.Status = Status.Suspended;
331334
state.Timestamp = timestamp;
335+
state.Owner = null;
332336

333337
return true.ToTask();
334338
}

Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB.Tests/StoreTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,20 @@ public override Task RestartExecutionWorksWithEmptyEffectsAndMessages()
222222
[TestMethod]
223223
public override Task FunctionOwnedByReplicaIsPostponedAfterRescheduleFunctionsInvocation()
224224
=> FunctionOwnedByReplicaIsPostponedAfterRescheduleFunctionsInvocation(FunctionStoreFactory.Create());
225+
226+
[TestMethod]
227+
public override Task SuspensionSetsOwnerToNull()
228+
=> SuspensionSetsOwnerToNull(FunctionStoreFactory.Create());
229+
230+
[TestMethod]
231+
public override Task FailureSetsOwnerToNull()
232+
=> FailureSetsOwnerToNull(FunctionStoreFactory.Create());
233+
234+
[TestMethod]
235+
public override Task PostponedSetsOwnerToNull()
236+
=> PostponedSetsOwnerToNull(FunctionStoreFactory.Create());
237+
238+
[TestMethod]
239+
public override Task SucceedSetsOwnerToNull()
240+
=> SucceedSetsOwnerToNull(FunctionStoreFactory.Create());
225241
}

Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/SqlGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public StoreCommand SucceedFunction(
227227
{
228228
_succeedFunctionSql ??= $@"
229229
UPDATE {tablePrefix}
230-
SET status = {(int) Status.Succeeded}, result_json = ?, timestamp = ?, epoch = ?
230+
SET status = {(int) Status.Succeeded}, result_json = ?, timestamp = ?, epoch = ?, owner = NULL
231231
WHERE
232232
type = ? AND
233233
instance = ? AND
@@ -256,7 +256,7 @@ public StoreCommand PostponeFunction(
256256
{
257257
_postponedFunctionSql ??= $@"
258258
UPDATE {tablePrefix}
259-
SET status = {(int) Status.Postponed}, expires = ?, timestamp = ?, epoch = ?
259+
SET status = {(int) Status.Postponed}, expires = ?, timestamp = ?, epoch = ?, owner = NULL
260260
WHERE
261261
type = ? AND
262262
instance = ? AND
@@ -289,7 +289,7 @@ public StoreCommand FailFunction(
289289
{
290290
_failFunctionSql ??= $@"
291291
UPDATE {tablePrefix}
292-
SET status = {(int) Status.Failed}, exception_json = ?, timestamp = ?, epoch = ?
292+
SET status = {(int) Status.Failed}, exception_json = ?, timestamp = ?, epoch = ?, owner = NULL
293293
WHERE
294294
type = ? AND
295295
instance = ? AND
@@ -313,7 +313,7 @@ public StoreCommand SuspendFunction(StoredId storedId, long timestamp, int expec
313313
{
314314
_suspendFunctionSql ??= $@"
315315
UPDATE {tablePrefix}
316-
SET status = {(int) Status.Suspended}, timestamp = ?
316+
SET status = {(int) Status.Suspended}, timestamp = ?, owner = NULL
317317
WHERE type = ? AND
318318
instance = ? AND
319319
epoch = ? AND

Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL.Tests/StoreTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,20 @@ public override Task RestartExecutionWorksWithEmptyEffectsAndMessages()
224224
[TestMethod]
225225
public override Task FunctionOwnedByReplicaIsPostponedAfterRescheduleFunctionsInvocation()
226226
=> FunctionOwnedByReplicaIsPostponedAfterRescheduleFunctionsInvocation(FunctionStoreFactory.Create());
227+
228+
[TestMethod]
229+
public override Task SuspensionSetsOwnerToNull()
230+
=> SuspensionSetsOwnerToNull(FunctionStoreFactory.Create());
231+
232+
[TestMethod]
233+
public override Task FailureSetsOwnerToNull()
234+
=> FailureSetsOwnerToNull(FunctionStoreFactory.Create());
235+
236+
[TestMethod]
237+
public override Task PostponedSetsOwnerToNull()
238+
=> PostponedSetsOwnerToNull(FunctionStoreFactory.Create());
239+
240+
[TestMethod]
241+
public override Task SucceedSetsOwnerToNull()
242+
=> SucceedSetsOwnerToNull(FunctionStoreFactory.Create());
227243
}

Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL/SqlGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public StoreCommand SucceedFunction(
192192
{
193193
_succeedFunctionSql ??= $@"
194194
UPDATE {tablePrefix}
195-
SET status = {(int) Status.Succeeded}, result_json = $1, timestamp = $2
195+
SET status = {(int) Status.Succeeded}, result_json = $1, timestamp = $2, owner = NULL
196196
WHERE
197197
type = $3 AND
198198
instance = $4 AND
@@ -221,7 +221,7 @@ public StoreCommand PostponeFunction(
221221
{
222222
_postponeFunctionSql ??= $@"
223223
UPDATE {tablePrefix}
224-
SET status = {(int) Status.Postponed}, expires = $1, timestamp = $2
224+
SET status = {(int) Status.Postponed}, expires = $1, timestamp = $2, owner = NULL
225225
WHERE
226226
type = $3 AND
227227
instance = $4 AND
@@ -253,7 +253,7 @@ public StoreCommand FailFunction(
253253
{
254254
_failFunctionSql ??= $@"
255255
UPDATE {tablePrefix}
256-
SET status = {(int) Status.Failed}, exception_json = $1, timestamp = $2
256+
SET status = {(int) Status.Failed}, exception_json = $1, timestamp = $2, owner = NULL
257257
WHERE
258258
type = $3 AND
259259
instance = $4 AND
@@ -276,7 +276,7 @@ public StoreCommand SuspendFunction(StoredId storedId, long timestamp, int expec
276276
{
277277
_suspendFunctionSql ??= $@"
278278
UPDATE {tablePrefix}
279-
SET status = {(int)Status.Suspended}, timestamp = $1
279+
SET status = {(int)Status.Suspended}, timestamp = $1, owner = NULL
280280
WHERE type = $2 AND
281281
instance = $3 AND
282282
epoch = $4 AND

Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer.Tests/StoreTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,20 @@ public override Task RestartExecutionWorksWithEmptyEffectsAndMessages()
223223
[TestMethod]
224224
public override Task FunctionOwnedByReplicaIsPostponedAfterRescheduleFunctionsInvocation()
225225
=> FunctionOwnedByReplicaIsPostponedAfterRescheduleFunctionsInvocation(FunctionStoreFactory.Create());
226+
227+
[TestMethod]
228+
public override Task SuspensionSetsOwnerToNull()
229+
=> SuspensionSetsOwnerToNull(FunctionStoreFactory.Create());
230+
231+
[TestMethod]
232+
public override Task FailureSetsOwnerToNull()
233+
=> FailureSetsOwnerToNull(FunctionStoreFactory.Create());
234+
235+
[TestMethod]
236+
public override Task PostponedSetsOwnerToNull()
237+
=> PostponedSetsOwnerToNull(FunctionStoreFactory.Create());
238+
239+
[TestMethod]
240+
public override Task SucceedSetsOwnerToNull()
241+
=> SucceedSetsOwnerToNull(FunctionStoreFactory.Create());
226242
}

Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlGenerator.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public StoreCommand SucceedFunction(StoredId storedId, byte[]? result, long time
262262
{
263263
_succeedFunctionSql ??= @$"
264264
UPDATE {tablePrefix}
265-
SET Status = {(int) Status.Succeeded}, ResultJson = @ResultJson, Timestamp = @Timestamp, Epoch = @ExpectedEpoch
265+
SET Status = {(int) Status.Succeeded}, ResultJson = @ResultJson, Timestamp = @Timestamp, Epoch = @ExpectedEpoch, Owner = NULL
266266
WHERE FlowType = @FlowType AND FlowInstance = @FlowInstance AND Epoch = @ExpectedEpoch";
267267

268268
var sql = paramPrefix == ""
@@ -284,7 +284,7 @@ public StoreCommand PostponeFunction(StoredId storedId, long postponeUntil, long
284284
{
285285
_postponedFunctionSql ??= @$"
286286
UPDATE {tablePrefix}
287-
SET Status = {(int) Status.Postponed}, Expires = @PostponedUntil, Timestamp = @Timestamp, Epoch = @ExpectedEpoch
287+
SET Status = {(int) Status.Postponed}, Expires = @PostponedUntil, Timestamp = @Timestamp, Epoch = @ExpectedEpoch, Owner = NULL
288288
WHERE FlowType = @FlowType AND FlowInstance = @FlowInstance AND Epoch = @ExpectedEpoch AND Interrupted = 0";
289289

290290
var sql = paramPrefix == ""
@@ -309,7 +309,7 @@ public StoreCommand FailFunction(StoredId storedId, StoredException storedExcept
309309
{
310310
_failFunctionSql ??= @$"
311311
UPDATE {tablePrefix}
312-
SET Status = {(int) Status.Failed}, ExceptionJson = @ExceptionJson, Timestamp = @timestamp, Epoch = @ExpectedEpoch
312+
SET Status = {(int) Status.Failed}, ExceptionJson = @ExceptionJson, Timestamp = @timestamp, Epoch = @ExpectedEpoch, Owner = NULL
313313
WHERE FlowType = @FlowType
314314
AND FlowInstance = @FlowInstance
315315
AND Epoch = @ExpectedEpoch";
@@ -338,7 +338,7 @@ string paramPrefix
338338
{
339339
_suspendFunctionSql ??= @$"
340340
UPDATE {tablePrefix}
341-
SET Status = {(int)Status.Suspended}, Timestamp = @Timestamp
341+
SET Status = {(int)Status.Suspended}, Timestamp = @Timestamp, Owner = NULL
342342
WHERE FlowType = @FlowType AND
343343
FlowInstance = @FlowInstance AND
344344
Epoch = @ExpectedEpoch AND

0 commit comments

Comments
 (0)