FulcrumFS FulcrumFS
FulcrumFS FulcrumFS
DocFX + Singulink = ♥

Search Results for

    Method DisposeAsync

    DisposeAsync()

    Disposes the transaction. A transaction that was neither committed nor rolled back is not rolled back: the files it added and the deletions it staged are left indeterminate for the cleaner to resolve.

    Declaration
    public ValueTask DisposeAsync()
    Returns
    Type Description
    ValueTask
    Implements
    IAsyncDisposable.DisposeAsync()
    Remarks

    A transaction is disposed without having been committed when something failed before its commit, and it cannot know whether that was before or after the application's database committed: a database commit that has taken effect on the server still throws if, for example, the connection is lost before the answer arrives. Rolling back then would delete files that a committed row references and discard the record of deletions that the database has committed. So disposal only releases what the transaction holds, which is exactly the state that a process which ended at this point leaves:

    • Each file the transaction added keeps its indeterminate marker, which nobody holds any more.
    • If the transaction was staged, its staged journal stays in place with nobody holding it. On a version 1 repository, which has no journals, each deleted file keeps its indeterminate marker instead.
    • If the transaction was not staged, its deletions exist only in memory: nothing was recorded for them, so nothing happens to those files and they are not indeterminate. The application cannot have committed its database in the order the transaction requires, since staging comes first.

    The files stay readable, EnumerateFilesAsync(CancellationToken) reports the added files and the files whose deletion was staged as indeterminate, and the next cleanup pass that is given a resolution callback (see CleanAsync(TimeSpan, Func<FileId, Task<IndeterminateResolution>>?, CancellationToken)) asks it about each of them: it keeps the files the database references and deletes the others. A pass without a callback leaves them as they are, so a repository that is never cleaned with a callback keeps the files of every transaction that was disposed this way.

    An application that knows that its database did not commit calls RollbackAsync(CancellationToken) before the transaction is disposed, which discards the added files, the recorded deletions and the journal at once. Disposing a transaction that has been committed or rolled back, or that added and deleted nothing, does nothing.

    If CommitAsync(CancellationToken) started the commit and failed, the files are left for the cleaner in the same way, which resolves them through the resolution callback, or deletes the files the journal lists without asking if the journal had already been renamed to committed when the commit failed.

    Disposal waits for a call on the transaction that is still running. It does not throw and reports nothing through TransactionCompletionFailed, and it needs no access to the repository.

    © Singulink. All rights reserved.