SlideShare a Scribd company logo
1 of 38
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

Predicates and Quantifiers
Predicates and QuantifiersPredicates and Quantifiers
Predicates and Quantifiersblaircomp2003
 
Harmonic Analysis and Deep Learning
Harmonic Analysis and Deep LearningHarmonic Analysis and Deep Learning
Harmonic Analysis and Deep LearningSungbin 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 CalculusMatthew Leingang
 
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 FunctionsMatthew Leingang
 
09d transform & conquer spring2015
09d transform & conquer spring201509d transform & conquer spring2015
09d transform & conquer spring2015Hira Gul
 
Deep generative model.pdf
Deep generative model.pdfDeep generative model.pdf
Deep generative model.pdfHyungjoo 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 inferenceasimnawaz54
 
Largedictionaries handout
Largedictionaries handoutLargedictionaries handout
Largedictionaries handoutcsedays
 
1 hofstad
1 hofstad1 hofstad
1 hofstadYandex
 
Hashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo HashingHashing Part Two: Cuckoo Hashing
Hashing Part Two: Cuckoo HashingBenjamin 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

Database chapter 10 questions
Database chapter 10 questionsDatabase chapter 10 questions
Database chapter 10 questionsjandrewsxu
 
Database Systems - SQL - DCL Statements (Chapter 3/4)
Database Systems - SQL - DCL Statements (Chapter 3/4)Database Systems - SQL - DCL Statements (Chapter 3/4)
Database Systems - SQL - DCL Statements (Chapter 3/4)Vidyasagar Mundroy
 
SQL Server Transaction Management
SQL Server Transaction ManagementSQL Server Transaction Management
SQL Server Transaction ManagementMark Ginnebaugh
 
Ch17 introduction to transaction processing concepts and theory
Ch17 introduction to transaction processing concepts and theoryCh17 introduction to transaction processing concepts and theory
Ch17 introduction to transaction processing concepts and theorymeenatchi selvaraj
 
protocols of concurrency control
protocols of concurrency controlprotocols of concurrency control
protocols of concurrency controlMOHIT DADU
 
SQL Server Reporting Services
SQL Server Reporting ServicesSQL Server Reporting Services
SQL Server Reporting ServicesAhmed Elbaz
 
SQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12cSQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12cTanel Poder
 
Transaction ও Concurrent execution
Transaction ও Concurrent executionTransaction ও Concurrent execution
Transaction ও Concurrent executionMaruf Ahmed
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMSkoolkampus
 

Viewers also liked (9)

Database chapter 10 questions
Database chapter 10 questionsDatabase chapter 10 questions
Database chapter 10 questions
 
Database Systems - SQL - DCL Statements (Chapter 3/4)
Database Systems - SQL - DCL Statements (Chapter 3/4)Database Systems - SQL - DCL Statements (Chapter 3/4)
Database Systems - SQL - DCL Statements (Chapter 3/4)
 
SQL Server Transaction Management
SQL Server Transaction ManagementSQL Server Transaction Management
SQL Server Transaction Management
 
Ch17 introduction to transaction processing concepts and theory
Ch17 introduction to transaction processing concepts and theoryCh17 introduction to transaction processing concepts and theory
Ch17 introduction to transaction processing concepts and theory
 
protocols of concurrency control
protocols of concurrency controlprotocols of concurrency control
protocols of concurrency control
 
SQL Server Reporting Services
SQL Server Reporting ServicesSQL Server Reporting Services
SQL Server Reporting Services
 
SQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12cSQL Monitoring in Oracle Database 12c
SQL Monitoring in Oracle Database 12c
 
Transaction ও Concurrent execution
Transaction ও Concurrent executionTransaction ও Concurrent execution
Transaction ও Concurrent execution
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMS
 

Similar to 2011 Db Concurrency

Engr 213 midterm 1b sol 2009
Engr 213 midterm 1b sol 2009Engr 213 midterm 1b sol 2009
Engr 213 midterm 1b sol 2009akabaka12
 
Varian, microeconomic analysis, solution book
Varian, microeconomic analysis, solution bookVarian, microeconomic analysis, solution book
Varian, microeconomic analysis, solution bookJosé Antonio PAYANO YALE
 
Intro probability 2
Intro probability 2Intro probability 2
Intro probability 2Phong 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 errorsmaheej
 
Interpolation techniques - Background and implementation
Interpolation techniques - Background and implementationInterpolation techniques - Background and implementation
Interpolation techniques - Background and implementationQuasar Chunawala
 
Emat 213 study guide
Emat 213 study guideEmat 213 study guide
Emat 213 study guideakabaka12
 
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

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 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