Skip to content

Commit

Permalink
fix: allow to resume a running session (#802)
Browse files Browse the repository at this point in the history
# Motivation

Allow a running session to be resumed. It also allows to retry Resume
RPC when errors occur. Does not put tasks back in Paused status when an
error occur.

# Description

- Remove the call to change the task status back to paused when there is
an exception.
- Allow session status change to Running when the session is already
Running

# Testing

- Tests were performed with the GUI on the ArmoniK infrastructure. It
fixes the issue when the Resume RPC times out. The tasks are not put
back in Paused.

# Impact

- Resume is working more reliably.

# Checklist

- [x] My code adheres to the coding and style guidelines of the project.
- [x] I have performed a self-review of my code.
- [ ] I have commented my code, particularly in hard-to-understand
areas.
- [ ] I have made corresponding changes to the documentation.
- [x] I have thoroughly tested my modifications and added tests when
necessary.
- [x] Tests pass locally and in the CI.
- [x] I have assessed the performance impact of my modifications.
  • Loading branch information
aneojgurhem authored Nov 27, 2024
2 parents b7646ca + de4e7e1 commit 2e55acc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Common/src/Storage/SessionTableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public static async Task<SessionData> ResumeSessionAsync(this ISessionTable sess
CancellationToken cancellationToken = default)
{
var session = await sessionTable.UpdateOneSessionAsync(sessionId,
data => data.Status == SessionStatus.Paused,
data => data.Status == SessionStatus.Paused || data.Status == SessionStatus.Running,
new UpdateDefinition<SessionData>().Set(model => model.Status,
SessionStatus.Running),
false,
Expand All @@ -251,8 +251,8 @@ public static async Task<SessionData> ResumeSessionAsync(this ISessionTable sess
switch (session.Status)
{
case SessionStatus.Paused:
throw new UnreachableException($"Session status should be {SessionStatus.Running} but is {session.Status}");
case SessionStatus.Running:
throw new UnreachableException($"Session status should be {SessionStatus.Running} but is {session.Status}");
case SessionStatus.Purged:
case SessionStatus.Cancelled:
throw new InvalidSessionTransitionException($"Cannot resume a session with status {session.Status}");
Expand Down
18 changes: 4 additions & 14 deletions Common/src/gRPC/Services/GrpcSessionsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;

using TaskStatus = ArmoniK.Core.Common.Storage.TaskStatus;

namespace ArmoniK.Core.Common.gRPC.Services;

[Authorize(AuthenticationSchemes = Authenticator.SchemeName)]
Expand Down Expand Up @@ -516,36 +514,28 @@ public override async Task<ResumeSessionResponse> ResumeSession(ResumeSessionReq
catch (SessionNotFoundException e)
{
logger_.LogWarning(e,
"Error while getting session");
"Error while resuming session");
throw new RpcException(new Status(StatusCode.NotFound,
"Session not found"));
}
catch (InvalidSessionTransitionException e)
{
logger_.LogWarning(e,
"Error while cancelling session");
"Error while resuming session");
throw new RpcException(new Status(StatusCode.FailedPrecondition,
"Session is in a state that cannot be cancelled"));
}
catch (ArmoniKException e)
{
logger_.LogWarning(e,
"Error while getting session");
await taskTable_.UpdateManyTasks(data => data.SessionId == request.SessionId && data.Status == TaskStatus.Submitted,
new UpdateDefinition<TaskData>().Set(data => data.Status,
TaskStatus.Paused))
.ConfigureAwait(false);
"Error while resuming session");
throw new RpcException(new Status(StatusCode.Internal,
"Internal Armonik Exception, see application logs"));
}
catch (Exception e)
{
logger_.LogWarning(e,
"Error while getting session");
await taskTable_.UpdateManyTasks(data => data.SessionId == request.SessionId && data.Status == TaskStatus.Submitted,
new UpdateDefinition<TaskData>().Set(data => data.Status,
TaskStatus.Paused))
.ConfigureAwait(false);
"Error while resuming session");
throw new RpcException(new Status(StatusCode.Unknown,
"Unknown Exception, see application logs"));
}
Expand Down

0 comments on commit 2e55acc

Please sign in to comment.