Sei sulla pagina 1di 16

DISTRIBUTED TRANSACTION MANAGEMENT & RECOVERY

S.SANTHI PRIYA

Properties of Transactions
Atomicity - Either all or none of the transactions operations are performed.
Reasons why a transaction is not completed : transaction aborts - Transaction recovery

system crashes - crash recovery

Durability - Once the transaction has committed, the system must guarantee that
the results of its operations will never be lost, independent of subsequent failures.

database recovery

Serializability - If several transactions are executed concurrently, the result must be


the same as if they were executed serially in same order. concurrency control

Isolation - An incomplete transaction cannot revel its results to other transactions


before its commitment.

Cascading aborts

Distributed Transactions
There exists a root agent which starts the whole transaction, so that when the user request the execution of an application, the root agent is started; the site of the root agent is called the site of origin of the transaction.

The root agent has the responsibility of issuing the begin_transaction, commit and abort primitives. Only the root agent can request the creation of new agent.
Example bank transactions

fund transfer at global level

Read( terminal, $AMOUNT, $FROM_ACC), $TO_ACC); Begin _transaction; select AMOUNT into $FROM_AMOUNT from ACCOUNT where ACCOUNT_NUMBER=$FROM_ACC; If $FROM_AMOUNT-$AMOUNT<0 then abort else begin Update ACCOUNT set AMOUNT=AMOUNT-$AMOUNT where ACCOUNT=$FROM_ACC; Update ACCOUNT set AMOUNT=AMOUNT+$AMOUNT where ACCOUNT=$TO_ACC; Commit; end

fund transfer constituted by two agents


ROOT- AGENT Read( terminal, $AMOUNT, $FROM_ACC, $TO_ACC); Begin _transaction; select AMOUNT into $FROM_AMOUNT from ACCOUNT where ACCOUNT_Number=$FROM_ACC; If $FROM_AMOUNT-$AMOUNT<0 then abort else begin Update ACCOUNT set AMOUNT=AMOUNT-$AMOUNT where ACCOUNT=$FROM_ACC; Create AGENT1; SEND TO AGENT1($AMOUNT,$TO_ACC); Commit End

AGENT1
Receive from ROOT_AGENT($AMOUNT,$TO_ACC); Update ACCOUNT set AMOUNT=AMOUNT+$AMOUNT where ACCOUNT=$TO_ACC;

SUPPORTING ATOMICITY OF DISTRIBUTED TRANSACTIONS

LTM Local Transaction Manager Failures Site failures


log contains information for undoing or redoing all actions which are performed by transactions

Recovery Procedures
reads the log file

Communication failures
Messages between sites lost/incorrect
Recovery Procedures Ensuring atomicity Concurrency control

Reference model for distributed transaction recovery


Messages ROOT Trans AGENT AGENT Messages AGENT Distributed Transaction

2 DTMAGENT DTM AGENT DTM AGENT

Messages

Messages

DTM

1 LTM at site 1 LTM at site j LTM at site k

LTM

Interface 1: local_begin, local_commit,Local_abort,Local_create Interface 2: begin, commit,abort,create

2 phase commit protocol


Phase 1 coordinator Write prepare record in the log Send PREPARE message and activate timeout participant Wait for PREPARE message; If the participant is willing to commit then begin write subtransactions records in the log; write ready record in the log; send READY answer message to coordinator end else begin write abort record in the log; send ABORT answer message to cordinator end

Phase 2 Coordinator Wait for ANSWER message from all participants or timeout; If timeout expired or some answer message is ABORT then begin write global-abort record in the log Send ABORT command message to all participants

end
else begin write global-commit record in the log

Send COMMIT command message to all participants


end

Participant

wait for command message;


write abort or commit record in the log; Send the ACK message to the coordinator

Execute command
Coordinator

Wait for ACK messages from all participnats;


Writecomplete record in the log

Site failures
A participant fails before having written the ready record in the log. Timeout expires A participant fails after having written the ready record in the log

Asks the coordinator or other participants to know the outcome


The coordinator fails after having written the prepare record in the log, but before having written a global_commit or global_abort

Wait for the recovery of the coordinator


The coordinator fails after having written a global_commit or global_abort record in the log Coordinator sends the decission once again The coordinator fails after having written the complete record in the log No action required

Lost Messages
An answer message from participant is Lost Timeout

A prepare message is Lost


Waiting state A command message is Lost

Waiting state participant remains uncertain


An ACK message is lost coordinator remains uncertain

Concurrency control
A transaction locks a data item in shared mode if it wants only to read the data item and in exclusive mode if it wants to write the data item. Compatibility rules

A transaction can lock a data item in shared mode if it is not locked at all or it is locked in shared mode by another transaction.
A transaction can lock a data item in exclusive mode only if it is not locked at all. Concurrent execution of transactions is correct provided that the following rules are observed: Transactions are well formed

Compatibility rules for locking are observed


Each transaction does not request new locks after it has released a lock

Reference model for distributed Concurrency control


Messages AGENT ROOT Trans AGENT Messages AGENT Distributed Transaction

2 DTMAGENT DTM AGENT DTM AGENT

Messages

Messages

DTM

1 LTM at site 1 LTM at site j LTM at site k

LTM

Interface 1: local_lock_shared, local_lock_exclusive,Local_unlock Interface 2:Lock_sshared,:ock exclusive,Unlock

2 phase locking
First phase during which new locks are acquired (growing phase) and a second phase during which new locks are released (Shrinking Phase)

Potrebbero piacerti anche