Atomic Transactions

download Atomic Transactions

of 42

Transcript of Atomic Transactions

  • 8/10/2019 Atomic Transactions

    1/42

    Atomic TransactionsCS-4513, D-Term 2007 1

    Atomic Transactions in

    Distributed Systems

    CS-4513

    D-Term 2007(Slides include materials rom Operating System Concepts, 7t!ed", by Silbers!at#, $al%in, & $a'ne,

    Modern Operating Systems, 2nded", by Tanenbaum, andDistributed Systems: Principles & Paradigms, 2nded" y Tanenbaum and )an Steen*

  • 8/10/2019 Atomic Transactions

    2/42

    Atomic TransactionsCS-4513, D-Term 2007 2

    Deinition + Transaction

    A seuence o o.erations t!at .erorm a

    sin'le lo'ical unction /am.les

    it!drain' money rom your account

    ain' an airline reser%ation

    ain' a credit-card .urc!ase

    ...

    sually used in contet o databases

  • 8/10/2019 Atomic Transactions

    3/42

    Atomic TransactionsCS-4513, D-Term 2007 3

    Deinition +Atomic Transaction

    A transaction t!at !a..ens com.letely or

    not at all 6o .artial results

    /am.le Cas! mac!ine !ands you cas! and deducts amount

    rom your account

    Airline conirms your reser%ation and+ 8educes number o ree seats

    + C!ar'es your credit card

    + (Sometimes* increases number o meals loaded on li'!t

  • 8/10/2019 Atomic Transactions

    4/42

    Atomic TransactionsCS-4513, D-Term 2007 4

    Atomic Transaction 8e%ie

    9undamental .rinci.les +A C I D

    +Atomicity+ to outside orld, transaction!a..ens indi%isibly

    +Consistency+ transaction .reser%es system

    in%ariants

    +Isolated+ transactions do not interere it!

    eac! ot!er

    +Durable+ once a transaction commits,t!e

    c!an'es are .ermanent

  • 8/10/2019 Atomic Transactions

    5/42

    Atomic TransactionsCS-4513, D-Term 2007 5

    Distributed Atomic Transactions

    Atomic transactions t!at s.an multi.le sites

    and:or systems Same semantics as atomic transactions on

    sin'le systemA C I D

    9ailure modes Cras! or ot!er ailure o one site or system

    6etor ailure or .artition

    y#antine ailures

  • 8/10/2019 Atomic Transactions

    6/42

    Atomic TransactionsCS-4513, D-Term 2007 ;

    To-

    =ne site is elected coordinatoro t!e

    transaction T SeeElectional'orit!ms (..t, !tml*

    Phase : !en coordinator is ready to

    commit t!e transaction

  • 8/10/2019 Atomic Transactions

    7/42

    Atomic TransactionsCS-4513, D-Term 2007 7

    To-

    Phase $:Coordinator

    +> any .artici.ant re.liesAbort(T*

  • 8/10/2019 Atomic Transactions

    8/42

    Atomic TransactionsCS-4513, D-Term 2007 @

    To-

  • 8/10/2019 Atomic Transactions

    9/42

    Atomic TransactionsCS-4513, D-Term 2007

    To-

    coordinator .artici.ant

    PREPARE

  • 8/10/2019 Atomic Transactions

    10/42

    Atomic TransactionsCS-4513, D-Term 2007 10

    9ailure 8eco%ery + To-

    9ailure modes (rom coordinators .oint o %ie*

    +=n cras!

    +'aitstate 6o res.onse rom some .artici.ant

    to !ote"re#uestmessa'e

    9ailure modes (rom .artici.ants .oint o %ie*

    +=n cras!+eadystate 6o messa'e rom coordinator to

    %lobal"Abort(T* or %lobal"Commit(T*

  • 8/10/2019 Atomic Transactions

    11/42

    Atomic TransactionsCS-4513, D-Term 2007 11

    ?ac o 8es.onse to Coordinator

    !ote"e#uest(T* messa'e

    /"'",

    +.artici.ant cras!

    +6etor ailure

    Timeout is considered eui%alent toAbort

    +

  • 8/10/2019 Atomic Transactions

    12/42

    Atomic TransactionsCS-4513, D-Term 2007 12

    Coordinator Cras!

    >ns.ect ?o'

    >Abortor Commitstate+ 8esend corres.ondin' messa'e

    + Tae corres.ondin' local action

    >Preparestate, eit!er+ 8esend !ote"re#uest(T* to all ot!er .artici.ants and

    ait or t!eir res.onsesB or

    + nilaterally abort transaction >"e", .utAbort(T* in on lo' on stable store

    Send %lobal"Abort(T* messa'e to all .artici.ants

    > not!in' in lo', abort transaction as abo%e

  • 8/10/2019 Atomic Transactions

    13/42

    Atomic TransactionsCS-4513, D-Term 2007 13

    6o 8es.onse to

  • 8/10/2019 Atomic Transactions

    14/42

    Atomic TransactionsCS-4513, D-Term 2007 14

    ns.ect local lo'

    +Commitstate 8edo:re.lay t!e transaction

    +Abortstate

    ndo:abort t!e transaction

    +6o records about T

    Same as local"abort(T*

    +eadyState

    Same as no res.onse toeady"to"commit(T* messa'e

  • 8/10/2019 Atomic Transactions

    15/42

    Atomic TransactionsCS-4513, D-Term 2007 15

    To-

    idely used in distributed transaction and

    database systems $enerally ors ell

    +!en coordinators are liely to reboot uicly

    +!en netor .artition is liely to end uicly

    Still subect to .artici.ant blocin'

  • 8/10/2019 Atomic Transactions

    16/42

    Atomic TransactionsCS-4513, D-Term 2007 1;

    T!ree-

    inor %ariation

    idely uoted in literature

    8arely im.lemented ecause indeinite blocin' due to coordinator

    ailures doesnt !a..en %ery oten in real lie

  • 8/10/2019 Atomic Transactions

    17/42

    Atomic TransactionsCS-4513, D-Term 2007 17

    PREPARE

    T!ree-

    T!ere is no state rom !ic! a transition can bemade to eit!er Commitor Abort

    T!ere is no state !ere it is not .ossible to mae ainal decision and rom !ic! transition can bemade to Commit"

  • 8/10/2019 Atomic Transactions

    18/42

    Atomic TransactionsCS-4513, D-Term 2007 1@

    T!ree-

    Coordinator sends !ote"e#uest(as beore*

    > all .artici.ants res.ond airmati%ely,

  • 8/10/2019 Atomic Transactions

    19/42

    Atomic TransactionsCS-4513, D-Term 2007 1

    T!ree-

    Coordinator bloced ineadystate

    Sae to abort transaction

    Coordinator bloced inPrecommitstate Sae to issue %lobal"Commit

    Any cras!ed or .artitioned .artici.ants ill commit

    !en reco%ered

  • 8/10/2019 Atomic Transactions

    20/42

    Atomic TransactionsCS-4513, D-Term 2007 20

    T!ree-

    any inPrecommit, t!e mo%e toPrecommitstate

    E

  • 8/10/2019 Atomic Transactions

    21/42

    Atomic TransactionsCS-4513, D-Term 2007 21

    T!ree-

    > any .rocesses are inPrecommitstate,

    t!en all cras!ed .rocesses ill reco%er toeady,Precommit, or Committedstates

    > any .rocess is ineadystate, t!en all

    ot!er cras!ed .rocesses ill reco%er toInit,Abort, orPrecommit

    Sur%i%in' .rocesses can mae collecti%e decision

  • 8/10/2019 Atomic Transactions

    22/42

    Atomic TransactionsCS-4513, D-Term 2007 1

    Atomic Transactions in

    Distributed Systems

    CS-4513D-Term 2007

    (Slides include materials rom Operating System Concepts, 7t!ed", by Silbers!at#, $al%in, & $a'ne,Modern Operating Systems, 2nded", by Tanenbaum, andDistributed Systems: Principles & Paradigms, 2nd

    ed" y Tanenbaum and )an Steen*

    Assumptions:

    Graduate level

    Operating SystemsMaking Choices aout operation systems

    !hy a micro"century# $%ust aout enough time &or one

    concept

  • 8/10/2019 Atomic Transactions

    23/42

    Atomic TransactionsCS-4513, D-Term 2007 2

    Deinition + Transaction

    A seuence o o.erations t!at .erorm asin'le lo'ical unction

    /am.les it!drain' money rom your account

    ain' an airline reser%ation

    ain' a credit-card .urc!ase

    ...

    sually used in contet o databases

  • 8/10/2019 Atomic Transactions

    24/42

    Atomic TransactionsCS-4513, D-Term 2007 3

    Deinition +Atomic Transaction

    A transaction t!at !a..ens com.letely ornot at all

    6o .artial results

    /am.le Cas! mac!ine !ands you cas! and deducts amount

    rom your account

    Airline conirms your reser%ation and+ 8educes number o ree seats

    + C!ar'es your credit card

    + (Sometimes* increases number o meals loaded on li'!t

  • 8/10/2019 Atomic Transactions

    25/42

    Atomic TransactionsCS-4513, D-Term 2007 4

    Atomic Transaction 8e%ie

    9undamental .rinci.les +A C I D+Atomicity+ to outside orld, transaction

    !a..ens indi%isibly

    +Consistency+ transaction .reser%es system

    in%ariants

    +Isolated+ transactions do not interere it!

    eac! ot!er

    +Durable+ once a transaction commits,t!e

    c!an'es are .ermanent

  • 8/10/2019 Atomic Transactions

    26/42

    Atomic TransactionsCS-4513, D-Term 2007 5

    Distributed Atomic Transactions

    Atomic transactions t!at s.an multi.le sitesand:or systems

    Same semantics as atomic transactions on

    sin'le system A C I D

    9ailure modes Cras! or ot!er ailure o one site or system

    6etor ailure or .artition y#antine ailures

  • 8/10/2019 Atomic Transactions

    27/42

  • 8/10/2019 Atomic Transactions

    28/42

    Atomic TransactionsCS-4513, D-Term 2007 7

    To-

    Phase $:Coordinator+> any .artici.ant re.liesAbort(T*

  • 8/10/2019 Atomic Transactions

    29/42

    Atomic TransactionsCS-4513, D-Term 2007 @

    To-

  • 8/10/2019 Atomic Transactions

    30/42

    Atomic TransactionsCS-4513, D-Term 2007

    To-

    coordinator .artici.ant

    PREPARE

  • 8/10/2019 Atomic Transactions

    31/42 1

    Atomic TransactionsCS-4513, D-Term 2007 10

    9ailure 8eco%ery + To-

    9ailure modes

    (rom coordinators .oint o %ie*

    +=n cras!

    +'aitstate 6o res.onse rom some .artici.ant

    to !ote"re#uestmessa'e

    9ailure modes (rom .artici.ants .oint o %ie*

    +=n cras!

    +eadystate 6o messa'e rom coordinator to

    %lobal"Abort(T* or %lobal"Commit(T*

  • 8/10/2019 Atomic Transactions

    32/42 1

    Atomic TransactionsCS-4513, D-Term 2007 11

    ?ac o 8es.onse to Coordinator

    !ote"e#uest(T* messa'e

    /"'",+.artici.ant cras!

    +6etor ailure

    Timeout is considered eui%alent toAbort

    +

  • 8/10/2019 Atomic Transactions

    33/42 1

    Atomic TransactionsCS-4513, D-Term 2007 12

    Coordinator Cras!

    >ns.ect ?o'

    >Abortor Commitstate+ 8esend corres.ondin' messa'e

    + Tae corres.ondin' local action

    >Preparestate, eit!er+ 8esend !ote"re#uest(T* to all ot!er .artici.ants and

    ait or t!eir res.onsesB or

    + nilaterally abort transaction >"e", .utAbort(T* in on lo' on stable store

    Send %lobal"Abort(T* messa'e to all .artici.ants > not!in' in lo', abort transaction as abo%e

  • 8/10/2019 Atomic Transactions

    34/42 1

    Atomic TransactionsCS-4513, D-Term 2007 13

    6o 8es.onse to

  • 8/10/2019 Atomic Transactions

    35/42 1

    Atomic TransactionsCS-4513, D-Term 2007 14

    ns.ect local lo'+Commitstate

    8edo:re.lay t!e transaction

    +Abortstate

    ndo:abort t!e transaction

    +6o records about T

    Same as local"abort(T*

    +eadyState

    Same as no res.onse toeady"to"commit(T* messa'e

  • 8/10/2019 Atomic Transactions

    36/42 1

    Atomic TransactionsCS-4513, D-Term 2007 15

    To-

    idely used in distributed transaction anddatabase systems

    $enerally ors ell

    +!en coordinators are liely to reboot uicly

    +!en netor .artition is liely to end uicly

    Still subect to .artici.ant blocin'

  • 8/10/2019 Atomic Transactions

    37/42 1

    Atomic TransactionsCS-4513, D-Term 2007 1;

    T!ree-

    inor %ariation

    idely uoted in literature

    8arely im.lemented ecause indeinite blocin' due to coordinator

    ailures doesnt !a..en %ery oten in real lie

  • 8/10/2019 Atomic Transactions

    38/42 1

    Atomic TransactionsCS-4513, D-Term 2007 17

    PREPARE

    T!ree-

    T!ere is no state rom !ic! a transition can bemade to eit!er Commitor Abort

    T!ere is no state !ere it is not .ossible to mae a

    inal decision and rom !ic! transition can bemade to Commit"

  • 8/10/2019 Atomic Transactions

    39/42 1

    Atomic TransactionsCS-4513, D-Term 2007 1@

    T!ree-

    Coordinator sends !ote"e#uest(as beore*

    > all .artici.ants res.ond airmati%ely,

  • 8/10/2019 Atomic Transactions

    40/42 1

    Atomic TransactionsCS-4513, D-Term 2007 1

    T!ree-

    Coordinator bloced ineadystate Sae to abort transaction

    Coordinator bloced inPrecommitstate Sae to issue %lobal"Commit

    Any cras!ed or .artitioned .artici.ants ill commit

    !en reco%ered

  • 8/10/2019 Atomic Transactions

    41/42 '

    Atomic TransactionsCS-4513, D-Term 2007 20

    T!ree-

    any inPrecommit, t!e mo%e toPrecommitstate

    E

  • 8/10/2019 Atomic Transactions

    42/42

    Atomic TransactionsCS-4513, D-Term 2007 21

    T!ree-

    > any .rocesses are inPrecommitstate,t!en all cras!ed .rocesses ill reco%er to

    eady,Precommit, or Committedstates

    > any .rocess is ineadystate, t!en all

    ot!er cras!ed .rocesses ill reco%er to Init,Abort, orPrecommit

    Sur%i%in' .rocesses can mae collecti%e decision