354 Ch17.ppt

Embed Size (px)

Citation preview

  • 7/23/2019 354 Ch17.ppt

    1/33

    Transaction Processing - 1

    Single-User System: At most one user at a time

    can use the system.

    Multiuser System: Many users can access the

    system concurrently.

    Concurrency

    Interleave !rocessing: concurrent e"ecution o#

    !rocesses is interleave in a single CPU Parallel !rocessing: !rocesses are concurrently

    e"ecute in multi!le CPUs.

  • 7/23/2019 354 Ch17.ppt

    2/33

    Transaction Processing - $

    A transaction: logical unit o# %& !rocessing thatinclues one or more access o!erations 'rea -retrieval( )rite - insert or u!ate( elete*.

    A transaction 'set o# o!erations* may +e stan-alones!eci#ie in a high level language li,e S su+mitteinteractively( or may +e em+ee )ithin a !rogram.

    Transaction +ounaries: &egin/Start an 0ntransaction.

    An a!!lication !rogram may contain severaltransactions se!arate +y the &egin an 0ntransaction +ounaries.

  • 7/23/2019 354 Ch17.ppt

    3/33

    Transaction Processing -

    Sim!le moel o# a %& '#or !ur!oses o#iscussing transactions*: A ata+ase - collection o# name ata items

    2ranularity o# ata - a #iel( a recor( or a )hole is,+loc, 'conce!ts are ine!enent o# granularity*

    &asic o!erations are rea an )rite rea3item'4*: 5eas a %& item name 4 into a !rogram

    varia+le. 'To sim!li#y our notation( )e assume that the!rogram varia+le is also name 4.*

    )rite3item'4*: 6rites the value o# !rogram varia+le 4 intothe %& item name 4.

  • 7/23/2019 354 Ch17.ppt

    4/33

    Transaction Processing - 7

    5ea an )rite o!erations: &asic unit o# ata trans#er #rom the is, to the

    com!uter main memory is one +loc,. In general( aata item ')hat is rea or )ritten* )ill +e the #iel o#some recor in the %&( although it may +e a largerunit 'a recor or a )hole +loc,*.

    rea3item'4* inclues the #ollo)ing ste!s: 8in the aress o# the is, +loc, that contains item 4.

    Co!y that is, +loc, into a +u##er in main memory 'i# thatis, +loc, is not alreay in some main memory +u##er*.

    Co!y item 4 #rom the +u##er to the !rogram varia+le name4.

  • 7/23/2019 354 Ch17.ppt

    5/33

    Transaction Processing 9

    )rite3item'4* inclues the #ollo)ing ste!s:

    8in the aress o# the is, +loc, that contains item

    4.

    Co!y that is, +loc, into a +u##er in main memory 'i#that is, +loc, is not alreay in some main memory

    +u##er*.

    Co!y item 4 #rom the !rogram varia+le name 4

    into its correct location in the +u##er. Store the u!ate +loc, #rom the +u##er +ac, to is,

    'either immeiately or at some later !oint in time*.

  • 7/23/2019 354 Ch17.ppt

    6/33

    T)o Sam!le Transactions

  • 7/23/2019 354 Ch17.ppt

    7/33

    Transaction Processing -

    6hy Concurrency Control is neee:

    The ost U!ate Pro+lem

    t)o transactions that access the same %& itemshave their o!erations interleave in a )ay that

    ma,es the value o# some ata+ase item incorrect.

  • 7/23/2019 354 Ch17.ppt

    8/33

    The ost U!ate Pro+lem

  • 7/23/2019 354 Ch17.ppt

    9/33

    Transaction Processing - ;

    The Tem!orary U!ate 'or %irty 5ea*

    Pro+lem

    one transaction u!ates a %& item an then the

    transaction #ails #or some reason. The u!ateitem is accesse +y another transaction +e#ore it is

    change +ac, to its original value.

  • 7/23/2019 354 Ch17.ppt

    10/33

    The Tem!orary U!ate Pro+lem

  • 7/23/2019 354 Ch17.ppt

    11/33

    Transaction Processing t inter#ere)ith each other.*

  • 7/23/2019 354 Ch17.ppt

    15/33

    Transaction Processing - 11

    9. %is, #ailure: Some is, +loc,s may lose their ata+ecause o# a rea or )rite mal#unction or +ecauseo# a is, rea/)rite hea crash. This may ha!!enuring a rea or a )rite o!eration o# the

    transaction.

    . Physical !ro+lems an catastro!hes: This re#ers toan enless list o# !ro+lems that inclues !o)er orair-conitioning #ailure( #ire( the#t( sa+otage(

    over)riting is,s or ta!es +y mista,e( an o!eratorerror.

  • 7/23/2019 354 Ch17.ppt

    16/33

    Transaction an System

    Conce!ts - 1 A transaction is an atomic unit o# )or, that is either

    com!lete in its entirety or not one at all.

    8or recovery !ur!oses( the system nees to ,ee! trac,

    o# )hen the transaction starts( terminates( an commitsor a+orts.

    Transaction states: Active state

    Partially committe state

    Committe state

    8aile state

    Terminate State

  • 7/23/2019 354 Ch17.ppt

    17/33

    Transaction an System

    Conce!ts - $ 5ecovery manager ,ee!s trac, o# the #ollo)ing

    o!erations:+egin3transaction: This mar,s the +eginning o# transaction

    e"ecution.

    rea or )rite: These s!eci#y rea or )rite o!erations on the%& that are e"ecute as !art o# a transaction.

    en3transaction: This s!eci#ies that rea an )rite o!erationshave eneB mar,s the en limit o# transaction e"ecution.

    it may +e necessary to chec, )hether the changes introuce +y the

    transaction can +e !ermanently a!!lie to the %& or )hether thetransaction has to +e a+orte +ecause it violates concurrency controlor #or some other reason.

  • 7/23/2019 354 Ch17.ppt

    18/33

    Transaction an System

    Conce!ts - commit3transaction: This signals a success#ul

    en o# the transaction so that any changes

    'u!ates* e"ecute +y the transaction can +e

    sa#ely committe to the %& an )ill not +eunone.

    roll+ac, 'or a+ort*: This signals that the

    transaction has ene unsuccess#ully( so that anychanges or e##ects that the transaction may have

    a!!lie to the %& must +e unone.

  • 7/23/2019 354 Ch17.ppt

    19/33

    Transaction an System

    Conce!ts - 7

    5ecovery techniues use the #ollo)ing

    o!erators:

    uno: Similar to roll+ac, e"ce!t that it a!!lies

    to a single o!eration rather than to a )hole

    transaction.

    reo: This s!eci#ies that certain transaction

    o!erations must +e reone to ensure that all theo!erations o# a committe transaction have

    +een a!!lie success#ully to the %&.

  • 7/23/2019 354 Ch17.ppt

    20/33

    State Transition %iagram Illustrating the

    States #or Transaction 0"ecution

  • 7/23/2019 354 Ch17.ppt

    21/33

    Transaction an System

    Conce!ts - 9 The System og 'or Dournal*: ,ee!s trac, o# all

    transaction o!erations that a##ect the values o# %& items. This in#ormation may +e use to recover #rom transaction

    #ailures.

    The log is ,e!t on is,: una##ecte +y #ailures e"ce!t is, orcatastro!hic #ailures.

    The log is !erioically +ac,e u! to archival storage 'ta!e* toguar against such catastro!hic #ailures.

    Tin the #ollo)ing iscussion re#ers to a uniuetransaction-i that is generate automatically +y thesystemB use to ienti#y each transaction.

  • 7/23/2019 354 Ch17.ppt

    22/33

    Transaction an System

    Conce!ts - Ty!es o# log recor #or transaction T:

    Estart3transaction(TF: 5ecors that T has starte e"ecution.

    E)rite3item(T(4(ol3value(ne)3valueF: 5ecors that Thas change the value o# %& item 4 #rom ol3value tone)3value.

    Erea3item(T(4F: 5ecors that T has rea the value o# %&item 4.

    Ecommit(TF: 5ecors that T has com!lete success#ully(

    an a##irms that its e##ect can +e committe 'recore!ermanently* to the %&.

    Ea+ort(TF: 5ecors that T has +een a+orte.

  • 7/23/2019 354 Ch17.ppt

    23/33

    Transaction an System

    Conce!ts - ; 5ecovery using log recors:

    I# the system crashes( )e can recover to a consistent ata+ase

    state +y e"amining the log.

    The log contains a recor o# every )rite that moi#ies some%& item GH it is !ossi+le to uno the the )rite o!erations o#

    transaction T. o)J &y tracing +ac,)ar through the log

    an resetting all items change +y a )rite to their ol3values.

    6e can also reo the e##ect o# the )rite o!erations o# a

    transaction T +y tracing #or)ar through the log an settingall items change +y a )rite 'that i not get committe* to

    their ne)3values.

  • 7/23/2019 354 Ch17.ppt

    24/33

    Transaction an System

    Conce!ts < Commit Point o# a Transaction:

    %e#inition: A transaction T reaches its commit !oint

    )hen all o!erations that access the %& have +een

    e"ecute success#ully an the e##ect o# all transactionshas +een recore in the log. &eyon the commit !oint(

    the transaction is committeB its e##ect is !ermanently

    recore in the ata+ase. The transaction then )rites a

    Ecommit(TF entry in the log.

    5oll &ac, o# transactions: Keee #or transactions that

    have a Estart3transaction(TF entry in the log +ut no

    Ecommit(TF entry.

  • 7/23/2019 354 Ch17.ppt

    25/33

    Transaction an System

    Conce!ts - = 5eoing transactions: Transactions that have )ritten their

    commit entry in the log must also have recore all their)rite o!erations 'other)ise they )oul not +e committe*so their e##ect on the %& can +e reone #rom the log.

    the log #ile must +e ,e!t on is,. At the time o# a system crash(only log entries )ritten to is, are consiere in the recovery!rocess +ecause the contents o# memory may +e lost.

    8orce )riting a log: +e#ore a transaction reaches itscommit !oint( any !ortion o# the log that has not +een

    )ritten to the is, yet must no) +e )ritten to the is,.This !rocess is calle #orce-)riting the log #ile +e#orecommitting a transaction.

  • 7/23/2019 354 Ch17.ppt

    26/33

    %esira+le Pro!erties o#

    Transactions - 1

    ACI% !ro!erties:

    Atomicity: A transaction is an atomic unit o#

    !rocessingB it is either !er#orme in its

    entirety or not !er#orme at all.

    Consistency!reservation: A correct e"ecution

    o# the transaction must ta,e the ata+ase #rom

    one consistent state to another.

  • 7/23/2019 354 Ch17.ppt

    27/33

    %esira+le Pro!erties o#

    Transactions - $

    Isolation: A transaction shoul not ma,e its

    u!ates visi+le to other transactions until it is

    committeB this !ro!erty( )hen en#orce strictly(

    solves the tem!orary u!ate !ro+lem an ma,escascaing roll+ac,s o# transactions unnecessary.

    Durabilityor !ermanency: @nce a transaction

    changes the %& an the changes are committe(

    these changes must never +e lost +ecause o#su+seuent #ailure.

  • 7/23/2019 354 Ch17.ppt

    28/33

    Transaction Su!!ort in S$ - 1

    A single S statement is al)ays consiere to +eatomic: either the statement com!letes e"ecution)ithout error or it #ails an leaves the ata+aseunchange.

    The STA5T T5AKSACTI@K or &02IK statement+egins a ne) transaction. C@MMIT commits thecurrent transaction( ma,ing its changes !ermanent.5@&ACL rolls +ac, the current transaction(canceling its changes.

    0very transaction must have an e"!licit enstatement( )hich is either a C@MMIT or5@&ACL.

  • 7/23/2019 354 Ch17.ppt

    29/33

    Transaction Su!!ort in S$ - $

    Characteristics s!eci#ie +y a S0T

    T5AKSACTI@K statement in S$:

    Access moe: 50A% @K or 50A% 65IT0. The

    e#ault is 50A% 65IT0 unless the isolation level o#50A% UKC@MITT0% is s!eci#ie( in )hich case

    50A% @K is assume.

    %iagnostic si?e n( s!eci#ies an integer value n(

    inicating the num+er o# conitions that can +e helsimultaneously in the iagnostic area. 'Su!!ly user

    #ee+ac, in#ormation*

  • 7/23/2019 354 Ch17.ppt

    30/33

    Transaction Su!!ort in S$ -

    Characteristics s!eci#ie +y a S0T

    T5AKSACTI@K statement in S$ 'cont.*:

    Isolation level NisolationH( )here NisolationH can +e

    50A% UKC@MMITT0%( 50A% C@MMITT0%(50P0ATA&0 50A% or S05IAIOA&0. The

    e#ault is S05IAIOA&0.

    6ith S05IAIOA&0: the interleave e"ecution o#

    transactions )ill ahere to our notion o#seriali?a+ility. o)ever( i# any transaction e"ecutes

    at a lo)er level( then seriali?a+ility may +e violate.

  • 7/23/2019 354 Ch17.ppt

    31/33

    Transaction Su!!ort in S$ - 7

    Potential !ro+lem )ith lo)er isolation levels: %irty 5ea: 5eaing a value that )as )ritten +y a

    transaction )hich #aile.

    Kon-re!eata+le 5ea: Allo)ing another transaction to )ritea ne) value +et)een multi!le reas o# one transaction.

    A transaction T1 may rea a given value #rom a ta+le.I# another transaction T$ later u!ates that value an T1reas that value again( T1 )ill see a i##erent value.Consier that T1 reas the em!loyee salary #or Smith.

    Ke"t( T$ u!ates the salary #or Smith. I# T1 reas Smithssalary again( then it )ill see a i##erent value #or Smithssalary.

  • 7/23/2019 354 Ch17.ppt

    32/33

    Transaction Su!!ort in S$ - 9

    Phantoms: Ke) ro)s +eing rea using the samerea )ith a conition.

    A transaction T1 may rea a set o# ro)s #rom a

    ta+le( !erha!s +ase on some conitions!eci#ie in the S 6050 clause. Ko)su!!ose that a transaction T$ inserts a ne) ro)that also satis#ies the 6050 clause conition

    o# T1( into the ta+le use +y T1. I# T1 isre!eate( then T1 )ill see a ro) that !reviouslyi not e"ist( calle a phantom.

  • 7/23/2019 354 Ch17.ppt

    33/33

    Transaction Su!!ort in S$ -

    Sam!le S transaction:040C S )henever slerror go to UK%@B

    040C S S0T T5AKSACTI@K

    50A% 65IT0

    %IA2K@STICS SIO0 9IS@ATI@K 0Q0 S05IAIOA&0B

    040C S IKS05T

    IKT@ 0MP@00 '8KAM0( KAM0( SSK( %K@( SAA5*

    QAU0S '5o+ert(Smith(==17$1($(9*B

    040C S UP%AT0 0MP@00

    S0T SAA5 G SAA5 R 1.16050 %K@ G $B

    040C S C@MMITB

    2@T@ T030K%B

    UK%@: 040C S 5@&ACLB

    T030K%: ...