Repository navigation
Expand file tree
/
Copy pathDatabaseEngine.cs
More file actions
108 lines (99 loc) · 7.82 KB
/
Copy pathDatabaseEngine.cs
File metadata and controls
108 lines (99 loc) · 7.82 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using KeyLoad.Core.Authorization;
using KeyLoad.Core.ResourceExecution;
using KeyLoad.Core.RuntimeJournaling.Contracts;
using KeyLoad.Storage;
using Microsoft.Extensions.Options;
namespace KeyLoad.Core;
/// <summary>Owns the shared database execution context, policy snapshots and node-local read admission.</summary>
public sealed class DatabaseEngine
{
internal MessagingExecutionOptions MessagingExecution => messagingExecution;
internal EventSourceExecutionOptions EventSourceExecution => eventSourceExecution;
internal TimeSeriesExecutionOptions TimeSeriesExecution => timeSeriesExecution;
internal ChangeFeedExecutionOptions ChangeFeedExecution => changeFeedExecution;
internal bool visibilityConfigured;
internal RowVisibilityCache? RowVisibility { get; set; }
/// <summary>Creates a node-owned engine with centrally validated operation policy snapshots.</summary>
/// <param name = "store">The externally owned node-local atomic store.</param>
/// <param name = "authorization">Evaluator for persisted operation, row and field policy.</param>
/// <param name = "limits">Centrally validated optional queue transfer attempt policies.</param>
/// <param name = "dueWorkOptions">Centrally validated node-local due discovery policy.</param>
/// <param name = "eventSourceOptions">Centrally validated event continuation policy.</param>
/// <param name = "messagingOptions">Centrally validated topic, catch-up and retry work limits.</param>
/// <param name = "graphOptions">Centrally validated shared graph traversal limits.</param>
/// <param name = "changeFeedOptions">Centrally validated change cursor and projection policy.</param>
/// <param name = "claimsOptions">Centrally validated execution signed-claim decoding limits.</param>
/// <param name = "timeSeriesOptions">Centrally validated time-series append admission.</param>
/// <param name = "timeProvider">Optional business clock; hosting runtime time is unaffected.</param>
public DatabaseEngine(IAtomicStore store, IAuthorizationPolicy authorization, IOptions<DatabaseLimits> limits, IOptions<DueWorkExecutionOptions> dueWorkOptions, IOptions<EventSourceExecutionOptions> eventSourceOptions, IOptions<MessagingExecutionOptions> messagingOptions, IOptions<GraphExecutionOptions> graphOptions, IOptions<ChangeFeedExecutionOptions> changeFeedOptions, IOptions<ClaimsExecutionOptions> claimsOptions, IOptions<TimeSeriesExecutionOptions> timeSeriesOptions, TimeProvider? timeProvider = null)
{
ArgumentNullException.ThrowIfNull(store) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
ArgumentNullException.ThrowIfNull(authorization) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
ArgumentNullException.ThrowIfNull(limits) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
ArgumentNullException.ThrowIfNull(dueWorkOptions) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
ArgumentNullException.ThrowIfNull(eventSourceOptions) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
ArgumentNullException.ThrowIfNull(messagingOptions) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
messagingExecution = messagingOptions.Value;
messagingExecution.Validate();
ArgumentNullException.ThrowIfNull(graphOptions) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
graphExecution = graphOptions.Value;
graphExecution.Validate();
ArgumentNullException.ThrowIfNull(changeFeedOptions) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
changeFeedExecution = changeFeedOptions.Value;
changeFeedExecution.Validate();
ArgumentNullException.ThrowIfNull(claimsOptions) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
ClaimsExecution = claimsOptions.Value;
ClaimsExecution.Validate();
ArgumentNullException.ThrowIfNull(timeSeriesOptions) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
TimeSeriesOptions = timeSeriesOptions;
timeSeriesExecution = timeSeriesOptions.Value;
timeSeriesExecution.Validate();
GraphOptions = graphOptions;
var operationLimits = limits.Value;
dueExecution = dueWorkOptions.Value;
eventSourceExecution = eventSourceOptions.Value;
operationLimits.Validate();
dueExecution.Validate();
eventSourceExecution.Validate();
Store = store;
Authorization = authorization;
Limits = operationLimits;
analyticalReadGate = new();
DueDiscoveryDeadline = dueExecution.DiscoveryDeadline;
eventSourceCursorLifetime = eventSourceExecution.CursorLifetime;
Clock = timeProvider ?? TimeProvider.System;
Durability = store.Identity.Durability;
}
private readonly ChangeFeedExecutionOptions changeFeedExecution;
internal ClaimsExecutionOptions ClaimsExecution { get; }
private readonly TimeSeriesExecutionOptions timeSeriesExecution;
internal IOptions<TimeSeriesExecutionOptions> TimeSeriesOptions { get; }
private readonly EventSourceExecutionOptions eventSourceExecution;
private readonly DueWorkExecutionOptions dueExecution;
internal DueWorkExecutionOptions DueExecution => dueExecution;
private readonly MessagingExecutionOptions messagingExecution;
private readonly GraphExecutionOptions graphExecution;
internal IOptions<GraphExecutionOptions> GraphOptions { get; }
internal GraphExecutionOptions GraphExecution => graphExecution;
internal readonly TimeSpan eventSourceCursorLifetime;
internal TimeProvider Clock { get; }
internal TimeSpan DueDiscoveryDeadline { get; }
/// <summary>Gets the borrowed business clock for consistent persisted read authority.</summary>
public TimeProvider EvaluationClock => Clock;
/// <summary>Gets the externally owned atomic store used by this engine.</summary>
public IAtomicStore Store { get; }
/// <summary>Gets the evaluator for persisted authorization policy.</summary>
public IAuthorizationPolicy Authorization { get; }
/// <summary>Gets the configured optional queue transfer attempt policies.</summary>
public DatabaseLimits Limits { get; }
/// <summary>Gets or sets the acknowledgement durability reported in commit receipts.</summary>
public DurabilityProfile Durability { get; set; }
internal int AcknowledgedPersistedCopies => Durability == DurabilityProfile.Buffered ? EngineResourceAccess.NoPersistedCopies : CommitReceipt.LocalCopyCount;
/// <summary>Gets the number of applied canonical commands across independent partition sequences.</summary>
public long LastApplied => Store.Read(view => StorageReplicaExecution.ReadPartitionPositions(view).Sum(cut => cut.Position));
internal readonly AnalyticalReadGate analyticalReadGate;
/// <summary>Gets the number of currently admitted analytical operations on this engine.</summary>
public int QueryReadsInFlight => analyticalReadGate.InFlight;
internal RuntimeJournalOperations? configuredRuntimeJournal;
internal RuntimeJournalOperations RuntimeJournal => Volatile.Read(ref configuredRuntimeJournal) ?? throw Errors.Fail(ErrorCode.RecoveryRequired, RuntimeJournalProtocol.NotConfigured);
}