nested transactions nested transactions
play

Nested Transactions Nested Transactions Flat transactions The - PowerPoint PPT Presentation

Nested Transactions Nested Transactions Flat transactions The rules for committing of nested transactions Nested Transactions A transaction commits or aborts only after its child transactions have completed; Structured in


  1. Nested Transactions Nested Transactions � Flat transactions � The rules for committing of nested transactions � Nested Transactions � A transaction commits or aborts only after its child transactions have completed; � Structured in an invert-root tree � When a sub-transaction completes, it makes an � The outermost transaction is the top-level transaction . independent decision on provisionally commit or abort. Others are sub-transactions . Its decision to abort is final. � a sub-transaction is atomic to its parent transaction � When a parent aborts, all of its sub-transactions are � Sub-transactions at the same level can run concurrently aborted, even though some of them may have � Each sub-transaction can fail independently of its parent provisionally committed. and of the other sub-transactions. When a sub-transaction aborts, the parent can decide � � Main advantages of nested transactions whether to abort or not. � When the top-level transaction commits, then all of the � Additional concurrency in a transaction : Sub- sub-transactions that have provisionally committed can transactions at one level may run concurrently with other commit. sub-transactions at the same level in the hierarchy. T : top-level transaction Transaction T: T1= openSubTransaction T2 = openSubTransaction a.withdraw(100); commit T1: T2 : b.deposit(100); openSubTransaction openSubTransaction openSubTransaction c.withdraw(200); prov. commit abort T21: T11: T12: d.deposit(200); openSubTransaction prov. commit prov. commit prov. commit � More robust : Sub-transactions can commit or abort T211: independently. prov.commit • For example, a transaction to deliver a mail message to a list of recipients. 1 2 1

  2. The coordinator of a distributed Distributed Transactions transaction � In general case, a transaction accesses objects � a client starts a transaction by sending an managed by multiple servers. openTransaction request to a coordinator of any server. � invokes operations in several different servers � transaction ID must be unique within the distributed � Atomic property of a distributed transaction system. � To achieve it, one server takes the coordinator position, � A simple way: TID � <server ID, a number unique to the to ensure the same outcome at all the servers; server> � All the servers involved in a distributed transaction are � the coordinator that opened the transaction becomes the called participant . coordinator of the distributed transaction, all the servers � “ two-phase commit protocol ”: communicate with each involved are participants. other to reach a joint decision about commit or abort. � During the progress of the transaction, the � Distributed transactions need to be serialized coordinator records a list of references to the globally, with local concurrency control . participants, and each participant records a � Distributed deadlock : a cycle in the global wait- reference to the coordinator. for graph Join(Trans, reference to participant) � Centralized algorithm � Distributed algorithm Informs a coordinator that a new participant has joined � Transaction recovery is used to ensure that all the the transaction Trans. objects involved in transactions are recoverable. 3 4 2

  3. Atomic commit protocols Two-phase commit protocol � One-phase atomic commit protocol � When participants join a transaction, they will inform the coordinator. No communication during � the coordinator to communicate the commit or abort request to all the participants, and to keep on repeating the the progress of the transaction. request until all the participants have acknowledged. � A client’s request to commit (or abort) a transaction � Problem : when the client requests a commit, it doesn’t is directed to the coordinator. allow a server to make a decision to abort a transaction. � When client requests “abortTransaction”, or one � Using concurrency control technique, it’s possible for a participant is aborted, the coordinator informs the server to abort a transaction (i.e. deadlock). participants immediately. � Two-phase commit protocol � The two-phase commit protocol is used when the � allow any participant to abort its part of a transaction client asks the coordinator to commit the � And if one part of a transaction is aborted, then the whole transaction must be aborted. transaction. � General idea � In the first phase, each participant votes for the � In the first phase, the coordinator asks all the transaction to be committed or aborted participants if they are prepared to commit; • Once a participant has voted to commit a transaction, it is not allowed to abort it. It is in a prepared state � In the second phase, it tells them to commit (or � In the second phase of the protocol, every participant in abort) the transaction. the transaction performs the joint decision. � The problem is to ensure that all the participants vote and ensure that they all reach the same decision, with server failures, lost messages. 5 6 3

  4. Failures in two-phase commit Two-phase commit protocol for protocol nested transactions � Server failure � Each sub-transaction starts after its parent and finishes before it. � each server saves information about two-phase commit protocol in its permanent storage. � When a sub-transaction completes, it makes an � Communication failure independent decision about commit provisionally � There are several stages, where the coordinator or a or abort. participant cannot progress until it receives another � Difference between provisional commit and request or reply message from others. prepared to commit � Timeouts : to avoid process blocking, caused by waiting � Provisional commit: it’s not saved on permanent storage; for reply, request messages. It only means it has finished correctly and will agree to � For example, after a participant has voted “Yes”, it will commit when it is asked to. wait for the coordinator to report the vote result. � Prepared commit: guarantees a sub-transaction will be • send a “getDecision” request to the coordinator to able to commit determine the result. � After all sub-transactions are completed, the • Problem: coordinator failure � wait for a long time provisionally committed sub-transactions • Fix: obtain the vote result by contact other participate in a two-phase commit protocol. participants instead of only contacting the coordinator. � When a top-level transaction completes, its coordinator � 2nd example: a participant hasn’t received a performs a two-phase commit protocol. “canCommit?” call from the coordinator after it has done � Sub-transaction ID is an extension of its parent’s all the client requests in the transaction. ID • Detect by no request from a particular transaction for a � Get IDs of all its ancesters. while. Abort. � Another example: coordinator waiting for votes from the 7 8 participants. Abort the transaction after a timeout. 4

  5. Two-phase commit protocol for Hierarchy two-phase commit protocol nested transactions � the coordinator of a parent transaction has a list of � The coordinator of the top-level transaction its child sub-transactions. communicates with the coordinators of its child sub-transactions, … … � When a sub-transaction provisionally commits, it � “canCommit” call reports its status and the status of its descendants to its parent. � the second argument is the TID of the participant making the “canCommit?” call. � When a sub-transaction aborts, it just reports abort � When the participant receives the call, it will look to its parent its transaction list for any provisionally committed � The client completes a set of nested transctions by transaction that matches the TID in the second invoking “closeTransaction” or “abortTransaction” argument. operation on the coordinator of the top-level � The coordinator of T 12 , T 21 . transaction (coordinator of this set of nested trans.). � If a participant finds any sub-transactions, it � Participants: the coordinators of all the sub- prepares the objects and replies with a Yes vote. transactions in the tree that have provisionally � If it fails to find any, then it replies with a No vote. committed but do not have aborted ancestors � Each participant collects the replies from its � The two-phase commit protocol may be performed descendants before replying to its parent. in a hierarchy manner or in a flat manner. 9 1 0 5

Recommend


More recommend