SlideShare a Scribd company logo
Concurrent Transactions
          Alan Medlar

      amedlar@cs.ucl.ac.uk
Concurrent Transactions
• We want our database to be accessible to
  many clients concurrently
 • Multiple processors or cores accessing
    same storage (containing whole database)
 • Multiple processors distributed over a
    network each with local storage (each
    holding a portion of the database)
Concurrent Transactions

• To increase performance we want to allow
  multiple database transactions, being
  processed on separate processors, to take
  place at once
• Run into problems when two (or more) of
  these transactions want to access the same
  data!
Schedules


• Concerned with the order of execution
• Consider two transactions, T and T :
                            1      2
T1          T2           T1            T2
 read(X)                                read(X)
X = X-100                             tmp = X*0.1
 write(X)                              X=X-tmp
 read(Y)                                write(X)
Y = Y+100                               read(Y)
 write(Y)                              Y=Y+tmp
              read(X)                   write(Y)
            tmp = X*0.1    read(X)
             X=X-tmp      X = X-100
              write(X)     write(X)
              read(Y)      read(Y)
             Y=Y+tmp      Y = Y+100
              write(Y)     write(Y)
Schedules

• Schedules of T  and T2 are serial due to
                1
  one transaction finishing before the other
• If Tand T2 were to happen at the same
     1
  time, forcing serialisation would limit
  performance!
T1          T2
 read(X)
X = X-100
 write(X)
              read(X)
            tmp = X*0.1
             X=X-tmp
              write(X)
 read(Y)
Y = Y+100
 write(Y)
              read(Y)
             Y=Y+tmp
             write(Y)
T1          T2
                         read(X)
                        X = X-100
                         write(X)
Despite these                         read(X)
transactions not                    tmp = X*0.1
being serialised, the                X=X-tmp
schedule ensures the                  write(X)
resulting database is    read(Y)
consistent              Y = Y+100
                         write(Y)
                                      read(Y)
                                     Y=Y+tmp
                                     write(Y)
T1          T2
 read(X)
X = X-100
              read(X)
            tmp = X*0.1
             X=X-tmp
              write(X)
 write(X)
 read(Y)
Y = Y+100
 write(Y)
              read(Y)
             Y=Y+tmp
             write(Y)
T1          T2
                        read(X)
                       X = X-100
                                     read(X)
Here the database
                                   tmp = X*0.1
gets into an
                                    X=X-tmp
inconsistent state
                                     write(X)
because the write(X)
                        write(X)
of T2 is lost due to
                        read(Y)
being overwritten by
                       Y = Y+100
T1!
                        write(Y)
                                     read(Y)
                                    Y=Y+tmp
                                    write(Y)
Conflict Analysis
•   What went wrong in the example?
    •   Ordering of reads and writes caused an inconsistency
Conflict Analysis
•   What went wrong in the example?
    •   Ordering of reads and writes caused an inconsistency
•   Use conflict analysis to identify the cause of the
    problem...
    •   Intuition: reads and writes applied in the same order as
        a serial schedule will always result in a consistent state
    •   Examine the schedule and try to rearrange them into
        the same order as a serial schedule by swapping
        instructions (paying special attention to “conflicts”)
Conflicts
• Looking consecutive reads and writes:
  • If they access different data items, they can
     be applied in any order
  • If they access the same data items, then
     the order of operations may be
     important, i.e. they may conflict
Conflicts
• Looking consecutive reads and writes:
  • If they access different data items, they can
     be applied in any order
  • If they access the same data items, then
     the order of operations may be
     important, i.e. they may conflict
• (This is simplified! We are not considering
  insertion and deletion)
Conflict Rules
•   In a schedule (only reads and writes) for consecutive
    instructions i1 and i2 :
    •   i1 = read(x), i2 = read(x) : no conflict
    •   i1 = read(x), i2 = write(x) : conflict
        (ordering dictates whether i1 gets value of write or
        previous state)
    •   i1 = write(x), i2 = read(x) : conflict
    •   i1 = write(x), i2 = write(x) : conflict
        (writes do not affect one another, but will affect next
        read)
Conflict Serialization
•   If a schedule S is transformed into schedule S’
    by a series of non-conflicting instruction
    swaps, the S and S’ are conflict equivalent
•   A schedule is conflict serializable if it is conflict
    equivalent to a serial schedule
•   A schedule that is conflict serializable will
    produce the same final state as some serial
    schedule and will leave the database in a
    consistent state
T1          T2
 read(X)
X = X-100
 write(X)
              read(X)
            tmp = X*0.1
             X=X-tmp
              write(X)
 read(Y)
Y = Y+100
 write(Y)
              read(Y)
             Y=Y+tmp
             write(Y)
T1          T2
 read(X)
X = X-100
 write(X)
              read(X)
            tmp = X*0.1
             X=X-tmp
              write(X)
 read(Y)
Y = Y+100
 write(Y)
              read(Y)
             Y=Y+tmp
             write(Y)
T1          T2
 read(X)
X = X-100
 write(X)
              read(X)
            tmp = X*0.1
             X=X-tmp
              write(X)
 read(Y)
Y = Y+100
 write(Y)
              read(Y)
             Y=Y+tmp
             write(Y)
T1          T2            T1          T2
 read(X)                   read(X)
X = X-100                 X = X-100
 write(X)                  write(X)
              read(X)      read(Y)
            tmp = X*0.1   Y = Y+100
             X=X-tmp       write(Y)
              write(X)                  read(X)
 read(Y)                              tmp = X*0.1
Y = Y+100                              X=X-tmp
 write(Y)                               write(X)
              read(Y)                   read(Y)
             Y=Y+tmp                   Y=Y+tmp
             write(Y)                   write(Y)
T1          T2
 read(X)
X = X-100
              read(X)
            tmp = X*0.1
             X=X-tmp
              write(X)
 write(X)
 read(Y)
Y = Y+100
 write(Y)
              read(Y)
             Y=Y+tmp
             write(Y)
T1          T2
                        read(X)
                       X = X-100
                                     read(X)
These instructions
                                   tmp = X*0.1
cannot be swapped
                                    X=X-tmp
because they are in
                                     write(X)
conflict!
                        write(X)
This schedule cannot    read(Y)
be re-ordered into a   Y = Y+100
serial schedule...      write(Y)
                                     read(Y)
                                    Y=Y+tmp
                                    write(Y)
Serializability

• Paramount correctness criteria for
  concurrent database transactions
• Ensures isolation between transactions
• Ensures consistency despite other
  transactions
Locking
•   We can get a serialisable schedule by
    enforcing mutual exclusion on data items: this
    could be achieved using simple locking
    •   shared lock - to read data items, can only
        be granted if there are either no locks or
        only shared locks on a data item
    •   write lock - for writing, can only be granted
        if there are no other locks on the data item
T1             T2
write_lock(X)
   read(X)
 X = X-100
  write(X)
 unlock(X)
                write_lock(X)
                   read(X)
                tmp = X*0.1
                 X=X-tmp
                  write(X)
                 unlock(X)
write_lock(Y)
   read(Y)
 Y = Y+100
  write(Y)
 unlock(Y)
                write_lock(Y)
                   read(Y)
                 Y=Y+tmp
                  write(Y)
                 unlock(Y)
T1             T2               T1             T2
write_lock(X)                   write_lock(X)
   read(X)                         read(X)
 X = X-100                       X = X-100
  write(X)                                      write_lock(X)
 unlock(X)                                         read(X)
                write_lock(X)                   tmp = X*0.1
                   read(X)                       X=X-tmp
                tmp = X*0.1                       write(X)
                 X=X-tmp                         unlock(X)
                  write(X)        write(X)
                 unlock(X)       unlock(X)
write_lock(Y)                   write_lock(Y)
   read(Y)                         read(Y)
 Y = Y+100                       Y = Y+100
  write(Y)                        write(Y)
 unlock(Y)                       unlock(Y)
                write_lock(Y)                   write_lock(Y)
                   read(Y)                         read(Y)
                 Y=Y+tmp                         Y=Y+tmp
                  write(Y)                        write(Y)
                 unlock(Y)                       unlock(Y)
T1             T2               T1               T2
write_lock(X)                   write_lock(X)
   read(X)                         read(X)
 X = X-100                       X = X-100
  write(X)                                        write_lock(X)

                                             s!
 unlock(X)                                           read(X)
                                         ail
                                       f
                write_lock(X)                     tmp = X*0.1
                                     k
                                   oc
                   read(X)                         X=X-tmp
                                 l
                tmp = X*0.1                         write(X)
                 X=X-tmp                           unlock(X)
                  write(X)        write(X)
                 unlock(X)       unlock(X)
write_lock(Y)                   write_lock(Y)
   read(Y)                         read(Y)
 Y = Y+100                       Y = Y+100
  write(Y)                        write(Y)
 unlock(Y)                       unlock(Y)
                write_lock(Y)                     write_lock(Y)
                   read(Y)                           read(Y)
                 Y=Y+tmp                           Y=Y+tmp
                  write(Y)                          write(Y)
                 unlock(Y)                         unlock(Y)
Problem: Immediate Modification



• If during a transaction our database uses
  immediate modification we have a
  problem, transactions are not isolated!
T1                  T2
write-lock(P)
   read(P)
 P = P - 100
  write(P)
  unlock(P)
                    read-lock(P)
                      read(P)
                     unlock(P)
                    read-lock(Q)
                      read(Q)
                     unlock(Q)
                printf(“%dn”, P + Q)
write-lock(Q)
  read(Q)
Q = Q + 100
  write(Q)
 unlock(Q)
T1                  T2

                                                  }
                                        P = 100
                                                      150
write-lock(P)
                                        Q = 50
   read(P)
 P = P - 100
  write(P)
  unlock(P)
                    read-lock(P)
                      read(P)
                     unlock(P)
                    read-lock(Q)
                      read(Q)
                     unlock(Q)
                printf(“%dn”, P + Q)
write-lock(Q)
  read(Q)
Q = Q + 100
  write(Q)
 unlock(Q)
T1                  T2

                                                  }
                                        P = 100
                                                      150
write-lock(P)
                                        Q = 50
   read(P)
 P = P - 100
  write(P)

                                                  }
                                        P= 0
                                                      50
  unlock(P)
                                        Q = 50
                    read-lock(P)
                      read(P)
                     unlock(P)
                    read-lock(Q)
                      read(Q)
                     unlock(Q)
                printf(“%dn”, P + Q)
write-lock(Q)
  read(Q)
Q = Q + 100
  write(Q)
 unlock(Q)
T1                  T2

                                                  }
                                        P = 100
                                                      150
write-lock(P)
                                        Q = 50
   read(P)
 P = P - 100
  write(P)

                                                  }
                                        P= 0
                                                      50
  unlock(P)
                                        Q = 50
                    read-lock(P)
                      read(P)
                     unlock(P)
                    read-lock(Q)
                      read(Q)
                     unlock(Q)
                printf(“%dn”, P + Q)
write-lock(Q)
  read(Q)
Q = Q + 100
  write(Q)

                                                  }
                                        P= 0
                                                      150
 unlock(Q)
                                        Q = 150
T1                  T2
write-lock(P)
   read(P)
 P = P - 100
                                         Solution: release locks
  write(P)

                                           as late as possible!
write-lock(Q)
  read(Q)
                                        (ensures serial schedule,
Q = Q + 100

                                        but potential deadlocks!)
  write(Q)
 unlock(Q)
  unlock(P)
                    read-lock(P)
                      read(P)
                    read-lock(Q)
                      read(Q)
                     unlock(Q)
                     unlock(P)
                printf(“%dn”, P + Q)
2-Phase Locking
•   One of many methods to ensure serializability


•   Growth phase: transactions can only acquire
    locks
•   Shrinking phase: transactions can only release
    locks
•   Once a transaction has started to release locks
    it cannot acquire anymore...
T1                  T2
T1 Growth Phase      write-lock(P)
                        read(P)
                      P = P - 100
                       write(P)
                     write-lock(Q)
                       read(Q)
                     Q = Q + 100
                       write(Q)
T1 Shrinking Phase    unlock(Q)
                       unlock(P)
                                                             T2 Growth Phase
                                         read-lock(P)
                                           read(P)
                                         read-lock(Q)
                                           read(Q)
                                                             T2 Shrinking Phase
                                          unlock(Q)
                                          unlock(P)
                                     printf(“%dn”, P + Q)
Deadlock

• Two or more transactions are waiting for
  locks that the other holds, hence none of
  those involved make progress
• Dealt with in different ways, not covered in
  this course...
Summary

• Most concurrent transactions have no
  conflicts: they either all access different
  data items or else only perform reads
• For the transactions that might conflict we
  can enforce serializability to maintain the
  ACID properties
Next: Distributed Transactions

More Related Content

What's hot

Prml
PrmlPrml
Prml
syou6162
 
Hashing Part One
Hashing Part OneHashing Part One
Hashing Part One
Benjamin Sach
 
Slides mc gill-v4
Slides mc gill-v4Slides mc gill-v4
Slides mc gill-v4
Arthur Charpentier
 
Predicates and Quantifiers
Predicates and QuantifiersPredicates and Quantifiers
Predicates and Quantifiers
blaircomp2003
 
Matrix calculus
Matrix calculusMatrix calculus
Matrix calculus
Sungbin Lim
 
Harmonic Analysis and Deep Learning
Harmonic Analysis and Deep LearningHarmonic Analysis and Deep Learning
Harmonic Analysis and Deep Learning
Sungbin Lim
 
Lesson 32: The Fundamental Theorem Of Calculus
Lesson 32: The Fundamental Theorem Of CalculusLesson 32: The Fundamental Theorem Of Calculus
Lesson 32: The Fundamental Theorem Of Calculus
Matthew Leingang
 
Predicate & quantifier
Predicate & quantifierPredicate & quantifier
Predicate & quantifier
University of Potsdam
 
Quantifier
QuantifierQuantifier
Predicates and Quantifiers
Predicates and Quantifiers Predicates and Quantifiers
Predicates and Quantifiers
Istiak Ahmed
 
Lesson 16: Derivatives of Exponential and Logarithmic Functions
Lesson 16: Derivatives of Exponential and Logarithmic FunctionsLesson 16: Derivatives of Exponential and Logarithmic Functions
Lesson 16: Derivatives of Exponential and Logarithmic Functions
Matthew Leingang
 
09d transform & conquer spring2015
09d transform & conquer spring201509d transform & conquer spring2015
09d transform & conquer spring2015
Hira Gul
 
Deep generative model.pdf
Deep generative model.pdfDeep generative model.pdf
Deep generative model.pdf
Hyungjoo Cho
 
Lecture 2 predicates quantifiers and rules of inference
Lecture 2 predicates quantifiers and rules of inferenceLecture 2 predicates quantifiers and rules of inference
Lecture 2 predicates quantifiers and rules of inference
asimnawaz54
 
Largedictionaries handout
Largedictionaries handoutLargedictionaries handout
Largedictionaries handout
csedays
 
Slides mc gill-v3
Slides mc gill-v3Slides mc gill-v3
Slides mc gill-v3
Arthur Charpentier
 
1 hofstad
1 hofstad1 hofstad
1 hofstad
Yandex
 
Hashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo HashingHashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo Hashing
Benjamin Sach
 

What's hot (18)

Prml
PrmlPrml
Prml
 
Hashing Part One
Hashing Part OneHashing Part One
Hashing Part One
 
Slides mc gill-v4
Slides mc gill-v4Slides mc gill-v4
Slides mc gill-v4
 
Predicates and Quantifiers
Predicates and QuantifiersPredicates and Quantifiers
Predicates and Quantifiers
 
Matrix calculus
Matrix calculusMatrix calculus
Matrix calculus
 
Harmonic Analysis and Deep Learning
Harmonic Analysis and Deep LearningHarmonic Analysis and Deep Learning
Harmonic Analysis and Deep Learning
 
Lesson 32: The Fundamental Theorem Of Calculus
Lesson 32: The Fundamental Theorem Of CalculusLesson 32: The Fundamental Theorem Of Calculus
Lesson 32: The Fundamental Theorem Of Calculus
 
Predicate & quantifier
Predicate & quantifierPredicate & quantifier
Predicate & quantifier
 
Quantifier
QuantifierQuantifier
Quantifier
 
Predicates and Quantifiers
Predicates and Quantifiers Predicates and Quantifiers
Predicates and Quantifiers
 
Lesson 16: Derivatives of Exponential and Logarithmic Functions
Lesson 16: Derivatives of Exponential and Logarithmic FunctionsLesson 16: Derivatives of Exponential and Logarithmic Functions
Lesson 16: Derivatives of Exponential and Logarithmic Functions
 
09d transform & conquer spring2015
09d transform & conquer spring201509d transform & conquer spring2015
09d transform & conquer spring2015
 
Deep generative model.pdf
Deep generative model.pdfDeep generative model.pdf
Deep generative model.pdf
 
Lecture 2 predicates quantifiers and rules of inference
Lecture 2 predicates quantifiers and rules of inferenceLecture 2 predicates quantifiers and rules of inference
Lecture 2 predicates quantifiers and rules of inference
 
Largedictionaries handout
Largedictionaries handoutLargedictionaries handout
Largedictionaries handout
 
Slides mc gill-v3
Slides mc gill-v3Slides mc gill-v3
Slides mc gill-v3
 
1 hofstad
1 hofstad1 hofstad
1 hofstad
 
Hashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo HashingHashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo Hashing
 

Viewers also liked

2011 Db Concurrency
2011 Db Concurrency2011 Db Concurrency
2011 Db Concurrency
atali
 
Learnt Technologies
Learnt TechnologiesLearnt Technologies
Learnt Technologies
Clunkasaurous_Rex
 
Autoerus - Automobiliu Servisas 03 26
Autoerus - Automobiliu Servisas 03 26Autoerus - Automobiliu Servisas 03 26
Autoerus - Automobiliu Servisas 03 26
OpenCoffee Club Vilnius
 
ScimoreDB - Enterprise level database
ScimoreDB - Enterprise level databaseScimoreDB - Enterprise level database
ScimoreDB - Enterprise level database
OpenCoffee Club Vilnius
 
OCC Vilnius - Investuotojai Ir Parama Idėjai
OCC Vilnius - Investuotojai Ir Parama IdėjaiOCC Vilnius - Investuotojai Ir Parama Idėjai
OCC Vilnius - Investuotojai Ir Parama Idėjai
OpenCoffee Club Vilnius
 
Money Watch - Finansai telefone
Money Watch - Finansai telefoneMoney Watch - Finansai telefone
Money Watch - Finansai telefone
OpenCoffee Club Vilnius
 
Vaziuojam.lt
Vaziuojam.ltVaziuojam.lt
Operation dic
Operation dicOperation dic
Operation dic
gnchavhan
 
Basketball Zone
Basketball ZoneBasketball Zone
Basketball Zone
OpenCoffee Club Vilnius
 
2011 Db Distributed
2011 Db Distributed2011 Db Distributed
2011 Db Distributed
atali
 
Mobiliosios Sferos Tendencijos Ir Galimybes
Mobiliosios Sferos Tendencijos Ir GalimybesMobiliosios Sferos Tendencijos Ir Galimybes
Mobiliosios Sferos Tendencijos Ir Galimybes
OpenCoffee Club Vilnius
 
OCC Vilnius - 3 Men. Veiklos Apžvalga
OCC Vilnius - 3 Men. Veiklos ApžvalgaOCC Vilnius - 3 Men. Veiklos Apžvalga
OCC Vilnius - 3 Men. Veiklos Apžvalga
OpenCoffee Club Vilnius
 
2011 Db Intro
2011 Db Intro2011 Db Intro
2011 Db Intro
atali
 
Marketing Design Portfolio
Marketing Design PortfolioMarketing Design Portfolio
Marketing Design Portfolio
Elizabeth Campbell
 
M. Golivkin - Entreprenerystės Ekosistema
M. Golivkin - Entreprenerystės EkosistemaM. Golivkin - Entreprenerystės Ekosistema
M. Golivkin - Entreprenerystės Ekosistema
OpenCoffee Club Vilnius
 
2011 Db Transactions
2011 Db Transactions2011 Db Transactions
2011 Db Transactions
atali
 
APP DESIGN by WIZARD INTERACTIVE
APP DESIGN by WIZARD INTERACTIVEAPP DESIGN by WIZARD INTERACTIVE
APP DESIGN by WIZARD INTERACTIVE
Elizabeth Campbell
 
Cloud Slam Co D Presentation
Cloud Slam Co D PresentationCloud Slam Co D Presentation
Cloud Slam Co D Presentation
Srini Chari, PhD., MBA.
 
Target Audience/ Attracting Audience
Target Audience/ Attracting AudienceTarget Audience/ Attracting Audience
Target Audience/ Attracting Audience
Clunkasaurous_Rex
 

Viewers also liked (19)

2011 Db Concurrency
2011 Db Concurrency2011 Db Concurrency
2011 Db Concurrency
 
Learnt Technologies
Learnt TechnologiesLearnt Technologies
Learnt Technologies
 
Autoerus - Automobiliu Servisas 03 26
Autoerus - Automobiliu Servisas 03 26Autoerus - Automobiliu Servisas 03 26
Autoerus - Automobiliu Servisas 03 26
 
ScimoreDB - Enterprise level database
ScimoreDB - Enterprise level databaseScimoreDB - Enterprise level database
ScimoreDB - Enterprise level database
 
OCC Vilnius - Investuotojai Ir Parama Idėjai
OCC Vilnius - Investuotojai Ir Parama IdėjaiOCC Vilnius - Investuotojai Ir Parama Idėjai
OCC Vilnius - Investuotojai Ir Parama Idėjai
 
Money Watch - Finansai telefone
Money Watch - Finansai telefoneMoney Watch - Finansai telefone
Money Watch - Finansai telefone
 
Vaziuojam.lt
Vaziuojam.ltVaziuojam.lt
Vaziuojam.lt
 
Operation dic
Operation dicOperation dic
Operation dic
 
Basketball Zone
Basketball ZoneBasketball Zone
Basketball Zone
 
2011 Db Distributed
2011 Db Distributed2011 Db Distributed
2011 Db Distributed
 
Mobiliosios Sferos Tendencijos Ir Galimybes
Mobiliosios Sferos Tendencijos Ir GalimybesMobiliosios Sferos Tendencijos Ir Galimybes
Mobiliosios Sferos Tendencijos Ir Galimybes
 
OCC Vilnius - 3 Men. Veiklos Apžvalga
OCC Vilnius - 3 Men. Veiklos ApžvalgaOCC Vilnius - 3 Men. Veiklos Apžvalga
OCC Vilnius - 3 Men. Veiklos Apžvalga
 
2011 Db Intro
2011 Db Intro2011 Db Intro
2011 Db Intro
 
Marketing Design Portfolio
Marketing Design PortfolioMarketing Design Portfolio
Marketing Design Portfolio
 
M. Golivkin - Entreprenerystės Ekosistema
M. Golivkin - Entreprenerystės EkosistemaM. Golivkin - Entreprenerystės Ekosistema
M. Golivkin - Entreprenerystės Ekosistema
 
2011 Db Transactions
2011 Db Transactions2011 Db Transactions
2011 Db Transactions
 
APP DESIGN by WIZARD INTERACTIVE
APP DESIGN by WIZARD INTERACTIVEAPP DESIGN by WIZARD INTERACTIVE
APP DESIGN by WIZARD INTERACTIVE
 
Cloud Slam Co D Presentation
Cloud Slam Co D PresentationCloud Slam Co D Presentation
Cloud Slam Co D Presentation
 
Target Audience/ Attracting Audience
Target Audience/ Attracting AudienceTarget Audience/ Attracting Audience
Target Audience/ Attracting Audience
 

Similar to 2011 Db Concurrency

Taylor problem
Taylor problemTaylor problem
Taylor problem
dinhmyhuyenvi
 
Engr 213 midterm 1b sol 2009
Engr 213 midterm 1b sol 2009Engr 213 midterm 1b sol 2009
Engr 213 midterm 1b sol 2009
akabaka12
 
Hw2 s
Hw2 sHw2 s
Hw2 s
Nick Nick
 
Koc2(dba)
Koc2(dba)Koc2(dba)
Koc2(dba)
Serhat Yucel
 
Varian, microeconomic analysis, solution book
Varian, microeconomic analysis, solution bookVarian, microeconomic analysis, solution book
Varian, microeconomic analysis, solution book
José Antonio PAYANO YALE
 
stochastic processes assignment help
stochastic processes assignment helpstochastic processes assignment help
stochastic processes assignment help
Statistics Homework Helper
 
Intro probability 2
Intro probability 2Intro probability 2
Intro probability 2
Phong Vo
 
Lesson 27: Integration by Substitution (slides)
Lesson 27: Integration by Substitution (slides)Lesson 27: Integration by Substitution (slides)
Lesson 27: Integration by Substitution (slides)
Mel Anthony Pepito
 
Lesson 27: Integration by Substitution (slides)
Lesson 27: Integration by Substitution (slides)Lesson 27: Integration by Substitution (slides)
Lesson 27: Integration by Substitution (slides)
Matthew Leingang
 
03 truncation errors
03 truncation errors03 truncation errors
03 truncation errors
maheej
 
1 - Linear Regression
1 - Linear Regression1 - Linear Regression
1 - Linear Regression
Nikita Zhiltsov
 
Interpolation techniques - Background and implementation
Interpolation techniques - Background and implementationInterpolation techniques - Background and implementation
Interpolation techniques - Background and implementation
Quasar Chunawala
 
Emat 213 study guide
Emat 213 study guideEmat 213 study guide
Emat 213 study guide
akabaka12
 
Lesson 29: Integration by Substition (worksheet solutions)
Lesson 29: Integration by Substition (worksheet solutions)Lesson 29: Integration by Substition (worksheet solutions)
Lesson 29: Integration by Substition (worksheet solutions)
Matthew Leingang
 

Similar to 2011 Db Concurrency (14)

Taylor problem
Taylor problemTaylor problem
Taylor problem
 
Engr 213 midterm 1b sol 2009
Engr 213 midterm 1b sol 2009Engr 213 midterm 1b sol 2009
Engr 213 midterm 1b sol 2009
 
Hw2 s
Hw2 sHw2 s
Hw2 s
 
Koc2(dba)
Koc2(dba)Koc2(dba)
Koc2(dba)
 
Varian, microeconomic analysis, solution book
Varian, microeconomic analysis, solution bookVarian, microeconomic analysis, solution book
Varian, microeconomic analysis, solution book
 
stochastic processes assignment help
stochastic processes assignment helpstochastic processes assignment help
stochastic processes assignment help
 
Intro probability 2
Intro probability 2Intro probability 2
Intro probability 2
 
Lesson 27: Integration by Substitution (slides)
Lesson 27: Integration by Substitution (slides)Lesson 27: Integration by Substitution (slides)
Lesson 27: Integration by Substitution (slides)
 
Lesson 27: Integration by Substitution (slides)
Lesson 27: Integration by Substitution (slides)Lesson 27: Integration by Substitution (slides)
Lesson 27: Integration by Substitution (slides)
 
03 truncation errors
03 truncation errors03 truncation errors
03 truncation errors
 
1 - Linear Regression
1 - Linear Regression1 - Linear Regression
1 - Linear Regression
 
Interpolation techniques - Background and implementation
Interpolation techniques - Background and implementationInterpolation techniques - Background and implementation
Interpolation techniques - Background and implementation
 
Emat 213 study guide
Emat 213 study guideEmat 213 study guide
Emat 213 study guide
 
Lesson 29: Integration by Substition (worksheet solutions)
Lesson 29: Integration by Substition (worksheet solutions)Lesson 29: Integration by Substition (worksheet solutions)
Lesson 29: Integration by Substition (worksheet solutions)
 

Recently uploaded

Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 

Recently uploaded (20)

Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 

2011 Db Concurrency

  • 1. Concurrent Transactions Alan Medlar amedlar@cs.ucl.ac.uk
  • 2. Concurrent Transactions • We want our database to be accessible to many clients concurrently • Multiple processors or cores accessing same storage (containing whole database) • Multiple processors distributed over a network each with local storage (each holding a portion of the database)
  • 3. Concurrent Transactions • To increase performance we want to allow multiple database transactions, being processed on separate processors, to take place at once • Run into problems when two (or more) of these transactions want to access the same data!
  • 4. Schedules • Concerned with the order of execution • Consider two transactions, T and T : 1 2
  • 5. T1 T2 T1 T2 read(X) read(X) X = X-100 tmp = X*0.1 write(X) X=X-tmp read(Y) write(X) Y = Y+100 read(Y) write(Y) Y=Y+tmp read(X) write(Y) tmp = X*0.1 read(X) X=X-tmp X = X-100 write(X) write(X) read(Y) read(Y) Y=Y+tmp Y = Y+100 write(Y) write(Y)
  • 6. Schedules • Schedules of T and T2 are serial due to 1 one transaction finishing before the other • If Tand T2 were to happen at the same 1 time, forcing serialisation would limit performance!
  • 7. T1 T2 read(X) X = X-100 write(X) read(X) tmp = X*0.1 X=X-tmp write(X) read(Y) Y = Y+100 write(Y) read(Y) Y=Y+tmp write(Y)
  • 8. T1 T2 read(X) X = X-100 write(X) Despite these read(X) transactions not tmp = X*0.1 being serialised, the X=X-tmp schedule ensures the write(X) resulting database is read(Y) consistent Y = Y+100 write(Y) read(Y) Y=Y+tmp write(Y)
  • 9. T1 T2 read(X) X = X-100 read(X) tmp = X*0.1 X=X-tmp write(X) write(X) read(Y) Y = Y+100 write(Y) read(Y) Y=Y+tmp write(Y)
  • 10. T1 T2 read(X) X = X-100 read(X) Here the database tmp = X*0.1 gets into an X=X-tmp inconsistent state write(X) because the write(X) write(X) of T2 is lost due to read(Y) being overwritten by Y = Y+100 T1! write(Y) read(Y) Y=Y+tmp write(Y)
  • 11. Conflict Analysis • What went wrong in the example? • Ordering of reads and writes caused an inconsistency
  • 12. Conflict Analysis • What went wrong in the example? • Ordering of reads and writes caused an inconsistency • Use conflict analysis to identify the cause of the problem... • Intuition: reads and writes applied in the same order as a serial schedule will always result in a consistent state • Examine the schedule and try to rearrange them into the same order as a serial schedule by swapping instructions (paying special attention to “conflicts”)
  • 13. Conflicts • Looking consecutive reads and writes: • If they access different data items, they can be applied in any order • If they access the same data items, then the order of operations may be important, i.e. they may conflict
  • 14. Conflicts • Looking consecutive reads and writes: • If they access different data items, they can be applied in any order • If they access the same data items, then the order of operations may be important, i.e. they may conflict • (This is simplified! We are not considering insertion and deletion)
  • 15. Conflict Rules • In a schedule (only reads and writes) for consecutive instructions i1 and i2 : • i1 = read(x), i2 = read(x) : no conflict • i1 = read(x), i2 = write(x) : conflict (ordering dictates whether i1 gets value of write or previous state) • i1 = write(x), i2 = read(x) : conflict • i1 = write(x), i2 = write(x) : conflict (writes do not affect one another, but will affect next read)
  • 16. Conflict Serialization • If a schedule S is transformed into schedule S’ by a series of non-conflicting instruction swaps, the S and S’ are conflict equivalent • A schedule is conflict serializable if it is conflict equivalent to a serial schedule • A schedule that is conflict serializable will produce the same final state as some serial schedule and will leave the database in a consistent state
  • 17. T1 T2 read(X) X = X-100 write(X) read(X) tmp = X*0.1 X=X-tmp write(X) read(Y) Y = Y+100 write(Y) read(Y) Y=Y+tmp write(Y)
  • 18. T1 T2 read(X) X = X-100 write(X) read(X) tmp = X*0.1 X=X-tmp write(X) read(Y) Y = Y+100 write(Y) read(Y) Y=Y+tmp write(Y)
  • 19. T1 T2 read(X) X = X-100 write(X) read(X) tmp = X*0.1 X=X-tmp write(X) read(Y) Y = Y+100 write(Y) read(Y) Y=Y+tmp write(Y)
  • 20. T1 T2 T1 T2 read(X) read(X) X = X-100 X = X-100 write(X) write(X) read(X) read(Y) tmp = X*0.1 Y = Y+100 X=X-tmp write(Y) write(X) read(X) read(Y) tmp = X*0.1 Y = Y+100 X=X-tmp write(Y) write(X) read(Y) read(Y) Y=Y+tmp Y=Y+tmp write(Y) write(Y)
  • 21. T1 T2 read(X) X = X-100 read(X) tmp = X*0.1 X=X-tmp write(X) write(X) read(Y) Y = Y+100 write(Y) read(Y) Y=Y+tmp write(Y)
  • 22. T1 T2 read(X) X = X-100 read(X) These instructions tmp = X*0.1 cannot be swapped X=X-tmp because they are in write(X) conflict! write(X) This schedule cannot read(Y) be re-ordered into a Y = Y+100 serial schedule... write(Y) read(Y) Y=Y+tmp write(Y)
  • 23. Serializability • Paramount correctness criteria for concurrent database transactions • Ensures isolation between transactions • Ensures consistency despite other transactions
  • 24. Locking • We can get a serialisable schedule by enforcing mutual exclusion on data items: this could be achieved using simple locking • shared lock - to read data items, can only be granted if there are either no locks or only shared locks on a data item • write lock - for writing, can only be granted if there are no other locks on the data item
  • 25. T1 T2 write_lock(X) read(X) X = X-100 write(X) unlock(X) write_lock(X) read(X) tmp = X*0.1 X=X-tmp write(X) unlock(X) write_lock(Y) read(Y) Y = Y+100 write(Y) unlock(Y) write_lock(Y) read(Y) Y=Y+tmp write(Y) unlock(Y)
  • 26. T1 T2 T1 T2 write_lock(X) write_lock(X) read(X) read(X) X = X-100 X = X-100 write(X) write_lock(X) unlock(X) read(X) write_lock(X) tmp = X*0.1 read(X) X=X-tmp tmp = X*0.1 write(X) X=X-tmp unlock(X) write(X) write(X) unlock(X) unlock(X) write_lock(Y) write_lock(Y) read(Y) read(Y) Y = Y+100 Y = Y+100 write(Y) write(Y) unlock(Y) unlock(Y) write_lock(Y) write_lock(Y) read(Y) read(Y) Y=Y+tmp Y=Y+tmp write(Y) write(Y) unlock(Y) unlock(Y)
  • 27. T1 T2 T1 T2 write_lock(X) write_lock(X) read(X) read(X) X = X-100 X = X-100 write(X) write_lock(X) s! unlock(X) read(X) ail f write_lock(X) tmp = X*0.1 k oc read(X) X=X-tmp l tmp = X*0.1 write(X) X=X-tmp unlock(X) write(X) write(X) unlock(X) unlock(X) write_lock(Y) write_lock(Y) read(Y) read(Y) Y = Y+100 Y = Y+100 write(Y) write(Y) unlock(Y) unlock(Y) write_lock(Y) write_lock(Y) read(Y) read(Y) Y=Y+tmp Y=Y+tmp write(Y) write(Y) unlock(Y) unlock(Y)
  • 28. Problem: Immediate Modification • If during a transaction our database uses immediate modification we have a problem, transactions are not isolated!
  • 29. T1 T2 write-lock(P) read(P) P = P - 100 write(P) unlock(P) read-lock(P) read(P) unlock(P) read-lock(Q) read(Q) unlock(Q) printf(“%dn”, P + Q) write-lock(Q) read(Q) Q = Q + 100 write(Q) unlock(Q)
  • 30. T1 T2 } P = 100 150 write-lock(P) Q = 50 read(P) P = P - 100 write(P) unlock(P) read-lock(P) read(P) unlock(P) read-lock(Q) read(Q) unlock(Q) printf(“%dn”, P + Q) write-lock(Q) read(Q) Q = Q + 100 write(Q) unlock(Q)
  • 31. T1 T2 } P = 100 150 write-lock(P) Q = 50 read(P) P = P - 100 write(P) } P= 0 50 unlock(P) Q = 50 read-lock(P) read(P) unlock(P) read-lock(Q) read(Q) unlock(Q) printf(“%dn”, P + Q) write-lock(Q) read(Q) Q = Q + 100 write(Q) unlock(Q)
  • 32. T1 T2 } P = 100 150 write-lock(P) Q = 50 read(P) P = P - 100 write(P) } P= 0 50 unlock(P) Q = 50 read-lock(P) read(P) unlock(P) read-lock(Q) read(Q) unlock(Q) printf(“%dn”, P + Q) write-lock(Q) read(Q) Q = Q + 100 write(Q) } P= 0 150 unlock(Q) Q = 150
  • 33. T1 T2 write-lock(P) read(P) P = P - 100 Solution: release locks write(P) as late as possible! write-lock(Q) read(Q) (ensures serial schedule, Q = Q + 100 but potential deadlocks!) write(Q) unlock(Q) unlock(P) read-lock(P) read(P) read-lock(Q) read(Q) unlock(Q) unlock(P) printf(“%dn”, P + Q)
  • 34. 2-Phase Locking • One of many methods to ensure serializability • Growth phase: transactions can only acquire locks • Shrinking phase: transactions can only release locks • Once a transaction has started to release locks it cannot acquire anymore...
  • 35. T1 T2 T1 Growth Phase write-lock(P) read(P) P = P - 100 write(P) write-lock(Q) read(Q) Q = Q + 100 write(Q) T1 Shrinking Phase unlock(Q) unlock(P) T2 Growth Phase read-lock(P) read(P) read-lock(Q) read(Q) T2 Shrinking Phase unlock(Q) unlock(P) printf(“%dn”, P + Q)
  • 36. Deadlock • Two or more transactions are waiting for locks that the other holds, hence none of those involved make progress • Dealt with in different ways, not covered in this course...
  • 37. Summary • Most concurrent transactions have no conflicts: they either all access different data items or else only perform reads • For the transactions that might conflict we can enforce serializability to maintain the ACID properties

Editor's Notes