4

TransactionScope が複数のデータベース間でデータの整合性を保証する方法の原則を教えてもらえますか? 最初にコマンドをデータベースに送信し、データベースが応答するのを待ってから、以前に送信されたコマンドを適用するようにメッセージを送信すると思います。ただし、これらの適用メッセージを送信するときに実行が突然停止すると、コマンドを適用したデータベースと適用していないデータベースが発生する可能性があります。誰でもこれに光を当てることができますか?

編集:

私が求めているのは、停電や突然のシャットダウンの場合に複数のデータベースに書き込むときに、データの整合性を保証するために TransactionScope に頼ることができると思います。

ありがとう、バス

例:

    using(var scope=new TransactionScope())
    {
        using (var context = new FirstEntities())
        {
            context.AddToSomethingSet(new Something());
            context.SaveChanges();
        }

        using (var context = new SecondEntities())
        {
            context.AddToSomethingElseSet(new SomethingElse());
            context.SaveChanges();
        }

        scope.Complete();
    }
4

2 に答える 2

6

It promotes it to the Distributed Transaction Coordinator (msdtc) if it detects multiple databases which use each scope as a part of a 2-phase commit. Each scope votes to commit and hence we get the ACID properties but distributed accross databases. It can also be integrated with TxF, TxR. You should be able to use it the way you describe.

The two databases are consistent as the distributed COM+ transaction running under MTC have attached to them, database transactions.

If one database votes to commit (e.g. by doing a (:TransactionScope).Commit()), "it" tells the DTC that it votes to commit. When all databases have done this they have a change-list. As far as the database transactions don't deadlock or conflict with other transactions now (e.g. by means of a fairness algorithm that pre-empts one transaction) all operations for each database are in the transaction log. If the system loses power when not yet commit for one database has finished but it has for another, it has been recorded in the transaction log that all resources have voted to commit, so there is no logical implication that the commit should fail. Hence, next time the database that wasn't able to commit boots up, it will finish those transactions left in this indeterminate state.

于 2010-03-08T12:03:37.250 に答える
2

分散トランザクションでは、実際にデータベースの一貫性が失われる可能性があります。あなたが言った:

ある時点で、両方のデータベースに変更を適用するように指示する必要があります。最初のデータベースに適用するように指示した後、停電が発生したとしましょう。その後、データベースが同期しなくなります。それとも私は何かが足りないのですか?

あなたは違います。これは将軍問題として知られていると思います。それはおそらく防ぐことはできません。ただし、失敗のウィンドウは非常に小さいです。

于 2010-03-08T15:03:18.327 に答える