5-Transaction Processing Nhom2
5-Transaction Processing Nhom2
Systems
TS. Phan Thị Hà
Begin_transaction
…
Read
Read
…
Write
Read
…
Commit
◼ Read set (RS)
❑ The set of data items that are read by a transaction
◼ Write set (WS)
❑ The set of data items whose values are changed by this transaction
◼ Base set (BS)
❑ RS WS
ATOMICITY
❑ all or nothing
CONSISTENCY
❑ no violation of integrity constraints
ISOLATION
❑ concurrent changes invisible serializable
DURABILITY
❑ committed updates persist
◼ Pessimistic
❑ Two-Phase Locking-based (2PL)
◼ Centralized (primary site) 2PL
◼ Primary copy 2PL
◼ Distributed 2PL
❑ Timestamp Ordering (TO)
◼ Basic TO
◼ Multiversion TO
◼ Conservative TO
◼ Optimistic
❑ Locking-based
❑ Timestamp ordering-based
Ti Tj
Local WFG
Global WFG
Basic T/O:
for Ri(x) for Wi(x)
if ts(Ti) < wts(x) if ts(Ti) < rts(x) and ts(Ti) < wts(x)
then reject Ri(x) then reject Wi(x)
else accept Ri(x) else accept Wi(x)
rts(x) ts(Ti) wts(x) ts(Ti)
© 2020, M.T. Özsu & P. Valduriez TS.
24
Phan Thị Hà
Basic Timestamp Ordering
if ts(Ti) < wts(x) if ts(Ti) < rts(x) and ts(Ti) < wts(x)
then reject Ri(x) then reject Wi(x)
else accept Ri(x) else accept Wi(x)
rts(x) ts(Ti) wts(x) ts(Ti)
Pessimistic execution
Optimistic execution
Check if first 2
Conditions hold
Positive Yes
Any ?
neg? Update event clock:
No max(own,coord TM)
If global commit:
1) Persist 𝑇𝑖 updates
2) Update event clock
© 2020, M.T. Özsu & P. Valduriez TS.
37
Phan Thị Hà
Outline
◼ Distributed Transaction Processing
❑
❑ Distributed Reliability
Problem:
How to maintain
atomicity
durability
properties of transactions
◼ Transaction failures
❑ Transaction aborts (unilaterally or due to deadlock)
◼ System (site) failures
❑ Failure of processor, main memory, power supply, …
❑ Main memory contents are lost, but secondary storage contents
are safe
❑ Partial vs. total failure
◼ Media failures
❑ Failure of secondary storage devices → stored data is lost
❑ Head crash/controller failure
◼ Communication failures
❑ Lost/undeliverable messages
❑ Network partitioning
© 2020, M.T. Özsu & P. Valduriez TS.
40
Phan Thị Hà
Distributed Reliability Protocols
◼ Commit protocols
❑ How to execute commit command for distributed transactions.
❑ Issue: how to ensure atomicity and durability?
◼ Termination protocols
❑ If a failure occurs, how can the remaining operational sites deal with it.
❑ Non-blocking: the occurrence of failures should not force the sites to
wait until the failure is repaired to terminate the transaction.
◼ Recovery protocols
❑ When a failure occurs, how do the sites where the failure occurred deal
with it.
❑ Independent: a failed site can determine the outcome of a transaction
without having to obtain remote information.
◼ Independent recovery non-blocking termination
Coordinator Participant
COMMIT
To improve performance by
1) Reduce the number of messages between coordinator &
participants
2) Reduce the number of time logs are written
◼ Presumed Abort 2PC
❑ Participant polls coordinator about transaction’s outcome
❑ No information → abort the transaction
◼ Presumed Commit 2PC
❑ Participant polls coordinator about transaction’s outcome
❑ No information → assume transaction is committed
❑ Not an exact dual of presumed abort 2PC
Coordinator
◼ Timeout in INITIAL
❑ Who cares
◼ Timeout in WAIT
❑ Cannot unilaterally commit
❑ Can unilaterally abort
◼ Timeout in ABORT or COMMIT
❑ Stay blocked and wait for the acks
Participant
◼ Timeout in INITIAL
❑ Coordinator must have failed
in INITIAL state
❑ Unilaterally abort
◼ Timeout in READY
❑ Stay blocked
Coordinator
◼ Failure in INITIAL
❑ Start the commit process upon
recovery
◼ Failure in WAIT
❑ Restart the commit process upon
recovery
◼ Failure in ABORT or COMMIT
❑ Nothing special if all the acks have
been received
❑ Otherwise the termination protocol is
involved
Participant
◼ Failure in INITIAL
❑ Unilaterally abort upon recovery
◼ Failure in READY
❑ The coordinator has been
informed about the local decision
❑ Treat as timeout in READY state
and invoke the termination
protocol
◼ Failure in ABORT or COMMIT
❑ Nothing special needs to be done
◼ Blocking
❑ Ready implies that the participant waits for the coordinator
❑ If coordinator fails, site is blocked until recovery
❑ Blocking reduces availability
◼ Independent recovery is not possible
◼ However, it is known that:
❑ Independent recovery protocols exist only for single site failures;
no independent recovery protocol exists which is resilient to
multiple-site failures.
◼ So we search for these protocols – 3PC
◼ 3PC is non-blocking.
◼ A commit protocols is non-blocking iff
❑ it is synchronous within one state transition, and
❑ its state transition diagram contains
◼ no state which is “adjacent” to both a commit and an abort state,
and
◼ no non-committable state which is “adjacent” to a commit state
◼ Adjacent: possible to go from one stat to another with a
single state transition
◼ Committable: all sites have voted to commit a
transaction
❑ e.g.: COMMIT state
© 2020, M.T. Özsu & P. Valduriez TS.
56
Phan Thị Hà
State Transitions in 3PC
Coordinator Participant
◼ Simple partitioning
❑ Only two partitions
◼ Multiple partitioning
❑ More than two partitions
◼ Formal bounds:
❑ There exists no non-blocking protocol that is resilient to a
network partition if messages are lost when partition occurs.
❑ There exist non-blocking protocols which are resilient to a single
network partition if all undeliverable messages are returned to
sender.
❑ There exists no non-blocking protocol which is resilient to a
multiple partition.
Ignore and
Wait
if all are Ack (not with bal’,val’)
then val ← proposer wants &
nbal ← bal
No
else val ← val’ & nbal ← bal nbal = ack.bal? Ignore
Yes
Record
accepted(nbal,val)