Method CommitAsync
- Namespace
- MailFathom.Infrastructure.Persistence.Policies
- Assembly
- MailFathom.Infrastructure.dll
CommitAsync(Guid?, string, long, GovernedRecordsToJudge, CancellationToken)
Replaces the policy one scope holds, if it still stands at the expected version.
Task<SettingsPolicyCommit> CommitAsync(Guid? organizationId, string json, long expectedVersion, GovernedRecordsToJudge judged, CancellationToken cancellationToken)
Parameters
organizationIdGuid?The organization, or null for the deployment.
jsonstringThe candidate policy, as the JSON object the row will hold.
expectedVersionlongThe version the candidate was composed over, which is UnwrittenVersion for a scope that stored none.
judgedGovernedRecordsToJudgeWhich of the records the policy governs the write judges, and under what bounds.
cancellationTokenCancellationTokenCancels the commit.
Returns
- Task<SettingsPolicyCommit>
What the attempt did, carrying the version a commit produced.
Remarks
A policy somebody else moved and an organization removed underneath the write are one answer, for the reason a user's record gives the same one: the statement distinguishes neither and a caller settles both by reading again, which reports the version now in force or that there is no organization to write for. The attempt that commits second is the one refused, whichever replica each reached.
Where the candidate changes what a user's record is served on, the write judges every user record the policy
governs through IUserRecordPolicyJudge before it commits — every user of the organization, or
every user of the deployment for the deployment's own policy — and where it changes what a mail account is
served on, every mail account it governs through IMailAccountPolicyJudge. A record the candidate
would leave unservable refuses the whole write, so does a mail account whose effective settings a write under
a narrower grant may not move, and a governed set past the bound judged states refuses it
before any record is read. What passes commits together with the endpoint switches of every user whose
effective access it moved and the queryable settings of every mail account whose effective settings it moved,
so a request is admitted and a question about every account is answered by the policy on every replica,
including one that has not adopted it. No record's version moves.
The whole of it runs under the lock that excludes every write of a governed record, so a record written while the policy is being judged is either judged with it or judged against it afterwards, never missed by both.
Exceptions
- ArgumentException
Thrown when
jsonis null, empty, white space, not a JSON object, or past MaximumOctets as the database would store it.- ArgumentNullException
Thrown when
judgedis null.- ArgumentOutOfRangeException
Thrown when
expectedVersionis negative, or the boundjudgedstates is not positive.- SettingsPolicyUnreadableException
Thrown when a policy the write has to read is past MaximumOctets.