SlideShare uma empresa Scribd logo
1 de 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 defines 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 first 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 first 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 Modification

• 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 Modification

• 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

Mais conteúdo relacionado

Último

Genuine 8250077686 Hot and Beautiful 💕 Diu Escorts call Girls
Genuine 8250077686 Hot and Beautiful 💕 Diu Escorts call GirlsGenuine 8250077686 Hot and Beautiful 💕 Diu Escorts call Girls
Genuine 8250077686 Hot and Beautiful 💕 Diu Escorts call GirlsDeiva Sain Call Girl
 
Papi kondalu Call Girls 8250077686 Service Offer VIP Hot Model
Papi kondalu Call Girls 8250077686 Service Offer VIP Hot ModelPapi kondalu Call Girls 8250077686 Service Offer VIP Hot Model
Papi kondalu Call Girls 8250077686 Service Offer VIP Hot ModelDeiva Sain Call Girl
 
🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...
🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...
🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...Apsara Of India
 
Bhubaneswar Call Girls 8250077686 Service Offer VIP Hot Model
Bhubaneswar Call Girls 8250077686 Service Offer VIP Hot ModelBhubaneswar Call Girls 8250077686 Service Offer VIP Hot Model
Bhubaneswar Call Girls 8250077686 Service Offer VIP Hot ModelDeiva Sain Call Girl
 
Jhargram call girls 📞 8617697112 At Low Cost Cash Payment Booking
Jhargram call girls 📞 8617697112 At Low Cost Cash Payment BookingJhargram call girls 📞 8617697112 At Low Cost Cash Payment Booking
Jhargram call girls 📞 8617697112 At Low Cost Cash Payment BookingNitya salvi
 
Top travel agency in panchkula - Best travel agents in panchkula
Top  travel agency in panchkula - Best travel agents in panchkulaTop  travel agency in panchkula - Best travel agents in panchkula
Top travel agency in panchkula - Best travel agents in panchkulauseyourbrain1122
 
sample sample sample sample sample sample
sample sample sample sample sample samplesample sample sample sample sample sample
sample sample sample sample sample sampleCasey Keith
 
Night 7k to 12k Lahaul and Spiti Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Esco...
Night 7k to 12k Lahaul and Spiti Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Esco...Night 7k to 12k Lahaul and Spiti Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Esco...
Night 7k to 12k Lahaul and Spiti Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Esco...Nitya salvi
 
Genuine 8250077686 Hot and Beautiful 💕 Chennai Escorts call Girls
Genuine 8250077686 Hot and Beautiful 💕 Chennai Escorts call GirlsGenuine 8250077686 Hot and Beautiful 💕 Chennai Escorts call Girls
Genuine 8250077686 Hot and Beautiful 💕 Chennai Escorts call GirlsDeiva Sain Call Girl
 
Genuine 8250077686 Hot and Beautiful 💕 Hosur Escorts call Girls
Genuine 8250077686 Hot and Beautiful 💕 Hosur Escorts call GirlsGenuine 8250077686 Hot and Beautiful 💕 Hosur Escorts call Girls
Genuine 8250077686 Hot and Beautiful 💕 Hosur Escorts call GirlsDeiva Sain Call Girl
 
Genuine 9332606886 Hot and Beautiful 💕 Bilaspur Escorts call Girls
Genuine 9332606886 Hot and Beautiful 💕 Bilaspur Escorts call GirlsGenuine 9332606886 Hot and Beautiful 💕 Bilaspur Escorts call Girls
Genuine 9332606886 Hot and Beautiful 💕 Bilaspur Escorts call GirlsDeiva Sain Call Girl
 
Kanpur Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Kanpur Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort ServiceKanpur Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Kanpur Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort ServiceDamini Dixit
 
High Profile 🔝 8250077686 📞 Call Girls Service in Siri Fort🍑
High Profile 🔝 8250077686 📞 Call Girls Service in Siri Fort🍑High Profile 🔝 8250077686 📞 Call Girls Service in Siri Fort🍑
High Profile 🔝 8250077686 📞 Call Girls Service in Siri Fort🍑Damini Dixit
 
Alipore Call Girls - 📞 8617697112 🔝 Top Class Call Girls Service Available
Alipore Call Girls - 📞 8617697112 🔝 Top Class Call Girls Service AvailableAlipore Call Girls - 📞 8617697112 🔝 Top Class Call Girls Service Available
Alipore Call Girls - 📞 8617697112 🔝 Top Class Call Girls Service AvailableNitya salvi
 
Genuine 9332606886 Hot and Beautiful 💕 Pune Escorts call Girls
Genuine 9332606886 Hot and Beautiful 💕 Pune Escorts call GirlsGenuine 9332606886 Hot and Beautiful 💕 Pune Escorts call Girls
Genuine 9332606886 Hot and Beautiful 💕 Pune Escorts call GirlsDeiva Sain Call Girl
 
WhatsApp Chat: 📞 8617697112 Hire Call Girls Cooch Behar For a Sensual Sex Exp...
WhatsApp Chat: 📞 8617697112 Hire Call Girls Cooch Behar For a Sensual Sex Exp...WhatsApp Chat: 📞 8617697112 Hire Call Girls Cooch Behar For a Sensual Sex Exp...
WhatsApp Chat: 📞 8617697112 Hire Call Girls Cooch Behar For a Sensual Sex Exp...Nitya salvi
 
Are Vatican Museum Tickets and Private Tours Worth It
Are Vatican Museum Tickets and Private Tours Worth ItAre Vatican Museum Tickets and Private Tours Worth It
Are Vatican Museum Tickets and Private Tours Worth Itvaticanguidedtour
 
Top places to visit, top tourist destinations
Top places to visit, top tourist destinationsTop places to visit, top tourist destinations
Top places to visit, top tourist destinationsswarajdm34
 
Tamluk ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Tamluk ESCORT SERVICE❤CALL GIRL
Tamluk ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Tamluk ESCORT SERVICE❤CALL GIRLTamluk ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Tamluk ESCORT SERVICE❤CALL GIRL
Tamluk ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Tamluk ESCORT SERVICE❤CALL GIRLNitya salvi
 

Último (20)

Genuine 8250077686 Hot and Beautiful 💕 Diu Escorts call Girls
Genuine 8250077686 Hot and Beautiful 💕 Diu Escorts call GirlsGenuine 8250077686 Hot and Beautiful 💕 Diu Escorts call Girls
Genuine 8250077686 Hot and Beautiful 💕 Diu Escorts call Girls
 
Papi kondalu Call Girls 8250077686 Service Offer VIP Hot Model
Papi kondalu Call Girls 8250077686 Service Offer VIP Hot ModelPapi kondalu Call Girls 8250077686 Service Offer VIP Hot Model
Papi kondalu Call Girls 8250077686 Service Offer VIP Hot Model
 
🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...
🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...
🔥HOT🔥📲9602870969🔥Prostitute Service in Udaipur Call Girls in City Palace Lake...
 
Bhubaneswar Call Girls 8250077686 Service Offer VIP Hot Model
Bhubaneswar Call Girls 8250077686 Service Offer VIP Hot ModelBhubaneswar Call Girls 8250077686 Service Offer VIP Hot Model
Bhubaneswar Call Girls 8250077686 Service Offer VIP Hot Model
 
Jhargram call girls 📞 8617697112 At Low Cost Cash Payment Booking
Jhargram call girls 📞 8617697112 At Low Cost Cash Payment BookingJhargram call girls 📞 8617697112 At Low Cost Cash Payment Booking
Jhargram call girls 📞 8617697112 At Low Cost Cash Payment Booking
 
Top travel agency in panchkula - Best travel agents in panchkula
Top  travel agency in panchkula - Best travel agents in panchkulaTop  travel agency in panchkula - Best travel agents in panchkula
Top travel agency in panchkula - Best travel agents in panchkula
 
sample sample sample sample sample sample
sample sample sample sample sample samplesample sample sample sample sample sample
sample sample sample sample sample sample
 
Night 7k to 12k Lahaul and Spiti Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Esco...
Night 7k to 12k Lahaul and Spiti Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Esco...Night 7k to 12k Lahaul and Spiti Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Esco...
Night 7k to 12k Lahaul and Spiti Call Girls 👉👉 8617697112⭐⭐ 100% Genuine Esco...
 
Genuine 8250077686 Hot and Beautiful 💕 Chennai Escorts call Girls
Genuine 8250077686 Hot and Beautiful 💕 Chennai Escorts call GirlsGenuine 8250077686 Hot and Beautiful 💕 Chennai Escorts call Girls
Genuine 8250077686 Hot and Beautiful 💕 Chennai Escorts call Girls
 
Genuine 8250077686 Hot and Beautiful 💕 Hosur Escorts call Girls
Genuine 8250077686 Hot and Beautiful 💕 Hosur Escorts call GirlsGenuine 8250077686 Hot and Beautiful 💕 Hosur Escorts call Girls
Genuine 8250077686 Hot and Beautiful 💕 Hosur Escorts call Girls
 
Genuine 9332606886 Hot and Beautiful 💕 Bilaspur Escorts call Girls
Genuine 9332606886 Hot and Beautiful 💕 Bilaspur Escorts call GirlsGenuine 9332606886 Hot and Beautiful 💕 Bilaspur Escorts call Girls
Genuine 9332606886 Hot and Beautiful 💕 Bilaspur Escorts call Girls
 
Kanpur Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Kanpur Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort ServiceKanpur Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
Kanpur Call Girls Service ☎ ️82500–77686 ☎️ Enjoy 24/7 Escort Service
 
High Profile 🔝 8250077686 📞 Call Girls Service in Siri Fort🍑
High Profile 🔝 8250077686 📞 Call Girls Service in Siri Fort🍑High Profile 🔝 8250077686 📞 Call Girls Service in Siri Fort🍑
High Profile 🔝 8250077686 📞 Call Girls Service in Siri Fort🍑
 
CYTOTEC DUBAI ☎️ +966572737505 } Abortion pills in Abu dhabi,get misoprostal ...
CYTOTEC DUBAI ☎️ +966572737505 } Abortion pills in Abu dhabi,get misoprostal ...CYTOTEC DUBAI ☎️ +966572737505 } Abortion pills in Abu dhabi,get misoprostal ...
CYTOTEC DUBAI ☎️ +966572737505 } Abortion pills in Abu dhabi,get misoprostal ...
 
Alipore Call Girls - 📞 8617697112 🔝 Top Class Call Girls Service Available
Alipore Call Girls - 📞 8617697112 🔝 Top Class Call Girls Service AvailableAlipore Call Girls - 📞 8617697112 🔝 Top Class Call Girls Service Available
Alipore Call Girls - 📞 8617697112 🔝 Top Class Call Girls Service Available
 
Genuine 9332606886 Hot and Beautiful 💕 Pune Escorts call Girls
Genuine 9332606886 Hot and Beautiful 💕 Pune Escorts call GirlsGenuine 9332606886 Hot and Beautiful 💕 Pune Escorts call Girls
Genuine 9332606886 Hot and Beautiful 💕 Pune Escorts call Girls
 
WhatsApp Chat: 📞 8617697112 Hire Call Girls Cooch Behar For a Sensual Sex Exp...
WhatsApp Chat: 📞 8617697112 Hire Call Girls Cooch Behar For a Sensual Sex Exp...WhatsApp Chat: 📞 8617697112 Hire Call Girls Cooch Behar For a Sensual Sex Exp...
WhatsApp Chat: 📞 8617697112 Hire Call Girls Cooch Behar For a Sensual Sex Exp...
 
Are Vatican Museum Tickets and Private Tours Worth It
Are Vatican Museum Tickets and Private Tours Worth ItAre Vatican Museum Tickets and Private Tours Worth It
Are Vatican Museum Tickets and Private Tours Worth It
 
Top places to visit, top tourist destinations
Top places to visit, top tourist destinationsTop places to visit, top tourist destinations
Top places to visit, top tourist destinations
 
Tamluk ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Tamluk ESCORT SERVICE❤CALL GIRL
Tamluk ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Tamluk ESCORT SERVICE❤CALL GIRLTamluk ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Tamluk ESCORT SERVICE❤CALL GIRL
Tamluk ❤CALL GIRL 8617697112 ❤CALL GIRLS IN Tamluk ESCORT SERVICE❤CALL GIRL
 

Destaque

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
 
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
 

Destaque (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 defines 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 first 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 first 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 Modification • 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 Modification • 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

Notas do Editor