ITransaction インターフェイス

定義

1 つの論理作業単位として実行される一連の操作。

public interface ITransaction : IDisposable
type ITransaction = interface
    interface IDisposable
Public Interface ITransaction
Implements IDisposable
実装

注釈

トランザクションは、次の ACID プロパティを示す必要があります。 (参照: https://technet.microsoft.com/en-us/library/ms190612)

  • アトミック性 - トランザクションはアトミック作業単位である必要があります。すべてのデータ変更が実行されるか、実行されません。
  • 整合性 - 完了すると、トランザクションはすべてのデータを一貫した状態にしておく必要があります。 すべての内部データ構造は、トランザクション終了時に正しくなければなりません。
  • 分離 - 同時実行トランザクションによって行われた変更は、他の同時実行トランザクションによって行われた変更から分離する必要があります。 内 ITransaction の操作に使用される分離レベルは、操作の IReliableState 実行によって決まります。
  • 持続性 - トランザクションが完了すると、その効果はシステム内に永続的に配置されます。 システム障害が発生しても、変更結果は持続されます。

この型のインスタンス メンバーは、スレッド セーフであるとは限りません。 これにより、トランザクションはコンカレンシーの単位になります。ユーザーは、特定の時点で複数のトランザクションを実行中にすることができますが、特定のトランザクションでは各 API を一度に 1 つずつ呼び出す必要があります。 トランザクションを受け入れてタスクを返す API はすべて IReliableCollection{T} 、一度に 1 つずつ待機する必要があります。

正しい使用方法の例を次に示します。


while (true)
{
    cancellationToken.ThrowIfCancellationRequested();

    try
    {
        using (var tx = this.StateManager.CreateTransaction())
        {
            await concurrentQueue.EnqueueAsync(tx, 12L, cancellationToken);
            await tx.CommitAsync();

            return;
        }
    }
    catch (TransactionFaultedException e)
    {
        // This indicates that the transaction was internally faulted by the system. One possible cause for this is that the transaction was long running
        // and blocked a checkpoint. Increasing the "ReliableStateManagerReplicatorSettings.CheckpointThresholdInMB" will help reduce the chances of running into this exception
        Console.WriteLine("Transaction was internally faulted, retrying the transaction: " + e);
    }
    catch (FabricNotPrimaryException e)
    {
        // Gracefully exit RunAsync as the new primary should have RunAsync invoked on it and continue work.
        // If instead enqueue was being executed as part of a client request, the client would be signaled to re-resolve.
        Console.WriteLine("Replica is not primary, exiting RunAsync: " + e);
        return;
    }
    catch (FabricNotReadableException e)
    {
        // Retry until the queue is readable or a different exception is thrown.
        Console.WriteLine("Queue is not readable, retrying the transaction: " + e);
    }
    catch (FabricObjectClosedException e)
    {
        // Gracefully exit RunAsync as this is happening due to replica close.
        // If instead enqueue was being executed as part of a client request, the client would be signaled to re-resolve.
        Console.WriteLine("Replica is closing, exiting RunAsync: " + e);
        return;
    }
    catch (TimeoutException e)
    {
        Console.WriteLine("Encountered TimeoutException during EnqueueAsync, retrying the transaction: " + e);
    }

    // Delay and retry.
    await Task.Delay(TimeSpan.FromMilliseconds(100), cancellationToken);
}

未定義の動作を持つ不適切な使用法の例を次に示します。

using (var txn = this.StateManager.CreateTransaction())
{
    List<Task> taskList = new List<Task>();
    taskList.Add(concurrentQueue.DequeueAsync(txn, cancellationToken));
    taskList.Add(concurrentQueue.DequeueAsync(txn, cancellationToken));

    await Task.WhenAll(taskList);
    await txn.CommitAsync();
}

プロパティ

CommitSequenceNumber

コミット操作のシーケンス番号。

TransactionId

トランザクションを識別する値を取得します。

メソッド

Abort()

トランザクションを中止 (ロールバック) します。

CommitAsync()

トランザクションをコミットします。

GetVisibilitySequenceNumberAsync()

可視性シーケンス番号を取得します。

適用対象