SlideShare ist ein Scribd-Unternehmen logo
1 von 64
Transactions
     Alan Medlar

 amedlar@cs.ucl.ac.uk
Transactions

ā€¢ A transaction is a unit of work that is
  treated in a coherent and reliable manner. All
  transactions must be independent of one
  another
Transactions

ā€¢ A transaction is a unit of work that is
  treated in a coherent and reliable manner. All
  transactions must be independent of one
  another
ā€¢ Provide concurrency support (next lecture!)
Transactions

ā€¢ A transaction is a unit of work that is
  treated in a coherent and reliable manner. All
  transactions must be independent of one
  another
ā€¢ Provide concurrency support (next lecture!)
ā€¢ Fundamental in computer science
Properties

ā€¢ Handy mnemonic: ACID
 ā€¢ Atomicity
 ā€¢ Consistency
 ā€¢ Integrity
 ā€¢ Durability
Atomicity
ā€¢ Strong guarantee that changes to a
  database are applied ā€œall or nothingā€
Atomicity
ā€¢ Strong guarantee that changes to a
  database are applied ā€œall or nothingā€
ā€¢ Atomicity must be maintained in the face of
  failures (even from OS, hardware etc...)
Atomicity
ā€¢ Strong guarantee that changes to a
  database are applied ā€œall or nothingā€
ā€¢ Atomicity must be maintained in the face of
  failures (even from OS, hardware etc...)
ā€¢ E.g.: move Ā£100 from my bank account to
  your bank account. If transfer to your
  account fails, I must be credited back!
Consistency


ā€¢ Transactions should not violate integrity
  constraints leaving database in illegal state
  ā€¢ E.g.: age cannot be negative number
Isolation

ā€¢ Transactions should not affect one another
Isolation

ā€¢ Transactions should not affect one another
ā€¢ More precisely it deļ¬nes when the changes
  resulting from a transaction will be seen by
  other concurrent transactions
Durability

ā€¢ Outcome of transaction must persist
  beyond its completion
 ā€¢ i.e.: given a system crash, the state of the
    database can be recovered
Transaction Example
ā€¢ Debit Ā£100 from Aliceā€™s bank account and
  credit it to Bobā€™s account

  read(Alice)
  Alice = Alice - 100
  write(Alice)
  read(Bob)
  Bob = Bob + 100
  write(Bob)
Transaction Example
ā€¢ Debit Ā£100 from Aliceā€™s bank account and
  credit it to Bobā€™s account
                                                  } Ā£1950
                        Aliceā€™s balance = Ā£2000
                        Bobā€™s balance = Ā£-50
  read(Alice)
  Alice = Alice - 100
  write(Alice)
  read(Bob)
  Bob = Bob + 100
  write(Bob)
Transaction Example
ā€¢ Debit Ā£100 from Aliceā€™s bank account and
  credit it to Bobā€™s account
                                                  } Ā£1950
                        Aliceā€™s balance = Ā£2000
                        Bobā€™s balance = Ā£-50
  read(Alice)
  Alice = Alice - 100
                                                  } Ā£1850
                        Aliceā€™s balance = Ā£1900
  write(Alice)          Bobā€™s balance = Ā£-50
  read(Bob)
  Bob = Bob + 100
  write(Bob)
Transaction Example
ā€¢ Debit Ā£100 from Aliceā€™s bank account and
  credit it to Bobā€™s account
                                                  } Ā£1950
                        Aliceā€™s balance = Ā£2000
                        Bobā€™s balance = Ā£-50
  read(Alice)
  Alice = Alice - 100
                                                  } Ā£1850
                        Aliceā€™s balance = Ā£1900
  write(Alice)          Bobā€™s balance = Ā£-50
  read(Bob)
  Bob = Bob + 100
                                                  } Ā£1950
                        Aliceā€™s balance = Ā£1900
  write(Bob)            Bobā€™s balance = Ā£50
Transaction Example (2)
ā€¢ What if Bobā€™s account does not exist? Or
  permissions are set wrong?
Transaction Example (2)
ā€¢ What if Bobā€™s account does not exist? Or
  permissions are set wrong?

  read(Alice)
  Alice = Alice - 100
  write(Alice)
  read(Bob)
  Bob = Bob + 100
  write(Bob)
Transaction Example (2)
ā€¢ What if Bobā€™s account does not exist? Or
  permissions are set wrong?
                                                  } Ā£1950
                        Aliceā€™s balance = Ā£2000
                        Bobā€™s balance = Ā£-50
  read(Alice)
  Alice = Alice - 100
  write(Alice)
  read(Bob)
  Bob = Bob + 100
  write(Bob)
Transaction Example (2)
ā€¢ What if Bobā€™s account does not exist? Or
  permissions are set wrong?
                                                  } Ā£1950
                        Aliceā€™s balance = Ā£2000
                        Bobā€™s balance = Ā£-50
  read(Alice)
  Alice = Alice - 100
                                                  } Ā£1850
                        Aliceā€™s balance = Ā£1900
  write(Alice)          Bobā€™s balance = Ā£-50
  read(Bob)
  Bob = Bob + 100
  write(Bob)
Transaction Example (2)
ā€¢ What if Bobā€™s account does not exist? Or
  permissions are set wrong?
                                                  } Ā£1950
                        Aliceā€™s balance = Ā£2000
                        Bobā€™s balance = Ā£-50
  read(Alice)
  Alice = Alice - 100
                                                  } Ā£1850
                        Aliceā€™s balance = Ā£1900
  write(Alice)          Bobā€™s balance = Ā£-50
  read(Bob)
  Bob = Bob + 100           Read fails, must
                           credit Alice back!
  write(Bob)
Atomicity


                                                } Ā£1950
                      Aliceā€™s balance = Ā£2000
                      Bobā€™s balance = Ā£-50
read(Alice)
Alice = Alice - 100
                                                } Ā£1850
                      Aliceā€™s balance = Ā£1900
write(Alice)          Bobā€™s balance = Ā£-50
read(Bob)
Bob = Bob + 100
                                                } Ā£1950
                      Aliceā€™s balance = Ā£1900
write(Bob)            Bobā€™s balance = Ā£50
Atomicity
               Both writes succeed
                 or neither do!
                                                } Ā£1950
                      Aliceā€™s balance = Ā£2000
                      Bobā€™s balance = Ā£-50
read(Alice)
Alice = Alice - 100
                                                } Ā£1850
                      Aliceā€™s balance = Ā£1900
write(Alice)          Bobā€™s balance = Ā£-50
read(Bob)
Bob = Bob + 100
                                                } Ā£1950
                      Aliceā€™s balance = Ā£1900
write(Bob)            Bobā€™s balance = Ā£50
Consistency


                                                } Ā£1950
                      Aliceā€™s balance = Ā£2000
                      Bobā€™s balance = Ā£-50
read(Alice)
Alice = Alice - 100
                                                } Ā£1850
                      Aliceā€™s balance = Ā£1900
write(Alice)          Bobā€™s balance = Ā£-50
read(Bob)
Bob = Bob + 100
                                                } Ā£1950
                      Aliceā€™s balance = Ā£1900
write(Bob)            Bobā€™s balance = Ā£50
Consistency
             Consistent state
      (no created or missing money!)
                                                } Ā£1950
                      Aliceā€™s balance = Ā£2000
                      Bobā€™s balance = Ā£-50
read(Alice)
Alice = Alice - 100
                                                } Ā£1850
                      Aliceā€™s balance = Ā£1900
write(Alice)          Bobā€™s balance = Ā£-50
read(Bob)
Bob = Bob + 100
                                                } Ā£1950
                      Aliceā€™s balance = Ā£1900
write(Bob)            Bobā€™s balance = Ā£50
Isolation


                                                } Ā£1950
                      Aliceā€™s balance = Ā£2000
                      Bobā€™s balance = Ā£-50
read(Alice)
Alice = Alice - 100
                                                } Ā£1850
                      Aliceā€™s balance = Ā£1900
write(Alice)          Bobā€™s balance = Ā£-50
read(Bob)
Bob = Bob + 100
                                                } Ā£1950
                      Aliceā€™s balance = Ā£1900
write(Bob)            Bobā€™s balance = Ā£50
Isolation
               No other transactions
              see intermediate values
                                                } Ā£1950
                      Aliceā€™s balance = Ā£2000
                      Bobā€™s balance = Ā£-50
read(Alice)
Alice = Alice - 100
                                                } Ā£1850
                      Aliceā€™s balance = Ā£1900
write(Alice)          Bobā€™s balance = Ā£-50
read(Bob)
Bob = Bob + 100
                                                } Ā£1950
                      Aliceā€™s balance = Ā£1900
write(Bob)            Bobā€™s balance = Ā£50
Durability
ā€¢ Transaction logs used to ensure durability
Durability
ā€¢ Transaction logs used to ensure durability
ā€¢ Log transaction writes, then update
  database
Durability
ā€¢ Transaction logs used to ensure durability
ā€¢ Log transaction writes, then update
  database
ā€¢ Logs must be written ļ¬rst or else updates
  can be lost given a system crash!
Durability
ā€¢ Transaction logs used to ensure durability
ā€¢ Log transaction writes, then update
  database
ā€¢ Logs must be written ļ¬rst or else updates
  can be lost given a system crash!
ā€¢ Disks can still fail! (disk mirroring?)
Failures
ā€¢   Possible failures include:

    ā€¢   System crash

    ā€¢   Hardware malfunctions

        ā€¢   Disk failure

    ā€¢   Deadlocks

    ā€¢   System errors: out of memory, program errors (see
        ā€œman 2 writeā€)

    ā€¢   etc...
State Machine
          Partial   Commit-
         commit       ted

Active

         Failed     Aborted
State Machine
                          Partial   Commit-
                         commit       ted

                Active

Initial state            Failed     Aborted
State Machine
Last statement
 processed
                 Partial   Commit-
                commit       ted

       Active

                Failed     Aborted
State Machine
          Partial   Commit-
         commit       ted

                        Completion
Active
                     (database updated)
         Failed     Aborted
State Machine
                Partial   Commit-
               commit       ted

     Active

               Failed     Aborted


Processing can no
 longer proceed
State Machine
          Partial   Commit-
         commit       ted

Active

         Failed     Aborted


                     Transaction rolled
                     back to prior state
Transaction Logging

ā€¢ Transaction start: <T , start>
                      i

ā€¢ Transaction write: <T , X ,V ,V >
                          i       j   1   2

ā€¢ Transaction commit: <T , commit>
                              i
Transaction Logging
         Transaction ID

ā€¢ Transaction start: <T , start>
                      i

ā€¢ Transaction write: <T , X ,V ,V >
                          i       j   1   2

ā€¢ Transaction commit: <T , commit>
                              i
Transaction Logging
         Transaction ID
                                          Data item ID
ā€¢ Transaction start: <T , start>
                      i

ā€¢ Transaction write: <T , X ,V ,V >
                          i       j   1   2

ā€¢ Transaction commit: <T , commit>
                              i
Transaction Logging
         Transaction ID
                                          Data item ID
ā€¢ Transaction start: <T , start>
                      i

ā€¢ Transaction write: <T , X ,V ,V >
                          i       j   1   2

ā€¢ Transaction commit: <T , commit>
                              i


                                      Data values before
                                       and after write
Transaction Logging
Transaction, ā€˜Tā€™

read(Alice)
Alice = Alice - 100
write(Alice)
read(Bob)
Bob = Bob + 100
write(Bob)
Transaction Logging
Transaction, ā€˜Tā€™
                                  <T, start>
read(Alice)
Alice = Alice - 100
                      <T, Alice, 2000, 1900>
write(Alice)
read(Bob)
Bob = Bob + 100
write(Bob)                 <T, Bob, -50, 50>
                               <T, commit>
Transaction Logging
Transaction, ā€˜Tā€™
                                  <T, start>
read(Alice)
Alice = Alice - 100
                      <T, Alice, 2000, 1900>
write(Alice)
read(Bob)
Bob = Bob + 100
write(Bob)                 <T, Bob, -50, 50>
                               <T, commit>
Transaction Logging
Transaction, ā€˜Tā€™
                                  <T, start>
read(Alice)
Alice = Alice - 100
                      <T, Alice, 2000, 1900>
write(Alice)
read(Bob)
Bob = Bob + 100
write(Bob)                 <T, Bob, -50, 50>
                               <T, commit>
Transaction Logging
Transaction, ā€˜Tā€™
                                  <T, start>
read(Alice)
Alice = Alice - 100
                      <T, Alice, 2000, 1900>
write(Alice)
read(Bob)
Bob = Bob + 100
write(Bob)                 <T, Bob, -50, 50>
                               <T, commit>
Deferred Modiļ¬cation

ā€¢ Ensure atomicity by deferring all writes
  until partial commit of transaction
ā€¢ <T , commit> is a partial commit (only
     i
  affected log so far, not database)
ā€¢ Given logs are in stable storage, writes can
  be made to the database itself !
Failure Recovery

ā€¢ If the system fails we can use the
  transaction log to recover the database
ā€¢ For all <T , start>, <T , commit> in log redo
            i           i
  writes sequentially
Recovery Example
<T1, start>
<T1, Alice, 2000, 1900>
<T1, Bob, -50, 50>
<T1, commit>

<T2, start>
<T2, Alice, 1900, 1800>

<T3, start>
Recovery Example


                          }
<T1, start>
                          start and commit
<T1, Alice, 2000, 1900>
                               present
<T1, Bob, -50, 50>
<T1, commit>

<T2, start>
<T2, Alice, 1900, 1800>

<T3, start>
Recovery Example
<T1, start>
                          Redo
<T1, Alice, 2000, 1900>
<T1, Bob, -50, 50>
<T1, commit>

<T2, start>
<T2, Alice, 1900, 1800>

<T3, start>
Recovery Example
<T1, start>
<T1, Alice, 2000, 1900>
                          Redo
<T1, Bob, -50, 50>
<T1, commit>

<T2, start>
<T2, Alice, 1900, 1800>

<T3, start>
Recovery Example
<T1, start>
<T1, Alice, 2000, 1900>
<T1, Bob, -50, 50>
<T1, commit>




                          }
<T2, start>
<T2, Alice, 1900, 1800>   no commit!
<T3, start>
Immediate Modiļ¬cation

ā€¢ Instead of waiting for a commit, we could
  just perform the writes as they happen (but
  still post-log writing)
  ā€¢ Incomplete transactions written to
    database require old value V1
Failure Recovery

ā€¢ Again, if the system fails we use the
  transaction log to recover the database
ā€¢ For all <T , start>, <T , commit> in log redo
            i           i
  database write
ā€¢ For all <T , start>, without <T , commit> in
            i                    i
  log undo write
Recovery Example
<T1, start>
<T1, Alice, 2000, 1900>
<T1, Bob, -50, 50>
<T1, commit>

<T2, start>
<T2, Alice, 1900, 1800>

<T3, start>
Recovery Example
<T1, start>
                          Redo
<T1, Alice, 2000, 1900>
<T1, Bob, -50, 50>
<T1, commit>

<T2, start>
<T2, Alice, 1900, 1800>

<T3, start>
Recovery Example
<T1, start>
<T1, Alice, 2000, 1900>
                          Redo
<T1, Bob, -50, 50>
<T1, commit>

<T2, start>
<T2, Alice, 1900, 1800>

<T3, start>
Recovery Example
<T1, start>
<T1, Alice, 2000, 1900>
<T1, Bob, -50, 50>
<T1, commit>

<T2, start>
                          Redo
<T2, Alice, 1900, 1800>

<T3, start>
Recovery Example
<T1, start>
<T1, Alice, 2000, 1900>
<T1, Bob, -50, 50>
<T1, commit>

<T2, start>
<T2, Alice, 1900, 1800>

                          No Commit!
<T3, start>
Recovery Example
<T1, start>
<T1, Alice, 2000, 1900>
<T1, Bob, -50, 50>
<T1, commit>

<T2, start>
                          Undo
<T2, Alice, 1900, 1800>

<T3, start>
Check-points
ā€¢ Speed up recovery!
ā€¢ Create a ā€œcheck-pointā€ to reduce work to
  be done given a failure
  ā€¢ Flush all buffers to disk
  ā€¢ Write <checkpoint> to log
ā€¢ On failure: read log until <checkpoint>
  found, then start recovery
Next: Concurrent Transactions

Weitere Ƥhnliche Inhalte

KĆ¼rzlich hochgeladen

9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday Safaris
9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday Safaris9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday Safaris
9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday SafarisKibera Holiday Safaris Safaris
Ā 
Dubai Call Girls O528786472 Call Girls Dubai Big Juicy
Dubai Call Girls O528786472 Call Girls Dubai Big JuicyDubai Call Girls O528786472 Call Girls Dubai Big Juicy
Dubai Call Girls O528786472 Call Girls Dubai Big Juicyhf8803863
Ā 
Study Consultants in Lahore || šŸ“ž03094429236
Study Consultants in Lahore || šŸ“ž03094429236Study Consultants in Lahore || šŸ“ž03094429236
Study Consultants in Lahore || šŸ“ž03094429236Sherazi Tours
Ā 
08448380779 Call Girls In Chhattarpur Women Seeking Men
08448380779 Call Girls In Chhattarpur Women Seeking Men08448380779 Call Girls In Chhattarpur Women Seeking Men
08448380779 Call Girls In Chhattarpur Women Seeking MenDelhi Call girls
Ā 
Visa Consultant in Lahore || šŸ“ž03094429236
Visa Consultant in Lahore || šŸ“ž03094429236Visa Consultant in Lahore || šŸ“ž03094429236
Visa Consultant in Lahore || šŸ“ž03094429236Sherazi Tours
Ā 
Exploring Sicily Your Comprehensive Ebook Travel Guide
Exploring Sicily Your Comprehensive Ebook Travel GuideExploring Sicily Your Comprehensive Ebook Travel Guide
Exploring Sicily Your Comprehensive Ebook Travel GuideTime for Sicily
Ā 
DARK TRAVEL AGENCY presented by Khuda Bux
DARK TRAVEL AGENCY presented by Khuda BuxDARK TRAVEL AGENCY presented by Khuda Bux
DARK TRAVEL AGENCY presented by Khuda BuxBeEducate
Ā 
Top 10 Traditional Indian Handicrafts.pptx
Top 10 Traditional Indian Handicrafts.pptxTop 10 Traditional Indian Handicrafts.pptx
Top 10 Traditional Indian Handicrafts.pptxdishha99
Ā 
How can I fly with the British Airways Unaccompanied Minor Policy?
How can I fly with the British Airways Unaccompanied Minor Policy?How can I fly with the British Airways Unaccompanied Minor Policy?
How can I fly with the British Airways Unaccompanied Minor Policy?flightsvillacom
Ā 
08448380779 Call Girls In Shahdara Women Seeking Men
08448380779 Call Girls In Shahdara Women Seeking Men08448380779 Call Girls In Shahdara Women Seeking Men
08448380779 Call Girls In Shahdara Women Seeking MenDelhi Call girls
Ā 
char Dham yatra, Uttarakhand tourism.pptx
char Dham yatra, Uttarakhand tourism.pptxchar Dham yatra, Uttarakhand tourism.pptx
char Dham yatra, Uttarakhand tourism.pptxpalakdigital7
Ā 
Akshay Mehndiratta Summer Special Light Meal Ideas From Across India.pptx
Akshay Mehndiratta Summer Special Light Meal Ideas From Across India.pptxAkshay Mehndiratta Summer Special Light Meal Ideas From Across India.pptx
Akshay Mehndiratta Summer Special Light Meal Ideas From Across India.pptxAkshay Mehndiratta
Ā 
Hoi An Ancient Town, Vietnam (č¶Šå— ęœƒå®‰å¤éŽ®).ppsx
Hoi An Ancient Town, Vietnam (č¶Šå— ęœƒå®‰å¤éŽ®).ppsxHoi An Ancient Town, Vietnam (č¶Šå— ęœƒå®‰å¤éŽ®).ppsx
Hoi An Ancient Town, Vietnam (č¶Šå— ęœƒå®‰å¤éŽ®).ppsxChung Yen Chang
Ā 
Call Girls šŸ«¤ Connaught Place āž”ļø 9999965857 āž”ļø Delhi šŸ«¦ Russian Escorts FULL ...
Call Girls šŸ«¤ Connaught Place āž”ļø 9999965857  āž”ļø Delhi šŸ«¦  Russian Escorts FULL ...Call Girls šŸ«¤ Connaught Place āž”ļø 9999965857  āž”ļø Delhi šŸ«¦  Russian Escorts FULL ...
Call Girls šŸ«¤ Connaught Place āž”ļø 9999965857 āž”ļø Delhi šŸ«¦ Russian Escorts FULL ...Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
Ā 
Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779
Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779
Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779Delhi Call girls
Ā 
visa consultant | šŸ“žšŸ“ž 03094429236 || Best Study Visa Consultant
visa consultant | šŸ“žšŸ“ž 03094429236 || Best Study Visa Consultantvisa consultant | šŸ“žšŸ“ž 03094429236 || Best Study Visa Consultant
visa consultant | šŸ“žšŸ“ž 03094429236 || Best Study Visa ConsultantSherazi Tours
Ā 

KĆ¼rzlich hochgeladen (20)

9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday Safaris
9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday Safaris9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday Safaris
9 Days Kenya Ultimate Safari Odyssey with Kibera Holiday Safaris
Ā 
Dubai Call Girls O528786472 Call Girls Dubai Big Juicy
Dubai Call Girls O528786472 Call Girls Dubai Big JuicyDubai Call Girls O528786472 Call Girls Dubai Big Juicy
Dubai Call Girls O528786472 Call Girls Dubai Big Juicy
Ā 
Call Girls Service !! New Friends Colony!! @9999965857 Delhi šŸ«¦ No Advance VV...
Call Girls Service !! New Friends Colony!! @9999965857 Delhi šŸ«¦ No Advance  VV...Call Girls Service !! New Friends Colony!! @9999965857 Delhi šŸ«¦ No Advance  VV...
Call Girls Service !! New Friends Colony!! @9999965857 Delhi šŸ«¦ No Advance VV...
Ā 
Study Consultants in Lahore || šŸ“ž03094429236
Study Consultants in Lahore || šŸ“ž03094429236Study Consultants in Lahore || šŸ“ž03094429236
Study Consultants in Lahore || šŸ“ž03094429236
Ā 
08448380779 Call Girls In Chhattarpur Women Seeking Men
08448380779 Call Girls In Chhattarpur Women Seeking Men08448380779 Call Girls In Chhattarpur Women Seeking Men
08448380779 Call Girls In Chhattarpur Women Seeking Men
Ā 
Visa Consultant in Lahore || šŸ“ž03094429236
Visa Consultant in Lahore || šŸ“ž03094429236Visa Consultant in Lahore || šŸ“ž03094429236
Visa Consultant in Lahore || šŸ“ž03094429236
Ā 
Exploring Sicily Your Comprehensive Ebook Travel Guide
Exploring Sicily Your Comprehensive Ebook Travel GuideExploring Sicily Your Comprehensive Ebook Travel Guide
Exploring Sicily Your Comprehensive Ebook Travel Guide
Ā 
DARK TRAVEL AGENCY presented by Khuda Bux
DARK TRAVEL AGENCY presented by Khuda BuxDARK TRAVEL AGENCY presented by Khuda Bux
DARK TRAVEL AGENCY presented by Khuda Bux
Ā 
Top 10 Traditional Indian Handicrafts.pptx
Top 10 Traditional Indian Handicrafts.pptxTop 10 Traditional Indian Handicrafts.pptx
Top 10 Traditional Indian Handicrafts.pptx
Ā 
Call Girls Service !! Indirapuram!! @9999965857 Delhi šŸ«¦ No Advance VVVIP šŸŽ S...
Call Girls Service !! Indirapuram!! @9999965857 Delhi šŸ«¦ No Advance  VVVIP šŸŽ S...Call Girls Service !! Indirapuram!! @9999965857 Delhi šŸ«¦ No Advance  VVVIP šŸŽ S...
Call Girls Service !! Indirapuram!! @9999965857 Delhi šŸ«¦ No Advance VVVIP šŸŽ S...
Ā 
How can I fly with the British Airways Unaccompanied Minor Policy?
How can I fly with the British Airways Unaccompanied Minor Policy?How can I fly with the British Airways Unaccompanied Minor Policy?
How can I fly with the British Airways Unaccompanied Minor Policy?
Ā 
08448380779 Call Girls In Shahdara Women Seeking Men
08448380779 Call Girls In Shahdara Women Seeking Men08448380779 Call Girls In Shahdara Women Seeking Men
08448380779 Call Girls In Shahdara Women Seeking Men
Ā 
Call Girls In Munirka šŸ“± 9999965857 šŸ¤© Delhi šŸ«¦ HOT AND SEXY VVIP šŸŽ SERVICE
Call Girls In Munirka šŸ“±  9999965857  šŸ¤© Delhi šŸ«¦ HOT AND SEXY VVIP šŸŽ SERVICECall Girls In Munirka šŸ“±  9999965857  šŸ¤© Delhi šŸ«¦ HOT AND SEXY VVIP šŸŽ SERVICE
Call Girls In Munirka šŸ“± 9999965857 šŸ¤© Delhi šŸ«¦ HOT AND SEXY VVIP šŸŽ SERVICE
Ā 
char Dham yatra, Uttarakhand tourism.pptx
char Dham yatra, Uttarakhand tourism.pptxchar Dham yatra, Uttarakhand tourism.pptx
char Dham yatra, Uttarakhand tourism.pptx
Ā 
Rohini Sector 18 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 18 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 18 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 18 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Ā 
Akshay Mehndiratta Summer Special Light Meal Ideas From Across India.pptx
Akshay Mehndiratta Summer Special Light Meal Ideas From Across India.pptxAkshay Mehndiratta Summer Special Light Meal Ideas From Across India.pptx
Akshay Mehndiratta Summer Special Light Meal Ideas From Across India.pptx
Ā 
Hoi An Ancient Town, Vietnam (č¶Šå— ęœƒå®‰å¤éŽ®).ppsx
Hoi An Ancient Town, Vietnam (č¶Šå— ęœƒå®‰å¤éŽ®).ppsxHoi An Ancient Town, Vietnam (č¶Šå— ęœƒå®‰å¤éŽ®).ppsx
Hoi An Ancient Town, Vietnam (č¶Šå— ęœƒå®‰å¤éŽ®).ppsx
Ā 
Call Girls šŸ«¤ Connaught Place āž”ļø 9999965857 āž”ļø Delhi šŸ«¦ Russian Escorts FULL ...
Call Girls šŸ«¤ Connaught Place āž”ļø 9999965857  āž”ļø Delhi šŸ«¦  Russian Escorts FULL ...Call Girls šŸ«¤ Connaught Place āž”ļø 9999965857  āž”ļø Delhi šŸ«¦  Russian Escorts FULL ...
Call Girls šŸ«¤ Connaught Place āž”ļø 9999965857 āž”ļø Delhi šŸ«¦ Russian Escorts FULL ...
Ā 
Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779
Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779
Night 7k Call Girls Noida Sector 93 Escorts Call Me: 8448380779
Ā 
visa consultant | šŸ“žšŸ“ž 03094429236 || Best Study Visa Consultant
visa consultant | šŸ“žšŸ“ž 03094429236 || Best Study Visa Consultantvisa consultant | šŸ“žšŸ“ž 03094429236 || Best Study Visa Consultant
visa consultant | šŸ“žšŸ“ž 03094429236 || Best Study Visa Consultant
Ā 

Empfohlen

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
Ā 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
Ā 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
Ā 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
Ā 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
Ā 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
Ā 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
Ā 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
Ā 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
Ā 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
Ā 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
Ā 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
Ā 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
Ā 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data ScienceChristy Abraham Joy
Ā 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
Ā 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
Ā 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
Ā 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
Ā 

Empfohlen (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Ā 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Ā 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
Ā 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
Ā 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Ā 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Ā 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
Ā 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Ā 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Ā 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Ā 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
Ā 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Ā 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Ā 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Ā 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Ā 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Ā 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Ā 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
Ā 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Ā 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Ā 

2011 Db Transactions

  • 1. Transactions Alan Medlar amedlar@cs.ucl.ac.uk
  • 2. Transactions ā€¢ A transaction is a unit of work that is treated in a coherent and reliable manner. All transactions must be independent of one another
  • 3. Transactions ā€¢ A transaction is a unit of work that is treated in a coherent and reliable manner. All transactions must be independent of one another ā€¢ Provide concurrency support (next lecture!)
  • 4. Transactions ā€¢ A transaction is a unit of work that is treated in a coherent and reliable manner. All transactions must be independent of one another ā€¢ Provide concurrency support (next lecture!) ā€¢ Fundamental in computer science
  • 5. Properties ā€¢ Handy mnemonic: ACID ā€¢ Atomicity ā€¢ Consistency ā€¢ Integrity ā€¢ Durability
  • 6. Atomicity ā€¢ Strong guarantee that changes to a database are applied ā€œall or nothingā€
  • 7. Atomicity ā€¢ Strong guarantee that changes to a database are applied ā€œall or nothingā€ ā€¢ Atomicity must be maintained in the face of failures (even from OS, hardware etc...)
  • 8. Atomicity ā€¢ Strong guarantee that changes to a database are applied ā€œall or nothingā€ ā€¢ Atomicity must be maintained in the face of failures (even from OS, hardware etc...) ā€¢ E.g.: move Ā£100 from my bank account to your bank account. If transfer to your account fails, I must be credited back!
  • 9. Consistency ā€¢ Transactions should not violate integrity constraints leaving database in illegal state ā€¢ E.g.: age cannot be negative number
  • 10. Isolation ā€¢ Transactions should not affect one another
  • 11. Isolation ā€¢ Transactions should not affect one another ā€¢ More precisely it deļ¬nes when the changes resulting from a transaction will be seen by other concurrent transactions
  • 12. Durability ā€¢ Outcome of transaction must persist beyond its completion ā€¢ i.e.: given a system crash, the state of the database can be recovered
  • 13. Transaction Example ā€¢ Debit Ā£100 from Aliceā€™s bank account and credit it to Bobā€™s account read(Alice) Alice = Alice - 100 write(Alice) read(Bob) Bob = Bob + 100 write(Bob)
  • 14. Transaction Example ā€¢ Debit Ā£100 from Aliceā€™s bank account and credit it to Bobā€™s account } Ā£1950 Aliceā€™s balance = Ā£2000 Bobā€™s balance = Ā£-50 read(Alice) Alice = Alice - 100 write(Alice) read(Bob) Bob = Bob + 100 write(Bob)
  • 15. Transaction Example ā€¢ Debit Ā£100 from Aliceā€™s bank account and credit it to Bobā€™s account } Ā£1950 Aliceā€™s balance = Ā£2000 Bobā€™s balance = Ā£-50 read(Alice) Alice = Alice - 100 } Ā£1850 Aliceā€™s balance = Ā£1900 write(Alice) Bobā€™s balance = Ā£-50 read(Bob) Bob = Bob + 100 write(Bob)
  • 16. Transaction Example ā€¢ Debit Ā£100 from Aliceā€™s bank account and credit it to Bobā€™s account } Ā£1950 Aliceā€™s balance = Ā£2000 Bobā€™s balance = Ā£-50 read(Alice) Alice = Alice - 100 } Ā£1850 Aliceā€™s balance = Ā£1900 write(Alice) Bobā€™s balance = Ā£-50 read(Bob) Bob = Bob + 100 } Ā£1950 Aliceā€™s balance = Ā£1900 write(Bob) Bobā€™s balance = Ā£50
  • 17. Transaction Example (2) ā€¢ What if Bobā€™s account does not exist? Or permissions are set wrong?
  • 18. Transaction Example (2) ā€¢ What if Bobā€™s account does not exist? Or permissions are set wrong? read(Alice) Alice = Alice - 100 write(Alice) read(Bob) Bob = Bob + 100 write(Bob)
  • 19. Transaction Example (2) ā€¢ What if Bobā€™s account does not exist? Or permissions are set wrong? } Ā£1950 Aliceā€™s balance = Ā£2000 Bobā€™s balance = Ā£-50 read(Alice) Alice = Alice - 100 write(Alice) read(Bob) Bob = Bob + 100 write(Bob)
  • 20. Transaction Example (2) ā€¢ What if Bobā€™s account does not exist? Or permissions are set wrong? } Ā£1950 Aliceā€™s balance = Ā£2000 Bobā€™s balance = Ā£-50 read(Alice) Alice = Alice - 100 } Ā£1850 Aliceā€™s balance = Ā£1900 write(Alice) Bobā€™s balance = Ā£-50 read(Bob) Bob = Bob + 100 write(Bob)
  • 21. Transaction Example (2) ā€¢ What if Bobā€™s account does not exist? Or permissions are set wrong? } Ā£1950 Aliceā€™s balance = Ā£2000 Bobā€™s balance = Ā£-50 read(Alice) Alice = Alice - 100 } Ā£1850 Aliceā€™s balance = Ā£1900 write(Alice) Bobā€™s balance = Ā£-50 read(Bob) Bob = Bob + 100 Read fails, must credit Alice back! write(Bob)
  • 22. Atomicity } Ā£1950 Aliceā€™s balance = Ā£2000 Bobā€™s balance = Ā£-50 read(Alice) Alice = Alice - 100 } Ā£1850 Aliceā€™s balance = Ā£1900 write(Alice) Bobā€™s balance = Ā£-50 read(Bob) Bob = Bob + 100 } Ā£1950 Aliceā€™s balance = Ā£1900 write(Bob) Bobā€™s balance = Ā£50
  • 23. Atomicity Both writes succeed or neither do! } Ā£1950 Aliceā€™s balance = Ā£2000 Bobā€™s balance = Ā£-50 read(Alice) Alice = Alice - 100 } Ā£1850 Aliceā€™s balance = Ā£1900 write(Alice) Bobā€™s balance = Ā£-50 read(Bob) Bob = Bob + 100 } Ā£1950 Aliceā€™s balance = Ā£1900 write(Bob) Bobā€™s balance = Ā£50
  • 24. Consistency } Ā£1950 Aliceā€™s balance = Ā£2000 Bobā€™s balance = Ā£-50 read(Alice) Alice = Alice - 100 } Ā£1850 Aliceā€™s balance = Ā£1900 write(Alice) Bobā€™s balance = Ā£-50 read(Bob) Bob = Bob + 100 } Ā£1950 Aliceā€™s balance = Ā£1900 write(Bob) Bobā€™s balance = Ā£50
  • 25. Consistency Consistent state (no created or missing money!) } Ā£1950 Aliceā€™s balance = Ā£2000 Bobā€™s balance = Ā£-50 read(Alice) Alice = Alice - 100 } Ā£1850 Aliceā€™s balance = Ā£1900 write(Alice) Bobā€™s balance = Ā£-50 read(Bob) Bob = Bob + 100 } Ā£1950 Aliceā€™s balance = Ā£1900 write(Bob) Bobā€™s balance = Ā£50
  • 26. Isolation } Ā£1950 Aliceā€™s balance = Ā£2000 Bobā€™s balance = Ā£-50 read(Alice) Alice = Alice - 100 } Ā£1850 Aliceā€™s balance = Ā£1900 write(Alice) Bobā€™s balance = Ā£-50 read(Bob) Bob = Bob + 100 } Ā£1950 Aliceā€™s balance = Ā£1900 write(Bob) Bobā€™s balance = Ā£50
  • 27. Isolation No other transactions see intermediate values } Ā£1950 Aliceā€™s balance = Ā£2000 Bobā€™s balance = Ā£-50 read(Alice) Alice = Alice - 100 } Ā£1850 Aliceā€™s balance = Ā£1900 write(Alice) Bobā€™s balance = Ā£-50 read(Bob) Bob = Bob + 100 } Ā£1950 Aliceā€™s balance = Ā£1900 write(Bob) Bobā€™s balance = Ā£50
  • 28. Durability ā€¢ Transaction logs used to ensure durability
  • 29. Durability ā€¢ Transaction logs used to ensure durability ā€¢ Log transaction writes, then update database
  • 30. Durability ā€¢ Transaction logs used to ensure durability ā€¢ Log transaction writes, then update database ā€¢ Logs must be written ļ¬rst or else updates can be lost given a system crash!
  • 31. Durability ā€¢ Transaction logs used to ensure durability ā€¢ Log transaction writes, then update database ā€¢ Logs must be written ļ¬rst or else updates can be lost given a system crash! ā€¢ Disks can still fail! (disk mirroring?)
  • 32. Failures ā€¢ Possible failures include: ā€¢ System crash ā€¢ Hardware malfunctions ā€¢ Disk failure ā€¢ Deadlocks ā€¢ System errors: out of memory, program errors (see ā€œman 2 writeā€) ā€¢ etc...
  • 33. State Machine Partial Commit- commit ted Active Failed Aborted
  • 34. State Machine Partial Commit- commit ted Active Initial state Failed Aborted
  • 35. State Machine Last statement processed Partial Commit- commit ted Active Failed Aborted
  • 36. State Machine Partial Commit- commit ted Completion Active (database updated) Failed Aborted
  • 37. State Machine Partial Commit- commit ted Active Failed Aborted Processing can no longer proceed
  • 38. State Machine Partial Commit- commit ted Active Failed Aborted Transaction rolled back to prior state
  • 39. Transaction Logging ā€¢ Transaction start: <T , start> i ā€¢ Transaction write: <T , X ,V ,V > i j 1 2 ā€¢ Transaction commit: <T , commit> i
  • 40. Transaction Logging Transaction ID ā€¢ Transaction start: <T , start> i ā€¢ Transaction write: <T , X ,V ,V > i j 1 2 ā€¢ Transaction commit: <T , commit> i
  • 41. Transaction Logging Transaction ID Data item ID ā€¢ Transaction start: <T , start> i ā€¢ Transaction write: <T , X ,V ,V > i j 1 2 ā€¢ Transaction commit: <T , commit> i
  • 42. Transaction Logging Transaction ID Data item ID ā€¢ Transaction start: <T , start> i ā€¢ Transaction write: <T , X ,V ,V > i j 1 2 ā€¢ Transaction commit: <T , commit> i Data values before and after write
  • 43. Transaction Logging Transaction, ā€˜Tā€™ read(Alice) Alice = Alice - 100 write(Alice) read(Bob) Bob = Bob + 100 write(Bob)
  • 44. Transaction Logging Transaction, ā€˜Tā€™ <T, start> read(Alice) Alice = Alice - 100 <T, Alice, 2000, 1900> write(Alice) read(Bob) Bob = Bob + 100 write(Bob) <T, Bob, -50, 50> <T, commit>
  • 45. Transaction Logging Transaction, ā€˜Tā€™ <T, start> read(Alice) Alice = Alice - 100 <T, Alice, 2000, 1900> write(Alice) read(Bob) Bob = Bob + 100 write(Bob) <T, Bob, -50, 50> <T, commit>
  • 46. Transaction Logging Transaction, ā€˜Tā€™ <T, start> read(Alice) Alice = Alice - 100 <T, Alice, 2000, 1900> write(Alice) read(Bob) Bob = Bob + 100 write(Bob) <T, Bob, -50, 50> <T, commit>
  • 47. Transaction Logging Transaction, ā€˜Tā€™ <T, start> read(Alice) Alice = Alice - 100 <T, Alice, 2000, 1900> write(Alice) read(Bob) Bob = Bob + 100 write(Bob) <T, Bob, -50, 50> <T, commit>
  • 48. Deferred Modiļ¬cation ā€¢ Ensure atomicity by deferring all writes until partial commit of transaction ā€¢ <T , commit> is a partial commit (only i affected log so far, not database) ā€¢ Given logs are in stable storage, writes can be made to the database itself !
  • 49. Failure Recovery ā€¢ If the system fails we can use the transaction log to recover the database ā€¢ For all <T , start>, <T , commit> in log redo i i writes sequentially
  • 50. Recovery Example <T1, start> <T1, Alice, 2000, 1900> <T1, Bob, -50, 50> <T1, commit> <T2, start> <T2, Alice, 1900, 1800> <T3, start>
  • 51. Recovery Example } <T1, start> start and commit <T1, Alice, 2000, 1900> present <T1, Bob, -50, 50> <T1, commit> <T2, start> <T2, Alice, 1900, 1800> <T3, start>
  • 52. Recovery Example <T1, start> Redo <T1, Alice, 2000, 1900> <T1, Bob, -50, 50> <T1, commit> <T2, start> <T2, Alice, 1900, 1800> <T3, start>
  • 53. Recovery Example <T1, start> <T1, Alice, 2000, 1900> Redo <T1, Bob, -50, 50> <T1, commit> <T2, start> <T2, Alice, 1900, 1800> <T3, start>
  • 54. Recovery Example <T1, start> <T1, Alice, 2000, 1900> <T1, Bob, -50, 50> <T1, commit> } <T2, start> <T2, Alice, 1900, 1800> no commit! <T3, start>
  • 55. Immediate Modiļ¬cation ā€¢ Instead of waiting for a commit, we could just perform the writes as they happen (but still post-log writing) ā€¢ Incomplete transactions written to database require old value V1
  • 56. Failure Recovery ā€¢ Again, if the system fails we use the transaction log to recover the database ā€¢ For all <T , start>, <T , commit> in log redo i i database write ā€¢ For all <T , start>, without <T , commit> in i i log undo write
  • 57. Recovery Example <T1, start> <T1, Alice, 2000, 1900> <T1, Bob, -50, 50> <T1, commit> <T2, start> <T2, Alice, 1900, 1800> <T3, start>
  • 58. Recovery Example <T1, start> Redo <T1, Alice, 2000, 1900> <T1, Bob, -50, 50> <T1, commit> <T2, start> <T2, Alice, 1900, 1800> <T3, start>
  • 59. Recovery Example <T1, start> <T1, Alice, 2000, 1900> Redo <T1, Bob, -50, 50> <T1, commit> <T2, start> <T2, Alice, 1900, 1800> <T3, start>
  • 60. Recovery Example <T1, start> <T1, Alice, 2000, 1900> <T1, Bob, -50, 50> <T1, commit> <T2, start> Redo <T2, Alice, 1900, 1800> <T3, start>
  • 61. Recovery Example <T1, start> <T1, Alice, 2000, 1900> <T1, Bob, -50, 50> <T1, commit> <T2, start> <T2, Alice, 1900, 1800> No Commit! <T3, start>
  • 62. Recovery Example <T1, start> <T1, Alice, 2000, 1900> <T1, Bob, -50, 50> <T1, commit> <T2, start> Undo <T2, Alice, 1900, 1800> <T3, start>
  • 63. Check-points ā€¢ Speed up recovery! ā€¢ Create a ā€œcheck-pointā€ to reduce work to be done given a failure ā€¢ Flush all buffers to disk ā€¢ Write <checkpoint> to log ā€¢ On failure: read log until <checkpoint> found, then start recovery

Hinweis der Redaktion