• No results found

Seminar 12

N/A
N/A
Protected

Academic year: 2021

Share "Seminar 12"

Copied!
16
0
0

Loading.... (view fulltext now)

Full text

(1)

DISTRIBUTED TRANSACTION

DISTRIBUTED TRANSACTION

MANAGEMENT & RECOVERY

MANAGEMENT & RECOVERY

S.SANTHI PRIYA

S.SANTHI PRIYA

(2)

Properties of Transactions

•  Atomicity - Either all or none of the transaction’s 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.

(3)

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.

(4)

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

(5)

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

(6)

 AGENT1

Receive from ROOT_AGENT($AMOUNT,$TO_ACC); Update ACCOUNT

set AMOUNT=AMOUNT+$AMOUNT where ACCOUNT=$TO_ACC;

(7)

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

(8)

Reference model for distributed

transaction recovery

Messages Messages Distributed

Trans Transaction 2 Messages Messages DTM 1 LTM LTM at site 1 LTM at site j AGENT AGENT ROOT AGENT DTM-AGENT DTM –  AGENT DTM –  AGENT LTM at site k 

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

(9)

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

(10)

• 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

(11)

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;

(12)

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

(13)

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

(14)

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

(15)

Reference model for distributed

Concurrency control

Messages Messages Distributed Trans Transaction 2 Messages Messages DTM 1 LTM LTM at site 1 LTM at site j AGENT AGENT ROOT AGENT DTM-AGENT DTM –  AGENT DTM –  AGENT LTM at site k 

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

(16)

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)

References

Related documents