diff --git a/Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/RFunctionTests/DelayedStartUpTests.cs b/Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/RFunctionTests/DelayedStartUpTests.cs index 136955758..ec37f482d 100644 --- a/Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/RFunctionTests/DelayedStartUpTests.cs +++ b/Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/RFunctionTests/DelayedStartUpTests.cs @@ -111,7 +111,6 @@ await store.PostponeFunction( registration.MapToStoredId(functionId.Instance), postponeUntil: 0, timestamp: DateTime.UtcNow.Ticks, - ignoreInterrupted: true, expectedReplica: ReplicaId.Empty, effects: null, messages: null, @@ -152,7 +151,6 @@ await store.PostponeFunction( registration.MapToStoredId(functionId.Instance), postponeUntil: 0, timestamp: DateTime.UtcNow.Ticks, - ignoreInterrupted: true, expectedReplica: ReplicaId.Empty, effects: null, messages: null, diff --git a/Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/ShutdownCoordinationTests/RFunctionsShutdownTests.cs b/Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/ShutdownCoordinationTests/RFunctionsShutdownTests.cs index 486c48929..bcb30bc10 100644 --- a/Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/ShutdownCoordinationTests/RFunctionsShutdownTests.cs +++ b/Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/ShutdownCoordinationTests/RFunctionsShutdownTests.cs @@ -183,7 +183,6 @@ await store.PostponeFunction( registration.MapToStoredId(functionId.Instance), postponeUntil: DateTime.UtcNow.AddDays(-1).Ticks, timestamp: DateTime.UtcNow.Ticks, - ignoreInterrupted: true, Guid.Empty.ToReplicaId(), effects: null, messages: null, diff --git a/Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/StoreTests.cs b/Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/StoreTests.cs index 690bd8c0d..49a0f01e2 100644 --- a/Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/StoreTests.cs +++ b/Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/StoreTests.cs @@ -175,8 +175,8 @@ public override Task MultipleFunctionsStatusCanBeFetched() => MultipleFunctionsStatusCanBeFetched(FunctionStoreFactory.Create()); [TestMethod] - public override Task InterruptedFunctionIsNotPostponedWhenFlagIsSet() - => InterruptedFunctionIsNotPostponedWhenFlagIsSet(FunctionStoreFactory.Create()); + public override Task InterruptedFunctionIsNotPostponedToZeroWhenInterrupted() + => InterruptedFunctionIsNotPostponedToZeroWhenInterrupted(FunctionStoreFactory.Create()); [TestMethod] public override Task InterruptNothingWorks() diff --git a/Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/FunctionTests/PostponedTests.cs b/Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/FunctionTests/PostponedTests.cs index b9f1089ae..567808d73 100644 --- a/Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/FunctionTests/PostponedTests.cs +++ b/Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/FunctionTests/PostponedTests.cs @@ -559,7 +559,6 @@ await store.PostponeFunction( storedId, postponeUntil: DateTime.UtcNow.AddDays(-1).Ticks, timestamp: DateTime.UtcNow.Ticks, - ignoreInterrupted: false, expectedReplica: ReplicaId.Empty, effects: null, messages: null, diff --git a/Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/StoreTests.cs b/Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/StoreTests.cs index 3e9209dcc..e11e470ac 100644 --- a/Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/StoreTests.cs +++ b/Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/StoreTests.cs @@ -235,7 +235,6 @@ await store.PostponeFunction( functionId, postponeUntil: nowTicks, timestamp: DateTime.UtcNow.Ticks, - ignoreInterrupted: false, expectedReplica: ReplicaId.Empty, effects: null, messages: null, @@ -273,7 +272,6 @@ await store.PostponeFunction( functionId, postponeUntil: nowTicks, timestamp: DateTime.UtcNow.Ticks, - ignoreInterrupted: false, expectedReplica: ReplicaId.Empty, effects: null, messages: null, @@ -311,7 +309,6 @@ await store.PostponeFunction( functionId, postponeUntil: nowTicks, timestamp: DateTime.UtcNow.Ticks, - ignoreInterrupted: false, expectedReplica: ReplicaId.NewId(), effects: null, messages: null, @@ -802,7 +799,6 @@ await store.PostponeFunction( functionId, postponeUntil: DateTime.UtcNow.Ticks, timestamp: DateTime.UtcNow.Ticks, - ignoreInterrupted: false, expectedReplica: ReplicaId.Empty, effects: null, messages: null, @@ -905,11 +901,12 @@ await store.SuspendFunction( effects: null, messages: null, storageSession: null - ).ShouldBeFalseAsync(); + ).ShouldBeTrueAsync(); var storedFunction = await store.GetFunction(functionId); storedFunction.ShouldNotBeNull(); - (storedFunction.Status is Status.Executing).ShouldBeTrue(); + storedFunction.Status.ShouldBe(Status.Postponed); + storedFunction.Expires.ShouldBe(0); } public abstract Task FunctionIsStillExecutingOnSuspensionAndInterruptCountMismatch(); @@ -945,11 +942,12 @@ await store.MessageStore.AppendMessage( storageSession: null ); - success.ShouldBeFalse(); + success.ShouldBeTrue(); var storedFunction = await store.GetFunction(functionId); storedFunction.ShouldNotBeNull(); - storedFunction.Status.ShouldBe(Status.Executing); + storedFunction.Status.ShouldBe(Status.Postponed); + storedFunction.Expires.ShouldBe(0); } public abstract Task InterruptCountCanBeIncrementedForExecutingFunction(); @@ -1284,8 +1282,8 @@ await store.SucceedFunction( statusAndEpoch2.Status.ShouldBe(Status.Succeeded); } - public abstract Task InterruptedFunctionIsNotPostponedWhenFlagIsSet(); - protected async Task InterruptedFunctionIsNotPostponedWhenFlagIsSet(Task storeTask) + public abstract Task InterruptedFunctionIsNotPostponedToZeroWhenInterrupted(); + protected async Task InterruptedFunctionIsNotPostponedToZeroWhenInterrupted(Task storeTask) { var storedId = TestStoredId.Create(); var store = await storeTask; @@ -1306,17 +1304,17 @@ await store.CreateFunction( var success = await store.PostponeFunction( storedId, postponeUntil: 0, - timestamp: 0, - ignoreInterrupted: false, + timestamp: 100, expectedReplica: ReplicaId.Empty, effects: null, messages: null, storageSession: null ); - success.ShouldBeFalse(); + success.ShouldBeTrue(); var sf = await store.GetFunction(storedId).ShouldNotBeNullAsync(); - sf.Status.ShouldBe(Status.Executing); + sf.Status.ShouldBe(Status.Postponed); + sf.Expires.ShouldBe(0); } public abstract Task InterruptNothingWorks(); @@ -1349,7 +1347,6 @@ await store.CreateFunction( storedId, postponeUntil: 0, timestamp: 0, - ignoreInterrupted: true, expectedReplica: ReplicaId.Empty, effects: null, messages: null, @@ -1803,7 +1800,6 @@ await store.CreateFunction( await store.PostponeFunction( functionId, postponeUntil: DateTime.UtcNow.Ticks, - ignoreInterrupted: false, timestamp: DateTime.UtcNow.Ticks, expectedReplica: ReplicaId.Empty, effects: null, diff --git a/Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/WatchDogsTests/CrashableFunctionStore.cs b/Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/WatchDogsTests/CrashableFunctionStore.cs index 9b16363f5..4e8333ec3 100644 --- a/Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/WatchDogsTests/CrashableFunctionStore.cs +++ b/Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/WatchDogsTests/CrashableFunctionStore.cs @@ -137,7 +137,6 @@ public async Task PostponeFunction( StoredId storedId, long postponeUntil, long timestamp, - bool ignoreInterrupted, ReplicaId expectedReplica, IReadOnlyList? effects, IReadOnlyList? messages, @@ -147,7 +146,7 @@ public async Task PostponeFunction( if (_crashed) throw new TimeoutException(); - var result = await _inner.PostponeFunction(storedId, postponeUntil, timestamp, ignoreInterrupted, expectedReplica, effects, messages, storageSession); + var result = await _inner.PostponeFunction(storedId, postponeUntil, timestamp, expectedReplica, effects, messages, storageSession); AfterPostponeFunctionFlag.Raise(); return result; diff --git a/Core/Cleipnir.ResilientFunctions/CoreRuntime/Invocation/InvocationHelper.cs b/Core/Cleipnir.ResilientFunctions/CoreRuntime/Invocation/InvocationHelper.cs index 4aac35dbe..ae05e1303 100644 --- a/Core/Cleipnir.ResilientFunctions/CoreRuntime/Invocation/InvocationHelper.cs +++ b/Core/Cleipnir.ResilientFunctions/CoreRuntime/Invocation/InvocationHelper.cs @@ -131,7 +131,6 @@ public async Task PersistResult(StoredId storedId, Result< storedId, postponeUntil: result.Postpone!.DateTime.Ticks, timestamp: UtcNow().Ticks, - ignoreInterrupted: true, _replicaId, effects: null, messages: null, @@ -520,7 +519,6 @@ public async Task Reschedule(StoredId id, TParam param) id, postponeUntil: 0, timestamp: UtcNow().Ticks, - ignoreInterrupted: true, _replicaId, effects: null, messages: null, diff --git a/Core/Cleipnir.ResilientFunctions/Storage/IFunctionStore.cs b/Core/Cleipnir.ResilientFunctions/Storage/IFunctionStore.cs index 4d8b4cdcc..070b4a3ec 100644 --- a/Core/Cleipnir.ResilientFunctions/Storage/IFunctionStore.cs +++ b/Core/Cleipnir.ResilientFunctions/Storage/IFunctionStore.cs @@ -85,7 +85,6 @@ Task PostponeFunction( StoredId storedId, long postponeUntil, long timestamp, - bool ignoreInterrupted, ReplicaId expectedReplica, IReadOnlyList? effects, IReadOnlyList? messages, diff --git a/Core/Cleipnir.ResilientFunctions/Storage/InMemoryFunctionStore.cs b/Core/Cleipnir.ResilientFunctions/Storage/InMemoryFunctionStore.cs index 20dc8d9af..192e3fa5d 100644 --- a/Core/Cleipnir.ResilientFunctions/Storage/InMemoryFunctionStore.cs +++ b/Core/Cleipnir.ResilientFunctions/Storage/InMemoryFunctionStore.cs @@ -280,7 +280,6 @@ public Task PostponeFunction( StoredId storedId, long postponeUntil, long timestamp, - bool ignoreInterrupted, ReplicaId? expectedReplica, IReadOnlyList? effects, IReadOnlyList? messages, @@ -293,9 +292,6 @@ public Task PostponeFunction( var state = _states[storedId]; if (state.Owner != expectedReplica) return false.ToTask(); - if (!ignoreInterrupted && state.Interrupted) - return false.ToTask(); - state.Status = Status.Postponed; state.Expires = state.Interrupted ? 0 : postponeUntil; state.Interrupted = false; @@ -348,12 +344,11 @@ public Task SuspendFunction( if (state.Owner != expectedReplica) return false.ToTask(); - if (state.Interrupted) - return false.ToTask(); - - state.Status = Status.Suspended; + state.Status = state.Interrupted ? Status.Postponed : Status.Suspended; + state.Expires = 0; state.Timestamp = timestamp; state.Owner = null; + state.Interrupted = false; return true.ToTask(); } diff --git a/Samples/Sample.ConsoleApp/Utils/CrashableFunctionStore.cs b/Samples/Sample.ConsoleApp/Utils/CrashableFunctionStore.cs index b855abcb7..8ea47e607 100644 --- a/Samples/Sample.ConsoleApp/Utils/CrashableFunctionStore.cs +++ b/Samples/Sample.ConsoleApp/Utils/CrashableFunctionStore.cs @@ -124,14 +124,13 @@ public Task PostponeFunction( StoredId storedId, long postponeUntil, long timestamp, - bool ignoreInterrupted, ReplicaId expectedReplica, IReadOnlyList? effects, IReadOnlyList? messages, IStorageSession? storageSession ) => _crashed ? Task.FromException(new TimeoutException()) - : _inner.PostponeFunction(storedId, postponeUntil, timestamp, ignoreInterrupted, expectedReplica, effects, messages, storageSession); + : _inner.PostponeFunction(storedId, postponeUntil, timestamp, expectedReplica, effects, messages, storageSession); public Task FailFunction( StoredId storedId, diff --git a/Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB.Tests/StoreTests.cs b/Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB.Tests/StoreTests.cs index 849539233..e2b0da995 100644 --- a/Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB.Tests/StoreTests.cs +++ b/Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB.Tests/StoreTests.cs @@ -164,8 +164,8 @@ public override Task MultipleFunctionsStatusCanBeFetched() => MultipleFunctionsStatusCanBeFetched(FunctionStoreFactory.Create()); [TestMethod] - public override Task InterruptedFunctionIsNotPostponedWhenFlagIsSet() - => InterruptedFunctionIsNotPostponedWhenFlagIsSet(FunctionStoreFactory.Create()); + public override Task InterruptedFunctionIsNotPostponedToZeroWhenInterrupted() + => InterruptedFunctionIsNotPostponedToZeroWhenInterrupted(FunctionStoreFactory.Create()); [TestMethod] public override Task InterruptNothingWorks() diff --git a/Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/MariaDbFunctionStore.cs b/Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/MariaDbFunctionStore.cs index 8fe984b88..1ea537ea8 100644 --- a/Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/MariaDbFunctionStore.cs +++ b/Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/MariaDbFunctionStore.cs @@ -357,7 +357,6 @@ public async Task PostponeFunction( StoredId storedId, long postponeUntil, long timestamp, - bool ignoreInterrupted, ReplicaId expectedReplica, IReadOnlyList? effects, IReadOnlyList? messages, @@ -365,7 +364,7 @@ public async Task PostponeFunction( { await using var conn = await CreateOpenConnection(_connectionString); await using var command = _sqlGenerator - .PostponeFunction(storedId, postponeUntil, timestamp, ignoreInterrupted, expectedReplica) + .PostponeFunction(storedId, postponeUntil, timestamp, expectedReplica) .ToSqlCommand(conn); var affectedRows = await command.ExecuteNonQueryAsync(); diff --git a/Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/SqlGenerator.cs b/Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/SqlGenerator.cs index 769921e41..c5e87281d 100644 --- a/Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/SqlGenerator.cs +++ b/Stores/MariaDB/Cleipnir.ResilientFunctions.MariaDB/SqlGenerator.cs @@ -239,7 +239,6 @@ public StoreCommand PostponeFunction( StoredId storedId, long postponeUntil, long timestamp, - bool ignoreInterrupted, ReplicaId expectedReplica) { _postponedFunctionSql ??= $@" @@ -251,15 +250,10 @@ public StoreCommand PostponeFunction( interrupted = 0 WHERE id = ? AND - owner = ? AND - interrupted=0"; - - var sql = _postponedFunctionSql; - if (ignoreInterrupted) - sql = sql.Replace("interrupted=0", "1 = 1"); + owner = ?"; return StoreCommand.Create( - sql, + _postponedFunctionSql, values: [ postponeUntil, timestamp, @@ -299,11 +293,12 @@ public StoreCommand SuspendFunction(StoredId storedId, long timestamp, ReplicaId { _suspendFunctionSql ??= $@" UPDATE {tablePrefix} - SET status = {(int) Status.Suspended}, timestamp = ?, owner = NULL - WHERE - id = ? AND - owner = ? AND - NOT interrupted"; + SET status = CASE WHEN interrupted = 1 THEN {(int) Status.Postponed} ELSE {(int) Status.Suspended} END, + expires = 0, + timestamp = ?, + owner = NULL, + interrupted = 0 + WHERE id = ? AND owner = ?"; return StoreCommand.Create( _suspendFunctionSql, diff --git a/Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL.Tests/StoreTests.cs b/Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL.Tests/StoreTests.cs index 0229360e4..dbc55a8b2 100644 --- a/Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL.Tests/StoreTests.cs +++ b/Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL.Tests/StoreTests.cs @@ -167,8 +167,8 @@ public override Task MultipleFunctionsStatusCanBeFetched() => MultipleFunctionsStatusCanBeFetched(FunctionStoreFactory.Create()); [TestMethod] - public override Task InterruptedFunctionIsNotPostponedWhenFlagIsSet() - => InterruptedFunctionIsNotPostponedWhenFlagIsSet(FunctionStoreFactory.Create()); + public override Task InterruptedFunctionIsNotPostponedToZeroWhenInterrupted() + => InterruptedFunctionIsNotPostponedToZeroWhenInterrupted(FunctionStoreFactory.Create()); [TestMethod] public override Task InterruptNothingWorks() diff --git a/Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL/PostgreSqlFunctionStore.cs b/Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL/PostgreSqlFunctionStore.cs index 63cc9de14..f03afc478 100644 --- a/Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL/PostgreSqlFunctionStore.cs +++ b/Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL/PostgreSqlFunctionStore.cs @@ -390,7 +390,6 @@ public async Task PostponeFunction( StoredId storedId, long postponeUntil, long timestamp, - bool ignoreInterrupted, ReplicaId expectedReplica, IReadOnlyList? effects, IReadOnlyList? messages, @@ -401,7 +400,6 @@ public async Task PostponeFunction( storedId, postponeUntil, timestamp, - ignoreInterrupted, expectedReplica ).ToNpgsqlCommand(conn); diff --git a/Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL/SqlGenerator.cs b/Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL/SqlGenerator.cs index 49f598304..a683c83fa 100644 --- a/Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL/SqlGenerator.cs +++ b/Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL/SqlGenerator.cs @@ -231,7 +231,6 @@ public StoreCommand PostponeFunction( StoredId storedId, long postponeUntil, long timestamp, - bool ignoreInterrupted, ReplicaId expectedReplica) { _postponeFunctionSql ??= $@" @@ -243,15 +242,10 @@ public StoreCommand PostponeFunction( interrupted = FALSE WHERE id = $3 AND - owner = $4 AND - NOT interrupted"; - - var sql = _postponeFunctionSql; - if (ignoreInterrupted) - sql = sql.Replace("NOT interrupted", "1 = 1"); + owner = $4"; return StoreCommand.Create( - sql, + _postponeFunctionSql, values: [ postponeUntil, timestamp, @@ -289,10 +283,12 @@ public StoreCommand SuspendFunction(StoredId storedId, long timestamp, ReplicaId { _suspendFunctionSql ??= $@" UPDATE {tablePrefix} - SET status = {(int)Status.Suspended}, timestamp = $1, owner = NULL - WHERE id = $2 AND - owner = $3 AND - NOT interrupted;"; + SET status = CASE WHEN interrupted THEN {(int) Status.Postponed} ELSE {(int) Status.Suspended} END, + expires = 0, + timestamp = $1, + owner = NULL, + interrupted = FALSE + WHERE id = $2 AND owner = $3"; return StoreCommand.Create( _suspendFunctionSql, diff --git a/Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer.Tests/StoreTests.cs b/Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer.Tests/StoreTests.cs index 05b3b5e3e..f2eec6e35 100644 --- a/Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer.Tests/StoreTests.cs +++ b/Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer.Tests/StoreTests.cs @@ -167,8 +167,8 @@ public override Task MultipleFunctionsStatusCanBeFetched() => MultipleFunctionsStatusCanBeFetched(FunctionStoreFactory.Create()); [TestMethod] - public override Task InterruptedFunctionIsNotPostponedWhenFlagIsSet() - => InterruptedFunctionIsNotPostponedWhenFlagIsSet(FunctionStoreFactory.Create()); + public override Task InterruptedFunctionIsNotPostponedToZeroWhenInterrupted() + => InterruptedFunctionIsNotPostponedToZeroWhenInterrupted(FunctionStoreFactory.Create()); [TestMethod] public override Task InterruptNothingWorks() diff --git a/Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlGenerator.cs b/Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlGenerator.cs index 8fd884839..39397a067 100644 --- a/Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlGenerator.cs +++ b/Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlGenerator.cs @@ -302,7 +302,7 @@ public StoreCommand SucceedFunction(StoredId storedId, byte[]? result, long time } private string? _postponedFunctionSql; - public StoreCommand PostponeFunction(StoredId storedId, long postponeUntil, long timestamp, bool ignoreInterrupted, ReplicaId expectedReplica, string paramPrefix) + public StoreCommand PostponeFunction(StoredId storedId, long postponeUntil, long timestamp, ReplicaId expectedReplica, string paramPrefix) { _postponedFunctionSql ??= @$" UPDATE {tablePrefix} @@ -311,15 +311,12 @@ public StoreCommand PostponeFunction(StoredId storedId, long postponeUntil, long Timestamp = @Timestamp, Owner = NULL, Interrupted = 0 - WHERE Id = @Id AND Owner = @ExpectedReplica AND Interrupted=0"; + WHERE Id = @Id AND Owner = @ExpectedReplica"; var sql = paramPrefix == "" ? _postponedFunctionSql : _postponedFunctionSql.Replace("@", $"@{paramPrefix}"); - if (ignoreInterrupted) - sql = sql.Replace("Interrupted=0", "1 = 1"); - var command = StoreCommand.Create(sql); command.AddParameter($"@{paramPrefix}PostponedUntil", postponeUntil); command.AddParameter($"@{paramPrefix}Timestamp", timestamp); @@ -352,23 +349,25 @@ public StoreCommand FailFunction(StoredId storedId, StoredException storedExcept private string? _suspendFunctionSql; public StoreCommand SuspendFunction( - StoredId storedId, + StoredId storedId, long timestamp, - ReplicaId expectedReplica, + ReplicaId expectedReplica, string paramPrefix ) { _suspendFunctionSql ??= @$" UPDATE {tablePrefix} - SET Status = {(int)Status.Suspended}, Timestamp = @Timestamp, Owner = NULL - WHERE Id = @Id AND - Owner = @ExpectedReplica AND - Interrupted = 0;"; - - var sql = paramPrefix == "" + SET Status = CASE WHEN Interrupted = 1 THEN {(int) Status.Postponed} ELSE {(int) Status.Suspended} END, + Expires = 0, + Timestamp = @Timestamp, + Owner = NULL, + Interrupted = 0 + WHERE Id = @Id AND Owner = @ExpectedReplica"; + + var sql = paramPrefix == "" ? _suspendFunctionSql : _suspendFunctionSql.Replace("@", $"@{paramPrefix}"); - + var command = StoreCommand.Create(sql); command.AddParameter($"@{paramPrefix}Timestamp", timestamp); command.AddParameter($"@{paramPrefix}Id", storedId.AsGuid); diff --git a/Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlServerFunctionStore.cs b/Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlServerFunctionStore.cs index a2c4ee985..3536b6845 100644 --- a/Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlServerFunctionStore.cs +++ b/Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer/SqlServerFunctionStore.cs @@ -412,7 +412,6 @@ public async Task PostponeFunction( StoredId storedId, long postponeUntil, long timestamp, - bool ignoreInterrupted, ReplicaId expectedReplica, IReadOnlyList? effects, IReadOnlyList? messages, @@ -423,7 +422,6 @@ public async Task PostponeFunction( storedId, postponeUntil, timestamp, - ignoreInterrupted, expectedReplica, paramPrefix: "" ).ToSqlCommand(conn); diff --git a/Stores/StressTests/StressTests/PostponedTest.cs b/Stores/StressTests/StressTests/PostponedTest.cs index 8ffcac936..64fa21884 100644 --- a/Stores/StressTests/StressTests/PostponedTest.cs +++ b/Stores/StressTests/StressTests/PostponedTest.cs @@ -41,7 +41,6 @@ await store.PostponeFunction( StoredId.Create(storedType, i.ToString()), postponeUntil: start.Ticks, timestamp: DateTime.UtcNow.Ticks, - ignoreInterrupted: true, expectedReplica: ReplicaId.Empty, effects: null, messages: null,