Skip to content

Commit dcb8af0

Browse files
committed
Rename RestartExecution/s to ClaimFunction/s and add owner-guarded SetFunction
The store's RestartExecution/RestartExecutions really take over ownership of a flow and hand back its current state, so rename them to ClaimFunction/ClaimFunctions across the IFunctionStore interface, all four stores and their SqlGenerators, the test doubles and the store test templates. The higher-level FlowsManager.RestartExecutions(messages) orchestration, InvocationHelper.RestartFunction and the RestartedFunction record keep their names; only their store calls are repointed. Add IFunctionStore.SetFunction: an owner-guarded general state-setter that writes status, owner (null releases) and, when provided, the effects snapshot in a single UPDATE guarded by owner = expectedReplica. expectedReplica is non-nullable - the caller must already own the flow - matching the terminal writers. This gives a claim-commit-release primitive without bespoke SQL. Surface the flow's current result bytes on the claim result by adding Result to StoredFlowWithEffects (StorageSession kept last), populated from result_json (SQL stores) and the in-memory state, so a caller can pass it straight into SetFunction without nulling the result. Build clean; InMemory 520 passed; ClaimFunction/SetFunction green on Postgres/SqlServer/MariaDB; full PostgreSQL suite 373 passed.
1 parent c834dba commit dcb8af0

26 files changed

Lines changed: 860 additions & 205 deletions

File tree

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

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,41 @@ public override Task ParameterAndStateAreNotUpdatedWhenEpochDoesNotMatch()
5858

5959

6060
[TestMethod]
61-
public override Task RestartExecutionsReturnsEmptyDictionaryWhenNoFlowsAreEligible()
62-
=> RestartExecutionsReturnsEmptyDictionaryWhenNoFlowsAreEligible(FunctionStoreFactory.Create());
61+
public override Task ClaimFunctionsReturnsEmptyDictionaryWhenNoFlowsAreEligible()
62+
=> ClaimFunctionsReturnsEmptyDictionaryWhenNoFlowsAreEligible(FunctionStoreFactory.Create());
6363

6464

6565

6666

6767
[TestMethod]
68-
public override Task RestartExecutionsRestartsMultipleUnownedFlows()
69-
=> RestartExecutionsRestartsMultipleUnownedFlows(FunctionStoreFactory.Create());
68+
public override Task ClaimFunctionsRestartsMultipleUnownedFlows()
69+
=> ClaimFunctionsRestartsMultipleUnownedFlows(FunctionStoreFactory.Create());
7070

7171
[TestMethod]
72-
public override Task RestartExecutionsRestartsOnlyUnownedFlows()
73-
=> RestartExecutionsRestartsOnlyUnownedFlows(FunctionStoreFactory.Create());
72+
public override Task ClaimFunctionsRestartsOnlyUnownedFlows()
73+
=> ClaimFunctionsRestartsOnlyUnownedFlows(FunctionStoreFactory.Create());
7474

7575
[TestMethod]
76-
public override Task RestartExecutionsReturnsEmptyDictionaryForEmptyInput()
77-
=> RestartExecutionsReturnsEmptyDictionaryForEmptyInput(FunctionStoreFactory.Create());
76+
public override Task ClaimFunctionsReturnsEmptyDictionaryForEmptyInput()
77+
=> ClaimFunctionsReturnsEmptyDictionaryForEmptyInput(FunctionStoreFactory.Create());
7878

7979
[TestMethod]
80-
public override Task RestartExecutionsIncludesExistingEffects()
81-
=> RestartExecutionsIncludesExistingEffects(FunctionStoreFactory.Create());
80+
public override Task ClaimFunctionsIncludesExistingEffects()
81+
=> ClaimFunctionsIncludesExistingEffects(FunctionStoreFactory.Create());
82+
83+
[TestMethod]
84+
public override Task SetFunctionUpdatesStatusOwnerAndEffectsWhenGuardMatches()
85+
=> SetFunctionUpdatesStatusOwnerAndEffectsWhenGuardMatches(FunctionStoreFactory.Create());
86+
87+
[TestMethod]
88+
public override Task SetFunctionReturnsFalseAndNoOpsWhenExpectedReplicaDoesNotMatch()
89+
=> SetFunctionReturnsFalseAndNoOpsWhenExpectedReplicaDoesNotMatch(FunctionStoreFactory.Create());
90+
91+
[TestMethod]
92+
public override Task SetFunctionWithNullOwnerReleasesOwnership()
93+
=> SetFunctionWithNullOwnerReleasesOwnership(FunctionStoreFactory.Create());
94+
95+
[TestMethod]
96+
public override Task SetFunctionWithNullEffectsLeavesEffectsUntouched()
97+
=> SetFunctionWithNullEffectsLeavesEffectsUntouched(FunctionStoreFactory.Create());
8298
}

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,16 @@ public override Task FunctionCanBeCreatedWithEffectsOnly()
171171
=> FunctionCanBeCreatedWithEffectsOnly(FunctionStoreFactory.Create());
172172

173173
[TestMethod]
174-
public override Task RestartExecutionReturnsEffects()
175-
=> RestartExecutionReturnsEffects(FunctionStoreFactory.Create());
174+
public override Task ClaimFunctionReturnsEffects()
175+
=> ClaimFunctionReturnsEffects(FunctionStoreFactory.Create());
176176

177177
[TestMethod]
178-
public override Task RestartExecutionWorksWithEmptyEffects()
179-
=> RestartExecutionWorksWithEmptyEffects(FunctionStoreFactory.Create());
178+
public override Task ClaimFunctionWorksWithEmptyEffects()
179+
=> ClaimFunctionWorksWithEmptyEffects(FunctionStoreFactory.Create());
180+
181+
[TestMethod]
182+
public override Task ClaimFunctionSurfacesResult()
183+
=> ClaimFunctionSurfacesResult(FunctionStoreFactory.Create());
180184

181185
[TestMethod]
182186
public override Task FunctionOwnedByReplicaIsPostponedAfterRescheduleFunctionsInvocation()
@@ -212,14 +216,14 @@ public override Task GetResultsReturnsOnlyExistingFunctionResults()
212216

213217

214218
[TestMethod]
215-
public override Task RestartExecutionsDoesNotReturnFlowClaimedByPreviousCall()
216-
=> RestartExecutionsDoesNotReturnFlowClaimedByPreviousCall(FunctionStoreFactory.Create());
219+
public override Task ClaimFunctionsDoesNotReturnFlowClaimedByPreviousCall()
220+
=> ClaimFunctionsDoesNotReturnFlowClaimedByPreviousCall(FunctionStoreFactory.Create());
217221

218222
[TestMethod]
219-
public override Task RestartExecutionsDoesNotClaimSucceededFlow()
220-
=> RestartExecutionsDoesNotClaimSucceededFlow(FunctionStoreFactory.Create());
223+
public override Task ClaimFunctionsDoesNotClaimSucceededFlow()
224+
=> ClaimFunctionsDoesNotClaimSucceededFlow(FunctionStoreFactory.Create());
221225

222226
[TestMethod]
223-
public override Task RestartExecutionsClaimsSuspendedFlow()
224-
=> RestartExecutionsClaimsSuspendedFlow(FunctionStoreFactory.Create());
227+
public override Task ClaimFunctionsClaimsSuspendedFlow()
228+
=> ClaimFunctionsClaimsSuspendedFlow(FunctionStoreFactory.Create());
225229
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ protected async Task StoreCanHandleMultipleEffectsWithSameIdOnDifferentSessions(
614614
);
615615

616616
await store.RescheduleCrashedFunctions(crashingReplicaId);
617-
var storageSession2 = await store.RestartExecution(
617+
var storageSession2 = await store.ClaimFunction(
618618
storedId,
619619
owner: ReplicaId.NewId()
620620
).SelectAsync(s => s!.StorageSession);

0 commit comments

Comments
 (0)