Repository navigation
Expand file tree
/
Copy pathEngineResourceAccess.cs
More file actions
66 lines (60 loc) · 4.76 KB
/
Copy pathEngineResourceAccess.cs
File metadata and controls
66 lines (60 loc) · 4.76 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
using KeyLoad.Storage;
namespace KeyLoad.Core;
/// <summary>Executes EngineResourceAccess operations against the caller's database context.</summary>
public static class EngineResourceAccess
{
internal const int DatabaseEngineNoRetainedBytes = 0;
internal const string DatabaseEngineResourceIsNotConfiguredDetail = "The resource is not configured.";
internal const string DatabaseEngineResourceBelongsToADifferentTransactionDomainDetail = "The resource belongs to a different transaction domain.";
internal const string DatabaseEngineResourceHasADifferentKindDetail = "The resource has a different kind.";
internal const int DatabaseEngineMinimumPositiveCount = 1;
internal const int NoPersistedCopies = 0;
/// <summary>Reads a configured resource and checks its transaction domain and optional kind.</summary>
/// <param name = "view">Current gated storage view.</param>
/// <param name = "partition">Atomic partition containing the operation.</param>
/// <param name = "name">Resource identifier.</param>
/// <param name = "kind">Optional required resource kind.</param>
/// <returns>The persisted resource definition.</returns>
/// <param name = "engine">The shared database execution context.</param>
public static ResourceDefinition Resource(this DatabaseEngine engine, IKeyValueView view, PartitionRef partition, string name, ResourceKind? kind = null)
{
ArgumentNullException.ThrowIfNull(engine) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
ArgumentNullException.ThrowIfNull(view) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
ArgumentNullException.ThrowIfNull(partition) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
return ResourceDefinitionBinding.BindResourceDefinition(view, partition, name, kind);
}
/// <summary>Creates a commit token from the local storage identity in the command's existing execution view.</summary>
/// <param name = "view">The command's already-owned transaction or committed read view.</param>
/// <param name = "partition">Complete atomic partition identity.</param>
/// <param name = "position">Applied commit position.</param>
/// <returns>The token bound to the resolved storage incarnation.</returns>
/// <param name = "engine">The shared database execution context.</param>
internal static CommitToken Token(this DatabaseEngine engine, IKeyValueView view, PartitionRef partition, long position)
{
ArgumentNullException.ThrowIfNull(view) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
ArgumentNullException.ThrowIfNull(partition) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
var owner = engine.ReadPlacementWitness(view, partition);
return new(owner.Incarnation, partition.AtomicPartitionId, position);
}
internal static void ValidateCommitToken(this DatabaseEngine engine, IKeyValueView view, PartitionRef partition, CommitToken token, ErrorCode failureCode, string safeDetail)
{
ArgumentNullException.ThrowIfNull(view) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
ArgumentNullException.ThrowIfNull(partition) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
ArgumentNullException.ThrowIfNull(token) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
var owner = engine.ReadPlacementWitness(view, partition);
if (token.Incarnation != owner.Incarnation || token.AtomicPartitionId != partition.AtomicPartitionId || token.Position < DatabaseEngineMinimumPositiveCount)
{
throw Errors.Fail(failureCode, safeDetail);
}
}
/// <summary>Validates every component of an atomic partition identity.</summary>
/// <param name = "partition">Complete identity to validate.</param>
public static void ValidatePartition(PartitionRef partition)
{
ArgumentNullException.ThrowIfNull(partition) /* KLD0041: The BCL null guard accepts this existing reference through its object parameter without copying its contents. */;
JsonData.Identifier(partition.TenantId);
JsonData.Identifier(partition.DatabaseId);
JsonData.Identifier(partition.TransactionDomainId);
JsonData.Identifier(partition.PartitionKey);
}
}