SlideShare a Scribd company logo
UNIT 6

Concurrency Control
Content
 Types of locks and system lock tables

 Serializablility by Two-Phase Locking

 Dealing with Deadlock and Starvation

 Timestamp ordering

 Validation concurrency control
Types of Lock

 Some of the main technique used to control concurrent

  execution of transaction are based on the concept of locking
  data items.

 Types of Lock

   Binary Lock :

   Shared/Exclusive ( Read/Write) Lock
Binary Lock
 A Binary Lock can have two state or values:

   Lock

   Unlock

 1 -> indicates locked

 0 -> indicates unlocked.
Locking
 • Locking is an operation which secures (a) permission to

  Read or (b) permission to Write a data item for a
  transaction.

 • A distinct lock is associated with each database item x.

 • A value of lock(x)=1

   • A value x can not be accessed by database operation that

    request the item.

 • Example: Lock (X)

   • Data item X is locked in behalf of the requesting

    transaction.
Unlocking
 • Unlocking    is   an   operation   which   removes     these
  permissions from the data item

 • Example: Unlock (X).

   • Data item X is made available to all other transactions.

 • Lock and Unlock are Atomic operations.
Exclusive/Shared Lock
• Two locks modes

  (a) shared (read)
  (b) exclusive (write)
 • Shared mode: Shared lock (X).

    • More than one transaction can apply share lock on X

     for reading its value but no write lock can be applied on
     X by any other transaction.
Exclusive/Shared Lock
• Exclusive mode : Write lock (X).

  • Only one write lock on X can exist at any time and no

   shared lock can be applied by any other transaction on X.

  • If transaction have exclusive lock then no transaction

   have exclusive lock on same item.
Lock table and Lock manager
 Lock table :

   The system need to maintain only these record for the item
    that are concurrently locked in a Lock table.
   Lock table is organize as a hash file.

   Item not in lock table are consider to be unlocked.

    Transaction ID Data item id lock mode Ptr to next data item
        T1              X1        Read            Next

 Lock Manager :

   Managing locks on data items.
 Database requires that all transactions should be well-

  formed.

 A transaction is well-formed if:

  • It must lock the data item before it reads or writes to it.

  • It must not lock an already locked data items and it must

    not try to unlock a free data item.
Lock Operation of Binary Lock
Lock_item(X) :
B:
     if LOCK (X) = 0 (* item is unlocked*)
            then LOCK (X)      1 (*lock the item*)
     else
        begin
            wait (until lock (X) = 0)
                     the lock manager wakes up the transaction;
            goto B
        end;
unlock Operation of Binary Lock
unlock_item(X) :
  LOCK (X)      0 (*unlock the item*)

  if any transactions are waiting then

       wake up one of the waiting the transactions;
Rules for transaction in binary locking scheme
1.   A transaction T must issue the operation lock_item(X) before
     any read_item(X) or write_item(X) operation performed in T.

2.   A transaction T must issue the operation unlock_item(X)
     after all read_item(X) and write_item(X) operation
     completed in T.

3.   A transaction T will not issue a lock_item(X) operation if it
     already hold lock on item X.

4.   A transaction T will not issue a unlock_item(X) operation
     unless it already hold lock on item X.
Lock Operation of Shared Lock
read_item(X) :
  B:
   if LOCK (X) = “unlocked” then
            begin
                   LOCK (X) “read-locked”;
                   no_of_reads (X) 1;
            end
     else if LOCK (X) “read-locked” then
           no_of_reads (X) no_of_reads (X) +1
     else
             begin
                   wait (until LOCK (X) = “unlocked”
                   and the lock manager wakes up the transaction);
                   go to B
             end;
Lock Operation of exclusive Lock
write_item(X) :
  B:
   if LOCK (X) = “unlocked” then
           LOCK (X)     “write-locked”;
    else
           begin
                   wait (until LOCK (X) = “unlocked”
                   and the lock manager wakes up the transaction);
                   go to B
           end;
Unlock Operation for two-mode
Unlock(x) :
    if LOCK (X) = “write-locked” then
           begin
                  LOCK (X) “unlocked”;
                  wake up on of the waiting transaction, if any
           end
     else if LOCK (X) = “read-locked” then
            begin
                  no_of_read(X) no_of_read(X)-1 ;
                  if no_of_read(X) =0 then
                            begin
                                LOCK (X) “unlocked”;
                                wake up on of the waiting transaction, if any
                            end
            end;
Rules for transaction in shared/exclusive locking scheme
1.   A transaction T must issue the operation read_lock(X) or

     write_lock(X) before any read_item(X) operation

     performed in T.

2.   A transaction T must issue the operation write_lock(X)

     before write_item(X) operation perforemed in T.

3.   A transaction T must issue the operation unlock(X) after

     all write_item(X) operation are completed in T.
Rules for transaction in shared/exclusive locking scheme
4.   A transaction T will not issue a read_lock(X) operation if it

     already holds a read(shared) lock or a write(exclusive)

     lock on item X.

5.   A transaction T will not issue a write_lock(X) operation if

     it already holds a read(shared) lock or a write(exclusive)

     lock on item X.

6.   A transaction T will not issue an unlock(x) operation

     unless it already holds a read(shared) lock or a

     write(exclusive) lock on item X.
Serializablility by Two Phase Locking
 A transaction is said to follow the two-phase locking

  protocol if all locking operations (read_lock, write_lock)

  precede the first unlock operation in the transaction.

 Such transaction can be divided in to 2 phase

   Expanding or Growing (first) Phase

   Shrinking (Second) Phase
Serializablility by Two Phase Locking
 Locking (Growing) Phase: In this phase new locks on the items

     can be acquired but none can be released.

     A transaction applies locks (read or write) on desired data

        items one at a time.(Gain Lock)

 Unlocking (Shrinking) Phase: In this phase existing lock can be
     released but no new lock can be acquired.

     A transaction unlocks its locked data items one at a time.(Release Lock)

    Requirement: For a transaction these two phases must be mutually
     exclusively, that is,

       During locking phase unlocking phase must not start

       During unlocking phase locking phase must not begin.
Serial Schedule of T1 and T2
     T1                T2                   Result

 read_lock (Y);    read_lock (X);    Initial values: X=20; Y=30

 read_item (Y);    read_item (X);    Result of serial execution

 unlock (Y);       unlock (X);       T1 followed by T2

 write_lock (X);   Write_lock (Y);   X=50, Y=80.

 read_item (X);    read_item (Y);    Result of serial execution

 X:=X+Y;           Y:=X+Y;           T2 followed by T1

 write_item (X);   write_item (Y);   X=70, Y=50

 unlock (X);       unlock (Y);
Problem to violated to phase locking Protocol
T1                T2
Read_lock(Y)
read_item (Y);
unlock (Y);                         Result :
                  read_lock (X);    X=50; Y=50
                  read_item (X);
                  unlock (X);
                  write_lock (Y);
                                    Non-Serializable
                  read_item (Y);    because it violated
                  Y:=X+Y;           two phase policy.
                  write_item (Y);
                  unlock (Y);
write_lock (X);
read_item (X);
X:=X+Y;
write_item (X);
unlock (X)
T1                T2

 Read_lock(Y)      read_lock (X);
 read_item (Y);    read_item (X);
 write_lock (X);   write_lock (Y);
 unlock (Y);       unlock (X);
 read_item (X);    read_item (Y);
 X:=X+Y;           Y:=X+Y;
 write_item (X);   write_item (Y);
 unlock (X)        unlock (Y);




 Follows Two phase locking protocols
Two phase locking protocols

 Advantage:

   It produce Serializable schedule.

 Problem With two phase locking protocols

   Two phase locking protocols can produce deadlock.
Lock conversion
 Lock upgrade: existing read lock to write lock

   if Ti has a read-lock (X) and Tj has no read-lock (X) (i j) then
          convert read-lock (X) to write-lock (X)
   else
           force Ti to wait until Tj unlocks X

 Lock downgrade: existing write lock to read lock

  Ti has a write-lock (X) (*no transaction can have any lock on X*)
  convert write-lock (X) to read-lock (X)
Variation of two phase locking

 Two-phase policy generates two locking algorithms
   Basic
   Conservative.

 Conservative:

   Prevents deadlock by locking all desired data items before
    transaction begins execution by pre-declaring its read-set and
    write-set.

   Deadlock free protocol
Terms in two-phase locking protocols
 Strict 2PL :
  A transaction must released all it’s exclusive lock only when it
    is committed or abort.
  Transaction T does not released any of its exclusive lock until
    after commit or aborts.
 Rigorous 2PL :
  A transaction must released all it’s lock only when it’s commit
    or abort.
  Transaction T does not released any of its lock(exclusive or
    Shared) until after commit or aborts.
  It is easier to implement than strict 2PL.
Deadlock
 Deadlock occurs when each transaction T in a set of two r

  more transaction is waiting for some item that is locked by
  some other transaction T’ in the set.

 Hence each transaction in the set is on a waiting queue,

  waiting for one of the other transaction in the set to
  release the lock on an item.
Deadlock

       T1               T2
read_lock (Y)
read_item(Y)
                 read_lock (X)     T1 and T2 did follow two-
                 read_item(X)
                                   phase policy but they are
write_lock (X)
(waits for X)                      deadlock
                 write_lock (Y);
                 (waits for Y)
3. Dealing with Deadlock
 There are several ways to dealing with deadlock
   Deadlock prevention

   Deadlock detection

   Prevent Starvation
Deadlock prevention
 Deadlock prevention protocols ensure that the system

  will never enter into a deadlock state.

 Some prevention strategies :

  1.       Require that each transaction locks all its data items

           before it begins execution (pre-declaration).
            The conservative two-phase locking uses this approach
  2.       On the basis of transaction timestamp TS(T)
Transaction Timestamp TP(S)
 Transaction timestamp is a unique identifier assigned to

  each transaction.

 It is based on the order in which transaction are started.

 If transaction T1 starts before transaction T2 then

      TS(T1 ) < TS(T2)

 Older transaction has smaller timestamp value.

 Two scheme that prevent deadlock

   1. Wait-Die

   2. Wound-Wait
Deadlock prevention Scheme.

 wait-die scheme — non-preemptive

   If TS(i)< TS(j), then (Ti older than Tj)
     Ti allowed to wait;
   otherwise (Ti younger than Tj)
        abort Ti(Ti dies) and
        restart it later with the same timestamp.
   Older transaction may wait for younger one to release data
   item. Younger transactions never wait for older ones; they
   are rolled back instead.
   A transaction may die several times before acquiring
   needed data item
 wound-wait scheme — preemptive

   If TS(i)< TS(j), then (Ti older than Tj)

      abort Tj (Ti wounds Tj)

      restart it later with the same timestamp.

   otherwise (Ti younger than Tj)

      Ti allowed to wait

   older transaction wounds (forces rollback) of younger

   transaction instead of waiting for it. Younger transactions
   may wait for older ones.

   may be fewer rollbacks than wait-die scheme.
Deadlock detection and resolution
   In this approach, deadlocks are allowed to happen.

   The scheduler maintains a wait-for-graph for detecting cycle.

   If a cycle exists, then one transaction involved in the cycle is selected
    (victim) and rolled-back.

   A wait-for-graph is created using the lock table.

   As soon as a transaction is blocked, it is added to the graph. When a
    chain like:

   Ti waits for Tj waits for Tk waits for Ti or Tj occurs, then this creates a
    cycle.

   One of the transaction of the cycle is selected and rolled back.
Starvation
 Starvation :it occurs when a transaction cannot proceed for

  an indefinite period of time while other transaction in the
  system continue normally.

 This may occur if the waiting scheme for locked items is

  unfair.

 Solution of Starvation :

   First come first served

   Based on priority

     But increased the priority of the transaction the longer it

      waits. until it get highest priority.
Concurrency control based on timestamp ordering
 Timestamp

   Transaction timestamp is a unique identifier assigned to

    each transaction.

   It is based on the order in which transaction are started.

    A larger timestamp value indicates a more recent event or

     operation.

    Timestamp based algorithm uses timestamp to serialize the

     execution of concurrent transactions.
Timestamp ordering algorithm
 Timestamp Ordering : A schedule in which the transaction

  participate is then Serializable and equivalent serial schedule
  has the transaction in order of their timestamp value this is
  called timestamp ordering.

 order of accessed item that does not violate serializablility

  order, for that algorithm associated with each database item X
  is used.
 read_TS(X)

   The read timestamp of item X; this is largest timestamp
    among all the timestamp of transaction that have
    successfully read item X.
   read_TS(X)=TS(T)
     Where T is the youngest transaction that has read X successfully.

 write_TS(X)

   The write timestamp of item X; this is largest timestamp
    among all the timestamp of transaction that have
    successfully written item X.
   weite_TS(X)=TS(T)
     Where T is the youngest transaction that has written X successfully.
Timestamp based concurrency control
  algorithm
Basic Timestamp Ordering

1. Transaction T issues a write_item(X) operation:

    a. If read_TS(X) > TS(T) or if write_TS(X) > TS(T), then

        abort and roll-back T and reject the operation.

        (younger transaction has already read the data item)

    b. If the condition in part (a) does not exist, then

        execute write_item(X) of T and set write_TS(X) to TS(T).
Timestamp based concurrency control
     algorithm
Basic Timestamp Ordering

2.   Transaction T issues a read_item(X) operation:

      a. If write_TS(X) > TS(T), then

          abort and roll-back T and reject the operation.

          (younger transaction has already written to the data item )

      b. If write_TS(X)    TS(T), then
          execute read_item(X) of T and set read_TS(X) to the larger of
          TS(T) and the current read_TS(X).
 Advantage :

   Basic TO always produce conflict Serializable schedule.

   Deadlock does not occur.

 Problem with Basic TO

   Cyclic restart may occur if a transaction is continually aborted
    and restarted.
 A Modification of Basic TO algorithm is known as Thomas’s
  write rule.
   It does not enforce conflict serializability

   But it reject fewer write operation by modifying the checks for
    the write_item(X) operation.
Timestamp based concurrency control
 algorithm
Thomas’s Write Rule

  1. If read_TS(X) > TS(T) then abort and roll-back T and reject

     the operation.

  2. If write_TS(X) > TS(T), then just ignore the write operation

     and continue execution. This is because the most recent
     writes counts in case of two consecutive writes.

  3. If the conditions given in 1 and 2 above do not occur, then

     execute write_item(X) of T and set write_TS(X) to TS(T).
Validation concurrency control techniques
 optimistic concurrency control technique (validation or
  certification technique)
   No checking is done while the transaction is executing.

   It follows some scheme.

     In this scheme , updation in the transaction are not applied
      directly to the database item until the transaction reaches it end.
     All updation applied to local copies of data item that are kept for
      transaction.
     At the end of transaction, concurrency control phases checks
      whether any of transaction’s updates violates serializability or not.
Three phases of concurrency control protocol
 Read Phase:
   A transaction can read values of committed data items from the
    database.
   However , updation are applied only to local copies of data items.

 Validation Phase :
   Checking is performed to ensure that serializability will not be
    violated if transaction updates are applied to the database.
 Write Phase
   If validation phase is successful, the transaction updates are
    applied to the database;
   Otherwise , the updates are discarded and the transaction is
    restarted .
Validation Phase
 This phase for Ti checks that, for each transaction Tj that is either
  committed or is in its validation phase, one of the following conditions
  holds:

   1. Tj completes its write phase before Ti starts its read phase.

   2. Ti starts its write phase after Tj completes its write phase,
      and the read_set of Ti has no items in common with the
      write_set of Tj

   3. Both the read_set and write_set of Ti have no items in
      common with the write_set of Tj, and Tj completes its end
      phase.
Unit 6

More Related Content

What's hot

Transaction Processing in DBMS.pptx
Transaction Processing in DBMS.pptxTransaction Processing in DBMS.pptx
Transaction Processing in DBMS.pptx
Lovely Professional University
 
concurrency-control
concurrency-controlconcurrency-control
concurrency-control
Saranya Natarajan
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
Ali Haider
 
Concurrency Conrol
Concurrency ConrolConcurrency Conrol
Concurrency Conrol
lubna19
 
Chapter19
Chapter19Chapter19
Chapter19
gourab87
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
Sara Ali
 
File access methods.54
File access methods.54File access methods.54
File access methods.54myrajendra
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMSkoolkampus
 
Serializability
SerializabilitySerializability
Serializability
Pyingkodi Maran
 
Deadlock in database
Deadlock in databaseDeadlock in database
Deadlock in database
Tayyab Hussain
 
Deadlock management
Deadlock managementDeadlock management
Deadlock management
Ahmed kasim
 
Presentation on Segmentation
Presentation on SegmentationPresentation on Segmentation
Presentation on Segmentation
Priyanka bisht
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
varsha singh
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
Adeel Rasheed
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
MOHIT DADU
 
Transaction management in DBMS
Transaction management in DBMSTransaction management in DBMS
Transaction management in DBMS
Megha Sharma
 
serializability in dbms
serializability in dbmsserializability in dbms
serializability in dbms
Saranya Natarajan
 
Deadlock in dbms
Deadlock in dbmsDeadlock in dbms
Difference Program vs Process vs Thread
Difference Program vs Process vs ThreadDifference Program vs Process vs Thread
Difference Program vs Process vs Thread
jeetendra mandal
 
Chapter18
Chapter18Chapter18
Chapter18
gourab87
 

What's hot (20)

Transaction Processing in DBMS.pptx
Transaction Processing in DBMS.pptxTransaction Processing in DBMS.pptx
Transaction Processing in DBMS.pptx
 
concurrency-control
concurrency-controlconcurrency-control
concurrency-control
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
 
Concurrency Conrol
Concurrency ConrolConcurrency Conrol
Concurrency Conrol
 
Chapter19
Chapter19Chapter19
Chapter19
 
Deadlocks in operating system
Deadlocks in operating systemDeadlocks in operating system
Deadlocks in operating system
 
File access methods.54
File access methods.54File access methods.54
File access methods.54
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
 
Serializability
SerializabilitySerializability
Serializability
 
Deadlock in database
Deadlock in databaseDeadlock in database
Deadlock in database
 
Deadlock management
Deadlock managementDeadlock management
Deadlock management
 
Presentation on Segmentation
Presentation on SegmentationPresentation on Segmentation
Presentation on Segmentation
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
Transaction management in DBMS
Transaction management in DBMSTransaction management in DBMS
Transaction management in DBMS
 
serializability in dbms
serializability in dbmsserializability in dbms
serializability in dbms
 
Deadlock in dbms
Deadlock in dbmsDeadlock in dbms
Deadlock in dbms
 
Difference Program vs Process vs Thread
Difference Program vs Process vs ThreadDifference Program vs Process vs Thread
Difference Program vs Process vs Thread
 
Chapter18
Chapter18Chapter18
Chapter18
 

Viewers also liked

Payment Instrument Utilization for Specific Transaction Types
Payment Instrument Utilization for  Specific Transaction TypesPayment Instrument Utilization for  Specific Transaction Types
Payment Instrument Utilization for Specific Transaction Types
NMSU - Family Resource Management
 
Different Types of Social Media Channels - Sysomos
Different Types of Social Media Channels - SysomosDifferent Types of Social Media Channels - Sysomos
Different Types of Social Media Channels - Sysomos
Sysomos
 
The 6 types of social media
The 6 types of social mediaThe 6 types of social media
The 6 types of social media
Tennycut
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
KurdGul
 
Types of Social Media - A Review
Types of Social Media - A ReviewTypes of Social Media - A Review
Types of Social Media - A Review
Paban S. Mohanty
 
The Ultimate Marketing Guide to Snapchat
The Ultimate Marketing Guide to SnapchatThe Ultimate Marketing Guide to Snapchat
The Ultimate Marketing Guide to Snapchat
Ross Simmonds
 
Types of communication
Types of communication Types of communication
Types of communication
Vicky Risky
 
The electronic payment systems
The electronic payment systemsThe electronic payment systems
The electronic payment systemsVishal Singh
 
Transaction management and concurrency control
Transaction management and concurrency controlTransaction management and concurrency control
Transaction management and concurrency control
Dhani Ahmad
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMSkoolkampus
 
11 Facts You Probably Didn't Know About Pasta
11 Facts You Probably Didn't Know About Pasta11 Facts You Probably Didn't Know About Pasta
11 Facts You Probably Didn't Know About Pasta
Jodie Harper
 
Top 10 Most Eaten Foods In The World
Top 10 Most Eaten Foods In The WorldTop 10 Most Eaten Foods In The World
Top 10 Most Eaten Foods In The World
Eason Chan
 
6 Questions to Lead You to a Social Media Strategy
6 Questions to Lead You to a Social Media Strategy6 Questions to Lead You to a Social Media Strategy
6 Questions to Lead You to a Social Media Strategy
Mark Schaefer
 
Project planning and project work plan
Project planning and project work planProject planning and project work plan
Project planning and project work plan
Ferdinand Importado, CPA, MBA
 
11 Things Healthy People Do Every Morning
11 Things Healthy People Do Every Morning11 Things Healthy People Do Every Morning
11 Things Healthy People Do Every Morning
Eason Chan
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees
 
Social Media for Business
Social Media for BusinessSocial Media for Business
Social Media for Business
Presentation Advisors
 

Viewers also liked (20)

Payment Instrument Utilization for Specific Transaction Types
Payment Instrument Utilization for  Specific Transaction TypesPayment Instrument Utilization for  Specific Transaction Types
Payment Instrument Utilization for Specific Transaction Types
 
Different Types of Social Media Channels - Sysomos
Different Types of Social Media Channels - SysomosDifferent Types of Social Media Channels - Sysomos
Different Types of Social Media Channels - Sysomos
 
The 6 types of social media
The 6 types of social mediaThe 6 types of social media
The 6 types of social media
 
plastic money
plastic moneyplastic money
plastic money
 
Intro. to prog. c++
Intro. to prog. c++Intro. to prog. c++
Intro. to prog. c++
 
Types of Social Media - A Review
Types of Social Media - A ReviewTypes of Social Media - A Review
Types of Social Media - A Review
 
The Ultimate Marketing Guide to Snapchat
The Ultimate Marketing Guide to SnapchatThe Ultimate Marketing Guide to Snapchat
The Ultimate Marketing Guide to Snapchat
 
Snapchat
SnapchatSnapchat
Snapchat
 
Types of communication
Types of communication Types of communication
Types of communication
 
The electronic payment systems
The electronic payment systemsThe electronic payment systems
The electronic payment systems
 
Transaction management and concurrency control
Transaction management and concurrency controlTransaction management and concurrency control
Transaction management and concurrency control
 
15. Transactions in DBMS
15. Transactions in DBMS15. Transactions in DBMS
15. Transactions in DBMS
 
Credit Cards
Credit CardsCredit Cards
Credit Cards
 
11 Facts You Probably Didn't Know About Pasta
11 Facts You Probably Didn't Know About Pasta11 Facts You Probably Didn't Know About Pasta
11 Facts You Probably Didn't Know About Pasta
 
Top 10 Most Eaten Foods In The World
Top 10 Most Eaten Foods In The WorldTop 10 Most Eaten Foods In The World
Top 10 Most Eaten Foods In The World
 
6 Questions to Lead You to a Social Media Strategy
6 Questions to Lead You to a Social Media Strategy6 Questions to Lead You to a Social Media Strategy
6 Questions to Lead You to a Social Media Strategy
 
Project planning and project work plan
Project planning and project work planProject planning and project work plan
Project planning and project work plan
 
11 Things Healthy People Do Every Morning
11 Things Healthy People Do Every Morning11 Things Healthy People Do Every Morning
11 Things Healthy People Do Every Morning
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
Social Media for Business
Social Media for BusinessSocial Media for Business
Social Media for Business
 

Similar to Unit 6

5-Chapter Five - Concurrenc.ppt
5-Chapter Five - Concurrenc.ppt5-Chapter Five - Concurrenc.ppt
5-Chapter Five - Concurrenc.ppt
DadiTesfaye
 
Dbms ii mca-ch10-concurrency-control-2013
Dbms ii mca-ch10-concurrency-control-2013Dbms ii mca-ch10-concurrency-control-2013
Dbms ii mca-ch10-concurrency-control-2013
Prosanta Ghosh
 
Chapter 4 Concrruncy controling techniques (1).ppt
Chapter 4 Concrruncy controling techniques (1).pptChapter 4 Concrruncy controling techniques (1).ppt
Chapter 4 Concrruncy controling techniques (1).ppt
binaboss24
 
Chapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.pptChapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.ppt
haymanot taddesse
 
Adbms 41 transaction control techniques
Adbms 41 transaction control techniquesAdbms 41 transaction control techniques
Adbms 41 transaction control techniques
Vaibhav Khanna
 
concurrency-control-techniques.ppt
concurrency-control-techniques.pptconcurrency-control-techniques.ppt
concurrency-control-techniques.ppt
kushvithchinna900
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
Christalin Nelson
 
concurrency control
concurrency controlconcurrency control
concurrency control
rajshreemuthiah
 
Concurrency Control & Deadlock Handling
Concurrency Control & Deadlock HandlingConcurrency Control & Deadlock Handling
Concurrency Control & Deadlock Handling
Meghaj Mallick
 
db unit 4 dbms protocols in transaction
db unit 4 dbms  protocols in transactiondb unit 4 dbms  protocols in transaction
db unit 4 dbms protocols in transaction
Kumari Naveen
 
Characteristics Schedule based on Recover-ability & Serial-ability
Characteristics Schedule based on Recover-ability & Serial-abilityCharacteristics Schedule based on Recover-ability & Serial-ability
Characteristics Schedule based on Recover-ability & Serial-ability
Meghaj Mallick
 
recoverability and serializability dbms
recoverability and serializability  dbmsrecoverability and serializability  dbms
recoverability and serializability dbms
Kumari Naveen
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
Megha Patel
 
Cs501 concurrency
Cs501 concurrencyCs501 concurrency
Cs501 concurrency
Kamal Singh Lodhi
 
Transactions
TransactionsTransactions
Transactionskalyan_bu
 
Os unit 3
Os unit 3Os unit 3
Os unit 3
Krupali Mistry
 
Concurrency control!
Concurrency control!Concurrency control!
Concurrency control!
Ashish K
 
Adbms 42 deadlocks and starvation
Adbms 42 deadlocks and starvationAdbms 42 deadlocks and starvation
Adbms 42 deadlocks and starvation
Vaibhav Khanna
 
Unit 5 rdbms study_material
Unit 5  rdbms study_materialUnit 5  rdbms study_material
Unit 5 rdbms study_material
gayaramesh
 

Similar to Unit 6 (20)

5-Chapter Five - Concurrenc.ppt
5-Chapter Five - Concurrenc.ppt5-Chapter Five - Concurrenc.ppt
5-Chapter Five - Concurrenc.ppt
 
Dbms ii mca-ch10-concurrency-control-2013
Dbms ii mca-ch10-concurrency-control-2013Dbms ii mca-ch10-concurrency-control-2013
Dbms ii mca-ch10-concurrency-control-2013
 
Chapter 4 Concrruncy controling techniques (1).ppt
Chapter 4 Concrruncy controling techniques (1).pptChapter 4 Concrruncy controling techniques (1).ppt
Chapter 4 Concrruncy controling techniques (1).ppt
 
Chapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.pptChapter Three _Concurrency Control Techniques_ETU.ppt
Chapter Three _Concurrency Control Techniques_ETU.ppt
 
Adbms 41 transaction control techniques
Adbms 41 transaction control techniquesAdbms 41 transaction control techniques
Adbms 41 transaction control techniques
 
concurrency-control-techniques.ppt
concurrency-control-techniques.pptconcurrency-control-techniques.ppt
concurrency-control-techniques.ppt
 
2 con control
2 con control2 con control
2 con control
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
concurrency control
concurrency controlconcurrency control
concurrency control
 
Concurrency Control & Deadlock Handling
Concurrency Control & Deadlock HandlingConcurrency Control & Deadlock Handling
Concurrency Control & Deadlock Handling
 
db unit 4 dbms protocols in transaction
db unit 4 dbms  protocols in transactiondb unit 4 dbms  protocols in transaction
db unit 4 dbms protocols in transaction
 
Characteristics Schedule based on Recover-ability & Serial-ability
Characteristics Schedule based on Recover-ability & Serial-abilityCharacteristics Schedule based on Recover-ability & Serial-ability
Characteristics Schedule based on Recover-ability & Serial-ability
 
recoverability and serializability dbms
recoverability and serializability  dbmsrecoverability and serializability  dbms
recoverability and serializability dbms
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMS
 
Cs501 concurrency
Cs501 concurrencyCs501 concurrency
Cs501 concurrency
 
Transactions
TransactionsTransactions
Transactions
 
Os unit 3
Os unit 3Os unit 3
Os unit 3
 
Concurrency control!
Concurrency control!Concurrency control!
Concurrency control!
 
Adbms 42 deadlocks and starvation
Adbms 42 deadlocks and starvationAdbms 42 deadlocks and starvation
Adbms 42 deadlocks and starvation
 
Unit 5 rdbms study_material
Unit 5  rdbms study_materialUnit 5  rdbms study_material
Unit 5 rdbms study_material
 

More from Abha Damani (20)

Unit2
Unit2Unit2
Unit2
 
Unit6
Unit6Unit6
Unit6
 
Unit5
Unit5Unit5
Unit5
 
Unit4
Unit4Unit4
Unit4
 
Unit3
Unit3Unit3
Unit3
 
Unit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingUnit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programming
 
Ch14
Ch14Ch14
Ch14
 
Ch12
Ch12Ch12
Ch12
 
Ch11
Ch11Ch11
Ch11
 
Ch10
Ch10Ch10
Ch10
 
Ch08
Ch08Ch08
Ch08
 
Ch01 enterprise
Ch01 enterpriseCh01 enterprise
Ch01 enterprise
 
3 data mgmt
3 data mgmt3 data mgmt
3 data mgmt
 
2 it supp_sys
2 it supp_sys2 it supp_sys
2 it supp_sys
 
1 org.perf it supp_appl
1 org.perf it supp_appl1 org.perf it supp_appl
1 org.perf it supp_appl
 
Managing and securing the enterprise
Managing and securing the enterpriseManaging and securing the enterprise
Managing and securing the enterprise
 
Ch6
Ch6Ch6
Ch6
 
Unit2
Unit2Unit2
Unit2
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 4
Unit 4Unit 4
Unit 4
 

Recently uploaded

The Parable of the Pipeline a book every new businessman or business student ...
The Parable of the Pipeline a book every new businessman or business student ...The Parable of the Pipeline a book every new businessman or business student ...
The Parable of the Pipeline a book every new businessman or business student ...
awaisafdar
 
Buy Verified PayPal Account | Buy Google 5 Star Reviews
Buy Verified PayPal Account | Buy Google 5 Star ReviewsBuy Verified PayPal Account | Buy Google 5 Star Reviews
Buy Verified PayPal Account | Buy Google 5 Star Reviews
usawebmarket
 
What is the TDS Return Filing Due Date for FY 2024-25.pdf
What is the TDS Return Filing Due Date for FY 2024-25.pdfWhat is the TDS Return Filing Due Date for FY 2024-25.pdf
What is the TDS Return Filing Due Date for FY 2024-25.pdf
seoforlegalpillers
 
Enterprise Excellence is Inclusive Excellence.pdf
Enterprise Excellence is Inclusive Excellence.pdfEnterprise Excellence is Inclusive Excellence.pdf
Enterprise Excellence is Inclusive Excellence.pdf
KaiNexus
 
FINAL PRESENTATION.pptx12143241324134134
FINAL PRESENTATION.pptx12143241324134134FINAL PRESENTATION.pptx12143241324134134
FINAL PRESENTATION.pptx12143241324134134
LR1709MUSIC
 
ikea_woodgreen_petscharity_dog-alogue_digital.pdf
ikea_woodgreen_petscharity_dog-alogue_digital.pdfikea_woodgreen_petscharity_dog-alogue_digital.pdf
ikea_woodgreen_petscharity_dog-alogue_digital.pdf
agatadrynko
 
Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...
dylandmeas
 
-- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month ---- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month --
NZSG
 
Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024
FelixPerez547899
 
The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...
Adam Smith
 
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.docBài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
daothibichhang1
 
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdfSearch Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Arihant Webtech Pvt. Ltd
 
Authentically Social Presented by Corey Perlman
Authentically Social Presented by Corey PerlmanAuthentically Social Presented by Corey Perlman
Authentically Social Presented by Corey Perlman
Corey Perlman, Social Media Speaker and Consultant
 
Recruiting in the Digital Age: A Social Media Masterclass
Recruiting in the Digital Age: A Social Media MasterclassRecruiting in the Digital Age: A Social Media Masterclass
Recruiting in the Digital Age: A Social Media Masterclass
LuanWise
 
Kseniya Leshchenko: Shared development support service model as the way to ma...
Kseniya Leshchenko: Shared development support service model as the way to ma...Kseniya Leshchenko: Shared development support service model as the way to ma...
Kseniya Leshchenko: Shared development support service model as the way to ma...
Lviv Startup Club
 
VAT Registration Outlined In UAE: Benefits and Requirements
VAT Registration Outlined In UAE: Benefits and RequirementsVAT Registration Outlined In UAE: Benefits and Requirements
VAT Registration Outlined In UAE: Benefits and Requirements
uae taxgpt
 
Business Valuation Principles for Entrepreneurs
Business Valuation Principles for EntrepreneursBusiness Valuation Principles for Entrepreneurs
Business Valuation Principles for Entrepreneurs
Ben Wann
 
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBdCree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
creerey
 
Improving profitability for small business
Improving profitability for small businessImproving profitability for small business
Improving profitability for small business
Ben Wann
 
Creative Web Design Company in Singapore
Creative Web Design Company in SingaporeCreative Web Design Company in Singapore
Creative Web Design Company in Singapore
techboxsqauremedia
 

Recently uploaded (20)

The Parable of the Pipeline a book every new businessman or business student ...
The Parable of the Pipeline a book every new businessman or business student ...The Parable of the Pipeline a book every new businessman or business student ...
The Parable of the Pipeline a book every new businessman or business student ...
 
Buy Verified PayPal Account | Buy Google 5 Star Reviews
Buy Verified PayPal Account | Buy Google 5 Star ReviewsBuy Verified PayPal Account | Buy Google 5 Star Reviews
Buy Verified PayPal Account | Buy Google 5 Star Reviews
 
What is the TDS Return Filing Due Date for FY 2024-25.pdf
What is the TDS Return Filing Due Date for FY 2024-25.pdfWhat is the TDS Return Filing Due Date for FY 2024-25.pdf
What is the TDS Return Filing Due Date for FY 2024-25.pdf
 
Enterprise Excellence is Inclusive Excellence.pdf
Enterprise Excellence is Inclusive Excellence.pdfEnterprise Excellence is Inclusive Excellence.pdf
Enterprise Excellence is Inclusive Excellence.pdf
 
FINAL PRESENTATION.pptx12143241324134134
FINAL PRESENTATION.pptx12143241324134134FINAL PRESENTATION.pptx12143241324134134
FINAL PRESENTATION.pptx12143241324134134
 
ikea_woodgreen_petscharity_dog-alogue_digital.pdf
ikea_woodgreen_petscharity_dog-alogue_digital.pdfikea_woodgreen_petscharity_dog-alogue_digital.pdf
ikea_woodgreen_petscharity_dog-alogue_digital.pdf
 
Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...Discover the innovative and creative projects that highlight my journey throu...
Discover the innovative and creative projects that highlight my journey throu...
 
-- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month ---- June 2024 is National Volunteer Month --
-- June 2024 is National Volunteer Month --
 
Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024Company Valuation webinar series - Tuesday, 4 June 2024
Company Valuation webinar series - Tuesday, 4 June 2024
 
The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...The Influence of Marketing Strategy and Market Competition on Business Perfor...
The Influence of Marketing Strategy and Market Competition on Business Perfor...
 
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.docBài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
Bài tập - Tiếng anh 11 Global Success UNIT 1 - Bản HS.doc
 
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdfSearch Disrupted Google’s Leaked Documents Rock the SEO World.pdf
Search Disrupted Google’s Leaked Documents Rock the SEO World.pdf
 
Authentically Social Presented by Corey Perlman
Authentically Social Presented by Corey PerlmanAuthentically Social Presented by Corey Perlman
Authentically Social Presented by Corey Perlman
 
Recruiting in the Digital Age: A Social Media Masterclass
Recruiting in the Digital Age: A Social Media MasterclassRecruiting in the Digital Age: A Social Media Masterclass
Recruiting in the Digital Age: A Social Media Masterclass
 
Kseniya Leshchenko: Shared development support service model as the way to ma...
Kseniya Leshchenko: Shared development support service model as the way to ma...Kseniya Leshchenko: Shared development support service model as the way to ma...
Kseniya Leshchenko: Shared development support service model as the way to ma...
 
VAT Registration Outlined In UAE: Benefits and Requirements
VAT Registration Outlined In UAE: Benefits and RequirementsVAT Registration Outlined In UAE: Benefits and Requirements
VAT Registration Outlined In UAE: Benefits and Requirements
 
Business Valuation Principles for Entrepreneurs
Business Valuation Principles for EntrepreneursBusiness Valuation Principles for Entrepreneurs
Business Valuation Principles for Entrepreneurs
 
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBdCree_Rey_BrandIdentityKit.PDF_PersonalBd
Cree_Rey_BrandIdentityKit.PDF_PersonalBd
 
Improving profitability for small business
Improving profitability for small businessImproving profitability for small business
Improving profitability for small business
 
Creative Web Design Company in Singapore
Creative Web Design Company in SingaporeCreative Web Design Company in Singapore
Creative Web Design Company in Singapore
 

Unit 6

  • 2. Content  Types of locks and system lock tables  Serializablility by Two-Phase Locking  Dealing with Deadlock and Starvation  Timestamp ordering  Validation concurrency control
  • 3. Types of Lock  Some of the main technique used to control concurrent execution of transaction are based on the concept of locking data items.  Types of Lock  Binary Lock :  Shared/Exclusive ( Read/Write) Lock
  • 4. Binary Lock  A Binary Lock can have two state or values:  Lock  Unlock  1 -> indicates locked  0 -> indicates unlocked.
  • 5. Locking • Locking is an operation which secures (a) permission to Read or (b) permission to Write a data item for a transaction. • A distinct lock is associated with each database item x. • A value of lock(x)=1 • A value x can not be accessed by database operation that request the item. • Example: Lock (X) • Data item X is locked in behalf of the requesting transaction.
  • 6. Unlocking • Unlocking is an operation which removes these permissions from the data item • Example: Unlock (X). • Data item X is made available to all other transactions. • Lock and Unlock are Atomic operations.
  • 7. Exclusive/Shared Lock • Two locks modes (a) shared (read) (b) exclusive (write) • Shared mode: Shared lock (X). • More than one transaction can apply share lock on X for reading its value but no write lock can be applied on X by any other transaction.
  • 8. Exclusive/Shared Lock • Exclusive mode : Write lock (X). • Only one write lock on X can exist at any time and no shared lock can be applied by any other transaction on X. • If transaction have exclusive lock then no transaction have exclusive lock on same item.
  • 9. Lock table and Lock manager  Lock table :  The system need to maintain only these record for the item that are concurrently locked in a Lock table.  Lock table is organize as a hash file.  Item not in lock table are consider to be unlocked. Transaction ID Data item id lock mode Ptr to next data item T1 X1 Read Next  Lock Manager :  Managing locks on data items.
  • 10.  Database requires that all transactions should be well- formed.  A transaction is well-formed if: • It must lock the data item before it reads or writes to it. • It must not lock an already locked data items and it must not try to unlock a free data item.
  • 11. Lock Operation of Binary Lock Lock_item(X) : B: if LOCK (X) = 0 (* item is unlocked*) then LOCK (X) 1 (*lock the item*) else begin wait (until lock (X) = 0) the lock manager wakes up the transaction; goto B end;
  • 12. unlock Operation of Binary Lock unlock_item(X) : LOCK (X) 0 (*unlock the item*) if any transactions are waiting then wake up one of the waiting the transactions;
  • 13. Rules for transaction in binary locking scheme 1. A transaction T must issue the operation lock_item(X) before any read_item(X) or write_item(X) operation performed in T. 2. A transaction T must issue the operation unlock_item(X) after all read_item(X) and write_item(X) operation completed in T. 3. A transaction T will not issue a lock_item(X) operation if it already hold lock on item X. 4. A transaction T will not issue a unlock_item(X) operation unless it already hold lock on item X.
  • 14. Lock Operation of Shared Lock read_item(X) : B: if LOCK (X) = “unlocked” then begin LOCK (X) “read-locked”; no_of_reads (X) 1; end else if LOCK (X) “read-locked” then no_of_reads (X) no_of_reads (X) +1 else begin wait (until LOCK (X) = “unlocked” and the lock manager wakes up the transaction); go to B end;
  • 15. Lock Operation of exclusive Lock write_item(X) : B: if LOCK (X) = “unlocked” then LOCK (X) “write-locked”; else begin wait (until LOCK (X) = “unlocked” and the lock manager wakes up the transaction); go to B end;
  • 16. Unlock Operation for two-mode Unlock(x) : if LOCK (X) = “write-locked” then begin LOCK (X) “unlocked”; wake up on of the waiting transaction, if any end else if LOCK (X) = “read-locked” then begin no_of_read(X) no_of_read(X)-1 ; if no_of_read(X) =0 then begin LOCK (X) “unlocked”; wake up on of the waiting transaction, if any end end;
  • 17. Rules for transaction in shared/exclusive locking scheme 1. A transaction T must issue the operation read_lock(X) or write_lock(X) before any read_item(X) operation performed in T. 2. A transaction T must issue the operation write_lock(X) before write_item(X) operation perforemed in T. 3. A transaction T must issue the operation unlock(X) after all write_item(X) operation are completed in T.
  • 18. Rules for transaction in shared/exclusive locking scheme 4. A transaction T will not issue a read_lock(X) operation if it already holds a read(shared) lock or a write(exclusive) lock on item X. 5. A transaction T will not issue a write_lock(X) operation if it already holds a read(shared) lock or a write(exclusive) lock on item X. 6. A transaction T will not issue an unlock(x) operation unless it already holds a read(shared) lock or a write(exclusive) lock on item X.
  • 19. Serializablility by Two Phase Locking  A transaction is said to follow the two-phase locking protocol if all locking operations (read_lock, write_lock) precede the first unlock operation in the transaction.  Such transaction can be divided in to 2 phase  Expanding or Growing (first) Phase  Shrinking (Second) Phase
  • 20. Serializablility by Two Phase Locking  Locking (Growing) Phase: In this phase new locks on the items can be acquired but none can be released.  A transaction applies locks (read or write) on desired data items one at a time.(Gain Lock)  Unlocking (Shrinking) Phase: In this phase existing lock can be released but no new lock can be acquired.  A transaction unlocks its locked data items one at a time.(Release Lock)  Requirement: For a transaction these two phases must be mutually exclusively, that is,  During locking phase unlocking phase must not start  During unlocking phase locking phase must not begin.
  • 21. Serial Schedule of T1 and T2 T1 T2 Result read_lock (Y); read_lock (X); Initial values: X=20; Y=30 read_item (Y); read_item (X); Result of serial execution unlock (Y); unlock (X); T1 followed by T2 write_lock (X); Write_lock (Y); X=50, Y=80. read_item (X); read_item (Y); Result of serial execution X:=X+Y; Y:=X+Y; T2 followed by T1 write_item (X); write_item (Y); X=70, Y=50 unlock (X); unlock (Y);
  • 22. Problem to violated to phase locking Protocol T1 T2 Read_lock(Y) read_item (Y); unlock (Y); Result : read_lock (X); X=50; Y=50 read_item (X); unlock (X); write_lock (Y); Non-Serializable read_item (Y); because it violated Y:=X+Y; two phase policy. write_item (Y); unlock (Y); write_lock (X); read_item (X); X:=X+Y; write_item (X); unlock (X)
  • 23. T1 T2 Read_lock(Y) read_lock (X); read_item (Y); read_item (X); write_lock (X); write_lock (Y); unlock (Y); unlock (X); read_item (X); read_item (Y); X:=X+Y; Y:=X+Y; write_item (X); write_item (Y); unlock (X) unlock (Y);  Follows Two phase locking protocols
  • 24. Two phase locking protocols  Advantage:  It produce Serializable schedule.  Problem With two phase locking protocols  Two phase locking protocols can produce deadlock.
  • 25. Lock conversion  Lock upgrade: existing read lock to write lock if Ti has a read-lock (X) and Tj has no read-lock (X) (i j) then convert read-lock (X) to write-lock (X) else force Ti to wait until Tj unlocks X  Lock downgrade: existing write lock to read lock Ti has a write-lock (X) (*no transaction can have any lock on X*) convert write-lock (X) to read-lock (X)
  • 26. Variation of two phase locking  Two-phase policy generates two locking algorithms  Basic  Conservative.  Conservative:  Prevents deadlock by locking all desired data items before transaction begins execution by pre-declaring its read-set and write-set.  Deadlock free protocol
  • 27. Terms in two-phase locking protocols  Strict 2PL :  A transaction must released all it’s exclusive lock only when it is committed or abort.  Transaction T does not released any of its exclusive lock until after commit or aborts.  Rigorous 2PL :  A transaction must released all it’s lock only when it’s commit or abort.  Transaction T does not released any of its lock(exclusive or Shared) until after commit or aborts.  It is easier to implement than strict 2PL.
  • 28. Deadlock  Deadlock occurs when each transaction T in a set of two r more transaction is waiting for some item that is locked by some other transaction T’ in the set.  Hence each transaction in the set is on a waiting queue, waiting for one of the other transaction in the set to release the lock on an item.
  • 29. Deadlock T1 T2 read_lock (Y) read_item(Y) read_lock (X) T1 and T2 did follow two- read_item(X) phase policy but they are write_lock (X) (waits for X) deadlock write_lock (Y); (waits for Y)
  • 30. 3. Dealing with Deadlock  There are several ways to dealing with deadlock  Deadlock prevention  Deadlock detection  Prevent Starvation
  • 31. Deadlock prevention  Deadlock prevention protocols ensure that the system will never enter into a deadlock state.  Some prevention strategies : 1. Require that each transaction locks all its data items before it begins execution (pre-declaration).  The conservative two-phase locking uses this approach 2. On the basis of transaction timestamp TS(T)
  • 32. Transaction Timestamp TP(S)  Transaction timestamp is a unique identifier assigned to each transaction.  It is based on the order in which transaction are started.  If transaction T1 starts before transaction T2 then TS(T1 ) < TS(T2)  Older transaction has smaller timestamp value.  Two scheme that prevent deadlock 1. Wait-Die 2. Wound-Wait
  • 33. Deadlock prevention Scheme.  wait-die scheme — non-preemptive If TS(i)< TS(j), then (Ti older than Tj) Ti allowed to wait; otherwise (Ti younger than Tj) abort Ti(Ti dies) and restart it later with the same timestamp.  Older transaction may wait for younger one to release data item. Younger transactions never wait for older ones; they are rolled back instead.  A transaction may die several times before acquiring needed data item
  • 34.  wound-wait scheme — preemptive If TS(i)< TS(j), then (Ti older than Tj) abort Tj (Ti wounds Tj) restart it later with the same timestamp. otherwise (Ti younger than Tj) Ti allowed to wait  older transaction wounds (forces rollback) of younger transaction instead of waiting for it. Younger transactions may wait for older ones.  may be fewer rollbacks than wait-die scheme.
  • 35. Deadlock detection and resolution  In this approach, deadlocks are allowed to happen.  The scheduler maintains a wait-for-graph for detecting cycle.  If a cycle exists, then one transaction involved in the cycle is selected (victim) and rolled-back.  A wait-for-graph is created using the lock table.  As soon as a transaction is blocked, it is added to the graph. When a chain like:  Ti waits for Tj waits for Tk waits for Ti or Tj occurs, then this creates a cycle.  One of the transaction of the cycle is selected and rolled back.
  • 36. Starvation  Starvation :it occurs when a transaction cannot proceed for an indefinite period of time while other transaction in the system continue normally.  This may occur if the waiting scheme for locked items is unfair.  Solution of Starvation :  First come first served  Based on priority  But increased the priority of the transaction the longer it waits. until it get highest priority.
  • 37. Concurrency control based on timestamp ordering Timestamp  Transaction timestamp is a unique identifier assigned to each transaction.  It is based on the order in which transaction are started.  A larger timestamp value indicates a more recent event or operation.  Timestamp based algorithm uses timestamp to serialize the execution of concurrent transactions.
  • 38. Timestamp ordering algorithm  Timestamp Ordering : A schedule in which the transaction participate is then Serializable and equivalent serial schedule has the transaction in order of their timestamp value this is called timestamp ordering.  order of accessed item that does not violate serializablility order, for that algorithm associated with each database item X is used.
  • 39.  read_TS(X)  The read timestamp of item X; this is largest timestamp among all the timestamp of transaction that have successfully read item X.  read_TS(X)=TS(T)  Where T is the youngest transaction that has read X successfully.  write_TS(X)  The write timestamp of item X; this is largest timestamp among all the timestamp of transaction that have successfully written item X.  weite_TS(X)=TS(T)  Where T is the youngest transaction that has written X successfully.
  • 40. Timestamp based concurrency control algorithm Basic Timestamp Ordering 1. Transaction T issues a write_item(X) operation: a. If read_TS(X) > TS(T) or if write_TS(X) > TS(T), then abort and roll-back T and reject the operation. (younger transaction has already read the data item) b. If the condition in part (a) does not exist, then execute write_item(X) of T and set write_TS(X) to TS(T).
  • 41. Timestamp based concurrency control algorithm Basic Timestamp Ordering 2. Transaction T issues a read_item(X) operation: a. If write_TS(X) > TS(T), then abort and roll-back T and reject the operation. (younger transaction has already written to the data item ) b. If write_TS(X) TS(T), then execute read_item(X) of T and set read_TS(X) to the larger of TS(T) and the current read_TS(X).
  • 42.  Advantage :  Basic TO always produce conflict Serializable schedule.  Deadlock does not occur.  Problem with Basic TO  Cyclic restart may occur if a transaction is continually aborted and restarted.  A Modification of Basic TO algorithm is known as Thomas’s write rule.  It does not enforce conflict serializability  But it reject fewer write operation by modifying the checks for the write_item(X) operation.
  • 43. Timestamp based concurrency control algorithm Thomas’s Write Rule 1. If read_TS(X) > TS(T) then abort and roll-back T and reject the operation. 2. If write_TS(X) > TS(T), then just ignore the write operation and continue execution. This is because the most recent writes counts in case of two consecutive writes. 3. If the conditions given in 1 and 2 above do not occur, then execute write_item(X) of T and set write_TS(X) to TS(T).
  • 44. Validation concurrency control techniques  optimistic concurrency control technique (validation or certification technique)  No checking is done while the transaction is executing.  It follows some scheme.  In this scheme , updation in the transaction are not applied directly to the database item until the transaction reaches it end.  All updation applied to local copies of data item that are kept for transaction.  At the end of transaction, concurrency control phases checks whether any of transaction’s updates violates serializability or not.
  • 45. Three phases of concurrency control protocol  Read Phase:  A transaction can read values of committed data items from the database.  However , updation are applied only to local copies of data items.  Validation Phase :  Checking is performed to ensure that serializability will not be violated if transaction updates are applied to the database.  Write Phase  If validation phase is successful, the transaction updates are applied to the database;  Otherwise , the updates are discarded and the transaction is restarted .
  • 46. Validation Phase  This phase for Ti checks that, for each transaction Tj that is either committed or is in its validation phase, one of the following conditions holds: 1. Tj completes its write phase before Ti starts its read phase. 2. Ti starts its write phase after Tj completes its write phase, and the read_set of Ti has no items in common with the write_set of Tj 3. Both the read_set and write_set of Ti have no items in common with the write_set of Tj, and Tj completes its end phase.