Repository navigation
Expand file tree
/
Copy pathEmbeddedCoordinator.cs
More file actions
52 lines (47 loc) · 3.4 KB
/
Copy pathEmbeddedCoordinator.cs
File metadata and controls
52 lines (47 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using ManagedCode.Communication;
using ManagedCode.Communication.Commands;
namespace KeyLoad.Core;
/// <summary>Coordinates direct embedded use of one real database engine.</summary>
/// <param name="database">Engine whose atomic store applies commands.</param>
public sealed class EmbeddedCoordinator(DatabaseEngine database) : ICommitCoordinator
{
/// <inheritdoc />
public Task<Result<TResult>> SubmitAsync<TResult>(OperationKind kind, Guid id, string principalId, string payloadJson,
CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
return ApplyAsync<TResult>(database.CreateCommand(kind, id, principalId, database.EvaluationClock.GetUtcNow(), payloadJson), cancellationToken);
}
/// <inheritdoc />
public Task<Result<TResult>> RuntimeSubmitAsync<TResult>(OperationKind kind, Guid id, string principalId,
object /* KLD0041: This native command admission receives the exact Kind-selected business input before storing it in the existing persisted envelope. */ input, ReadExecutionBudget? sourcePlanningBudget = null,
CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
sourcePlanningBudget?.Check();
var operation = sourcePlanningBudget is null
? database.CreateCommand(kind, id, principalId, database.EvaluationClock.GetUtcNow(), input) /* KLD0041: Command creation admits the exact Kind-selected input into the existing native persisted envelope without JSON conversion. */
: (database.CreateCommand(kind, id, principalId, database.EvaluationClock.GetUtcNow(), input, sourcePlanningBudget) /* KLD0041: Command creation admits the exact Kind-selected input into the existing native persisted envelope without JSON conversion. */);
return ApplyAsync<TResult>(operation, cancellationToken);
}
/// <inheritdoc />
public Task<Result<TResult>> SubmitVerifiedAsync<TResult>(Command<DatabaseCommand> operation, CancellationToken cancellationToken,
ReadExecutionBudget? sourcePlanningBudget = null)
{
cancellationToken.ThrowIfCancellationRequested();
sourcePlanningBudget?.Check();
return ApplyAsync<TResult>(database.OwnCommand(operation), cancellationToken);
}
/// <summary>Acknowledges the command after native process-persistent WAL publication.</summary>
private async Task<Result<TResult>> ApplyAsync<TResult>(Command<DatabaseCommand> operation, CancellationToken cancellationToken)
{
var /* KLD0041: The existing native stored-outcome schema carries different operation payload types; this step preserves that exact persisted result. */ result = (await database.ApplyCoreAsync(operation, null, selectEmbeddedClock: true, cancellationToken)).Result /* KLD0041: The existing native stored-outcome schema carries different operation payload types; this step preserves that exact persisted result. */;
return result.IsFailed ? Result<TResult>.Fail(result.Problem) : Result<TResult>.Succeed(result.Get<TResult>() /* KLD0041: The existing native stored-outcome schema carries different operation payload types; this step preserves that exact persisted result. */);
}
/// <inheritdoc />
public Task ReadBarrierAsync(CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
return Task.CompletedTask;
}
}