Method CommitAsync
CommitAsync(CancellationToken)
Commits the transaction, making all file additions and deletion made during the transaction permanent in the repository.
Declaration
public Task CommitAsync(CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | A cancellation token that cancels the call while it waits for another call on this transaction to finish. Once the commit has started it is not observed. |
Returns
| Type | Description |
|---|---|
| Task |
Implements
Remarks
In the deferred delete modes the deletions are recorded for the cleaner: a transaction that deletes two or more files records them in one delete journal, flushed to disk once for all of them, on a repository whose FormatVersion is 2 or later, and otherwise each deleted file gets a delete marker of its own. In Immediate mode the files are deleted now; one that cannot be deleted at once gets a delete marker, and a cleanup pass deletes it.
A failure to commit an individual file, or to write the journal, is not thrown: it is reported through TransactionCompletionFailed. If the journal cannot be written, each deletion is recorded with its own delete marker instead. A file whose commit failed stays accessible in an indeterminate state for the next cleanup pass to resolve.
Once the journal is written, the deletions it records are committed, and nothing that goes wrong with them afterwards is reported. All that is left is to remove each file's indeterminate marker, and a marker that cannot be removed, whatever the reason, is removed by the cleaner, which deletes the files the journal lists without asking.
If the repository cannot be accessed, for example because its volume has stopped answering, the commit waits for it for up to MaxAccessWaitOrRetryTime once for all of its files, not once for each, counting only the time it waits. Once that time is used up, each further file is attempted once without waiting, and one that cannot be committed is reported and left for the cleaner as above; a deletion that the journal has recorded is committed, and is not reported.
An indeterminate marker that cannot be removed because something else has it open is tolerated, not reported: removing the marker is what commits an added file, the file is accessible either way, and it stays indeterminate until the next cleanup pass resolves it and removes the marker. The attempt is logged to the marker (see MarkerFileLogging).
The files are committed one by one, so the transaction has no single point at which it commits, and once the commit has started the method throws in two cases only: a TransactionCompletionFailed handler threw, which happens after every file has been attempted, or the repository has been disposed, which leaves the files not yet committed indeterminate. Neither means that the transaction was rolled back, and disposing it afterwards rolls nothing back. An OperationCanceledException is thrown before the commit has started: nothing has been committed and the transaction is still open. It can be committed again; disposing it instead does not roll it back but leaves its files indeterminate for the cleaner to resolve (see DisposeAsync()). Pass None once the application's database has committed, so that a cancellation does not leave to the cleaner what the commit would have finished.
Exceptions
| Type | Condition |
|---|---|
| OperationCanceledException | The token was cancelled before the commit had started. Nothing has been committed. |
| ObjectDisposedException | The transaction has been disposed: nothing is committed, and a transaction that was disposed without having been committed or rolled back left its files indeterminate when it was disposed. Or the repository has been disposed: the files that had not been committed yet are left indeterminate. |