Docsity

Problem Statement - E-Commerce - Lecture Slides, Slides of Fundamentals of E-Commerce

Toggle sidebar
bg1
1
2/2/05 1
7. Two Phase Commit
Transaction Proc essing
for E-Com merce
2
/
2
/
05 2
Outline
1. Introduction
2. The Tw o-P hase Com mit (2P C ) Protocol
3. 2P C Failure H andling
4. 2P C Optimizations
5. Pro cess Structuring
6. Three P hase Com mit
2
/
2
/
05 3
7.1 Introduction
•Goal -ensure the atom icity of a transaction that
acc esses multiple resource managers
•(Recall, resource abstracts data, messages, and othe
r
item s that are sh ared by transactions.)
•Why is this hard?
–W hat if resou rce m anager RM ifails after a transaction
commits at RM k?
–W hat if other reso urce managers are dow n when RM i
rec ov ers?
–W hat if a transaction thinks a resource manager failed
and therefore ab orted, when it actually is still running?
2
/
2
/
05 4
A ssu m p tions
• E ach resource manager independently com m its or
aborts a transaction atom ically on its resources.
•Home(T) decides when to start com m itting T
•Home(T) doesn’t start com m itting T until T
terminates at all nodes (p o ssibly hard)
• R esource managers fail by stopping
–no B yzan tine failures, where a failed pro c ess exhibits
arbitrary behavior, suc h as sending the wrong m e ssag e
2
/
2
/
05 5
Problem Statem ent
•Tran saction T accessed data at resource managers
R1, … Rn.
•The goal is to either
–commit T at all of R1, … Rn, or
–abort T at all of R 1, … Rn
–even if reso urce managers, nodes and com m unications
links fail during the commit or ab ort activity
•That is, never co m m it at Ribut abort at Rk.
2
/
2
/
05 6
7.2 Two-P hase Comm it
•Two phase com m it (2PC ) is the standard protocol
for making com m it and abort atom ic
• C oordinator-the com ponent that coordinates
com m itment at hom e(T)
•Participant-a resource manager accessed by T
•A participant P is read y to com m it T if all of T’s
after-images at P are in stable storag e
•The coordinator must not co m m it T until all
participants are read y
–If P isn ’t read y, T commits, and P fails, then P can ’t
commit when it recovers.
Docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Problem Statement - E-Commerce - Lecture Slides and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

2/2/ 05 1

7.Tw o Phase Com m it

Transaction Processing

forE-Com m erce

2/2/ 05 2

O utline

1.Introduction

2.The Tw o-Phase Com m it(2PC)Protocol

3.2PC Failure H andling

4.2PC O ptim izations

5.Process Structuring

6.Three Phase Com m it

2/2/ 05 3

7.1 Introduction

  • G oal-ensure the atom icity ofa transaction that

accesses m ultiple resource m anagers

  • (Recall,resource abstracts data,m essages,and other

item s thatare shared by transactions.)

  • W hy is this hard?
    • W hatif resource m anagerRM (^) i fails aftera transaction com m its atRM (^) k?
    • W hatifotherresource m anagers are dow n w hen RM (^) i recovers?
    • W hatifa transaction thinksa resource m anagerfailed and therefore aborted,w hen itactually is stillrunning? 2/2/ 05 4

A ssum ptions

  • Each resource m anagerindependently com m its or

aborts a transaction atom ically on its resources.

  • H om e(T)decides w hen to startcom m itting T
  • H om e(T)doesn’tstartcom m itting T untilT

term inates atallnodes (possibly hard)

  • Resource m anagers failby stopping
    • no Byzantine failures,w here a failed process exhibits arbitrary behavior,such assending the w rong m essage

2/2/ 05 5

Problem Statem ent

  • Transaction T accessed data atresource m anagers

R 1 ,… R n.

  • The goalis to either
    • com m itT atallofR 1 ,… R (^) n,or
    • abortT atallofR 1 ,… R (^) n
    • even if resource m anagers,nodes and com m unications links failduring the com m itorabortactivity
  • Thatis,nevercom m itatR (^) i butabortatR (^) k.

2/2/ 05 6

7.2 Tw o-Phase Com m it

  • Tw o phase com m it(2PC)is the standard protocol

form aking com m itand abortatom ic

  • Coordinator-the com ponentthatcoordinates

com m itm entathom e(T)

  • Participant-a resource m anageraccessed by T
  • A participantP is ready to com m itT ifallofT’s

after-im ages atP are in stable storage

  • The coordinatorm ustnotcom m itT untilall

participants are ready

  • If P isn’tready,T com m its,and P fails,then P can’t com m itw hen itrecovers.

2

2/2/ 05 7

The Protocol

1 (Begin Phase 1)The coordinatorsends a

Request-to-Prepare m essage to each participant

2 The coordinatorw aits forallparticipants to vote

3 Each participant

votes Prepared if it’s ready to com m it m ay vote No forany reason m ay delay voting indefinitely

4 (Begin Phase 2)Ifcoordinatorreceives Prepared

from allparticipants,itdecides to com m it.

(The transaction is now com m itted.)

O therw ise,itdecides to abort.

2/2/ 05 8

The Protocol(cont’d)

5 The coordinatorsends its decision to all

participants (i.e.Commit orAbort)

6 Participants acknow ledge receiptofCommit or

Abort by replying Done.

2/2/ 05 9

Case 1:Com m it

Coordinator Participant Request-to-Prepare Prepared

Commit Done

2/2/ 05 10

Case 2:A bort

Coordinator Request-to-Prepare

No Abort Done

Participant

2/2/ 05 11

Perform ance

  • In the absence offailures,2PC requires 3

rounds ofm essages before the decision is m ade

  • Request-to-prepare
  • V otes
  • D ecision
  • D one m essages are justforbookkeeping
  • they don’taffectresponse tim e
  • they can be batched

2/2/ 05 12

U ncertainty

  • Before itvotes,a participantcan abortunilaterally
  • A ftera participantvotes Prepared and before itreceives the coordinator’s decision,itis uncertain.Itcan’tunilaterally com m itorabortduring its uncertainty period.

Coordinator Participant Request-to-Prepare Prepared

Commit Done

U ncertainty Period

4

2/2/ 05 19

CoordinatorRecovery

  • If the coordinatorfails and laterrecovers,itm ustknow the decision.Itm usttherefore log - the factthatitbegan T’s 2PC protocol,including the list ofparticipants,and - Com m itorA bort,before sending Commit or Abort to any participant(so itknow s w hetherto com m itorabortafter itrecovers).
  • If the coordinatorfails and recovers,itresends the decision to participants from w hom itdoesn’trem em bergetting Done - If the participantforgotthe transaction,itreplies Done - The coordinatorshould therefore log D one afterithas received them all. 2/2/ 05 20

ParticipantRecovery

  • Ifa participantP fails and laterrecovers,itfirstperform s centralized recovery (Restart)
  • Foreach distributed transaction T thatw asactive atthe tim e offailure - IfP is notuncertain aboutT,then itunilaterally aborts T - IfP is uncertain,itruns the term ination protocol (w hich m ay leave P blocked)
  • To ensure itcan tellw hetherit’s uncertain,P m ustlog its vote beforesending itto the coordinator
  • To avoid becom ing totally blocked due to one blocked transaction,P should reacquire T’s locks during Restart and allow Restartto finish before T is resolved.

2/2/ 05 21

H euristic Com m it

  • Suppose a participantrecovers,butthe term ination

protocolleaves T blocked.

  • O peratorcan guess w hetherto com m itorabort
    • M ustdetectw rong guesses w hen coordinatorrecovers
    • M ustrun com pensations forw rong guesses
  • H euristic com m it
    • If T is blocked,the localresource m anager(actually, transaction m anager)guesses
    • A tcoordinatorrecovery,the transaction m anagers jointly detectw rong guesses.

2/2/ 05 22

7.4 2PC O ptim izations and V ariations

  • O ptim izations
    • Read-only transaction
    • Presum ed A bort
    • Transferofcoordination
    • Cooperative term ination protocol
  • V ariations
    • Re-infection
    • Phase Zero

2/2/ 05 23

Read-only Transaction

  • A read-only participantneed only respond to phase

one.Itdoesn’tcare w hatthe decision is.

  • Itresponds Prepared-Read-Only to Request-to-Prepare,

to tellthe coordinatornotto send the decision

  • Lim itation -A llotherparticipants m ustbe fully

term inated,since the read-only participantw ill

release locks aftervoting.

  • N o m ore testing ofSQ L integrity constraints
  • N o m ore evaluation ofSQ L triggers

2/2/ 05 24

Presum ed A bort

  • A ftera coordinatordecides A bortand sends Abort to participants,itforgets aboutT im m ediately.
  • Participants don’tacknow ledge Abort (w ith Done ) Coordinator Participant Request-to-Prepare Prepared

Abort

Log abort (forgetT) Log abort(forgetT)

Log prepared

Log Start2PC

  • Ifa participanttim es outw aiting forthe decision,itasks the coordinatorto retry. - If the coordinatorhas no info forT,itreplies Abort.

5

2/2/ 05 25

TransferofCoordination If there is one participant,you can save a round ofm essages 1.Coordinatorasks participantto prepare and becom e the coordinator. 2.The participant(now coordinator) prepares,com m its,and tells the form ercoordinatorto com m it. 3.The coordinatorcom m its and replies D one. Coordinator Participant Request-to-Prepare-and -transfer-coordination Log com m it Commit

Log com m itted

Log prepared

Done

  • Supported by som e app servers,butnotin any standards. 2/2/ 05 26

Cooperative Term ination Protocol(CTP)

  • A ssum e coordinatorincludes a listofparticipants in Request-to-Prepare.
  • Ifa participanttim es-outw aiting forthe decision, itruns the follow ing protocol. 1.ParticipantP sends Decision-Req to otherparticipants 2.IfparticipantQ voted No orhasn’tvoted orreceived Abort from the coordinator,itresponds Abort 3.IfparticipantQ received Commit from the coordinator, itresponds Commit. 4.IfparticipantQ isuncertain,itresponds Uncertain (ordoesn’trespond atall).
  • Ifallparticipants are uncertain,then P rem ains blocked.

2/2/ 05 27

Cooperative Term ination Issues

  • Participants don’tknow w hen to forgetT,

since otherparticipants m ay require CTP

  • Solution 1 -A fterreceiving Done from allparticipants, coordinatorsends End to allparticipants
  • Solution 2 -A fterreceiving a decision,a participantm ay forgetT any tim e.
  • To ensure itcan run CTP,a participantshould

include the listofparticipants in the vote log record.

2/2/ 05 28

Reinfection

  • Suppose A iscoordinatorand B and C are participants
    • A asks B and C to prepare
    • B votes prepared
    • C calls B to do som e w ork.(B is reinfected.)
    • B does the w ork and tells C ithas prepared, butnow itexpectsC to be its coordinator.
    • W hen A asksC to prepare,C propagates the requestto B and votes prepared only ifboth B and C are prepared. (See Tree ofProcesses discussion later.)
  • Can be used to im plem entintegrity constraintchecking, triggers,and othercom m it-tim e processing,w ithout requiring an extra phase (betw een phases 1 and 2 of2PC).

2/2/ 05 29

Phase Zero

  • Suppose a participantP is caching transaction T’s updates thatP needs to send to an RM (another participant)before T com m its. - P m ustsend the updatesafterT invokes Com m it,to ensure P has allofT’s updates - P m ustsend the updates before the RM prepares,to ensure the updatesare m ade stable during phase one. - Thus,w e need an extra phase,before phase 1.
  • A participantexplicitly enlists forphase zero.
    • Itdoesn’tack phase zero untilitfinishes flushing its cached updatesto otherparticipants.
  • Supported in M icrosoftD TC. 2/2/ 05 30

7.5 Process Structuring

  • To supportm ultiple RM son m ultiple nodes,and m inim ize com m unication,use one transaction m anager(TM )pernode
  • TM m ay be in the O S (V A X /V M S,W in),the app server (IBM CICS),D BM S,ora separate product(early Tandem ).
  • TM perform s coordinatorand participantroles forall transactions atits node.
  • TM com m unicates w ith localRM sand rem ote TM s.

Transaction M anager

ResResourourcece M anager^ M anager Resource M anager

A pplication

Enlist and 2PC ops

RM ops StartTransaction, TX Commit, Rollback

XA 2PC ops O ther TM s

7

2/2/ 05 37

7.6 Three Phase Com m it-The Idea

  • 3PC prevents blocking in the absence ofcom m unications failures (unrealistic,but… ).Itcan be m ade resilientto com m unications failures,butthen itm ay block
  • 3PC is m uch m ore com plex than 2PC,butonly m arginally im proves reliability — prevents som e blocking situations.
  • 3PC therefore is notused m uch in practice
  • M ain idea:becom ing certain and deciding to com m itare separate steps.
  • 3PC ensures thatifany operationalprocess is uncertain, then no (failed oroperational)process hascom m itted.
  • So,in the term ination protocol,if the operationalprocesses are alluncertain,they can decide to abort(avoids blocking). 2/2/ 05 38

Three Phase Com m it-The Protocol 1.(Begin phase 1)CoordinatorC sendsRequest-to-prepare to allparticipants 2.Participants vote Prepared orN o,justlike 2PC. 3.IfC receives Prepared from allparticipants,then (begin phase 2)itsends Pre-Com m itto allparticipants. 4.Participants w aitforA bortorPre-Com m it. Participantacknow ledges Pre-com m it. 5.A fterC receives acksfrom allparticipants,ortim es outon som e ofthem ,it(begin third phase)sends Com m itto all participants (thatare up)

2/2/ 05 39

3PC Failure H andling

  • Ifcoordinatortim es outbefore receiving Prepared

from allparticipants,itdecides to abort.

  • Coordinatorignores participants thatdon’tack its

Pre-Com m it.

  • Participants thatvoted Prepared and tim ed out

w aiting forPre-Com m itorCom m ituse the

term ination protocol.

  • The term ination protocolis w here the com plexity

lies.(E.g.see [Bernstein,H adzilacos,G oodm an 87],

Section 7.4)