SlideShare uma empresa Scribd logo
1 de 47
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

Mais conteúdo relacionado

Mais procurados

Validation based protocol
Validation based protocolValidation based protocol
Validation based protocolBBDITM LUCKNOW
 
Concurrency Control Techniques
Concurrency Control TechniquesConcurrency Control Techniques
Concurrency Control TechniquesRaj vardhan
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating SystemJanki Shah
 
11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMSkoolkampus
 
Nested queries in database
Nested queries in databaseNested queries in database
Nested queries in databaseSatya P. Joshi
 
Network Layer design Issues.pptx
Network Layer design Issues.pptxNetwork Layer design Issues.pptx
Network Layer design Issues.pptxAcad
 
File organization 1
File organization 1File organization 1
File organization 1Rupali Rana
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignmentKarthi Keyan
 
Databases: Locking Methods
Databases: Locking MethodsDatabases: Locking Methods
Databases: Locking MethodsDamian T. Gordon
 
Distributed database management system
Distributed database management  systemDistributed database management  system
Distributed database management systemPooja Dixit
 
Transaction management
Transaction managementTransaction management
Transaction managementrenuka_a
 
Transactions in dbms
Transactions in dbmsTransactions in dbms
Transactions in dbmsNancy Gulati
 
Recovery with concurrent transaction
Recovery with concurrent transactionRecovery with concurrent transaction
Recovery with concurrent transactionlavanya marichamy
 

Mais procurados (20)

Validation based protocol
Validation based protocolValidation based protocol
Validation based protocol
 
Concurrency Control Techniques
Concurrency Control TechniquesConcurrency Control Techniques
Concurrency Control Techniques
 
Schedule in DBMS
Schedule in DBMSSchedule in DBMS
Schedule in DBMS
 
Serializability
SerializabilitySerializability
Serializability
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating System
 
11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS11. Storage and File Structure in DBMS
11. Storage and File Structure in DBMS
 
Nested queries in database
Nested queries in databaseNested queries in database
Nested queries in database
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
Network Layer design Issues.pptx
Network Layer design Issues.pptxNetwork Layer design Issues.pptx
Network Layer design Issues.pptx
 
File organization 1
File organization 1File organization 1
File organization 1
 
Locking in SQL Server
Locking in SQL ServerLocking in SQL Server
Locking in SQL Server
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
 
Databases: Locking Methods
Databases: Locking MethodsDatabases: Locking Methods
Databases: Locking Methods
 
Distributed database management system
Distributed database management  systemDistributed database management  system
Distributed database management system
 
Deadlock dbms
Deadlock dbmsDeadlock dbms
Deadlock dbms
 
Transaction management
Transaction managementTransaction management
Transaction management
 
Telnet presentation
Telnet presentationTelnet presentation
Telnet presentation
 
Transactions in dbms
Transactions in dbmsTransactions in dbms
Transactions in dbms
 
Recovery with concurrent transaction
Recovery with concurrent transactionRecovery with concurrent transaction
Recovery with concurrent transaction
 

Destaque

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 TypesNMSU - 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 - SysomosSysomos
 
The 6 types of social media
The 6 types of social mediaThe 6 types of social media
The 6 types of social mediaTennycut
 
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 ReviewPaban S. Mohanty
 
The Ultimate Marketing Guide to Snapchat
The Ultimate Marketing Guide to SnapchatThe Ultimate Marketing Guide to Snapchat
The Ultimate Marketing Guide to SnapchatRoss 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 controlDhani 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 PastaJodie 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 WorldEason 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 StrategyMark Schaefer
 
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 MorningEason Chan
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming LanguageAhmad Idrees
 

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

Semelhante a Unit 6

5-Chapter Five - Concurrenc.ppt
5-Chapter Five - Concurrenc.ppt5-Chapter Five - Concurrenc.ppt
5-Chapter Five - Concurrenc.pptDadiTesfaye
 
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-2013Prosanta 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).pptbinaboss24
 
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.ppthaymanot taddesse
 
Adbms 41 transaction control techniques
Adbms 41 transaction control techniquesAdbms 41 transaction control techniques
Adbms 41 transaction control techniquesVaibhav Khanna
 
concurrency-control-techniques.ppt
concurrency-control-techniques.pptconcurrency-control-techniques.ppt
concurrency-control-techniques.pptkushvithchinna900
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Concurrency Control & Deadlock Handling
Concurrency Control & Deadlock HandlingConcurrency Control & Deadlock Handling
Concurrency Control & Deadlock HandlingMeghaj 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 transactionKumari 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-abilityMeghaj Mallick
 
recoverability and serializability dbms
recoverability and serializability  dbmsrecoverability and serializability  dbms
recoverability and serializability dbmsKumari Naveen
 
Transaction management DBMS
Transaction  management DBMSTransaction  management DBMS
Transaction management DBMSMegha Patel
 
Transactions
TransactionsTransactions
Transactionskalyan_bu
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management SystemJanki Shah
 
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 starvationVaibhav Khanna
 

Semelhante a 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
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management System
 
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
 

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

Último

Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfJos Voskuil
 
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...lizamodels9
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...ssuserf63bd7
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCRashishs7044
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCRashishs7044
 
8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCRashishs7044
 
Kenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby AfricaKenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby Africaictsugar
 
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,noida100girls
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03DallasHaselhorst
 
Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Riya Pathan
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Kirill Klimov
 
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...ictsugar
 
Call Girls Miyapur 7001305949 all area service COD available Any Time
Call Girls Miyapur 7001305949 all area service COD available Any TimeCall Girls Miyapur 7001305949 all area service COD available Any Time
Call Girls Miyapur 7001305949 all area service COD available Any Timedelhimodelshub1
 
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...lizamodels9
 
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckPitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckHajeJanKamps
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaoncallgirls2057
 
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...lizamodels9
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesKeppelCorporation
 
Market Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMarket Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMintel Group
 

Último (20)

Digital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdfDigital Transformation in the PLM domain - distrib.pdf
Digital Transformation in the PLM domain - distrib.pdf
 
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
Call Girls In Radisson Blu Hotel New Delhi Paschim Vihar ❤️8860477959 Escorts...
 
International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...International Business Environments and Operations 16th Global Edition test b...
International Business Environments and Operations 16th Global Edition test b...
 
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
8447779800, Low rate Call girls in Kotla Mubarakpur Delhi NCR
 
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
8447779800, Low rate Call girls in Uttam Nagar Delhi NCR
 
8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR8447779800, Low rate Call girls in Saket Delhi NCR
8447779800, Low rate Call girls in Saket Delhi NCR
 
Kenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby AfricaKenya’s Coconut Value Chain by Gatsby Africa
Kenya’s Coconut Value Chain by Gatsby Africa
 
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
BEST Call Girls In Old Faridabad ✨ 9773824855 ✨ Escorts Service In Delhi Ncr,
 
Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03Cybersecurity Awareness Training Presentation v2024.03
Cybersecurity Awareness Training Presentation v2024.03
 
Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737Independent Call Girls Andheri Nightlaila 9967584737
Independent Call Girls Andheri Nightlaila 9967584737
 
Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024Flow Your Strategy at Flight Levels Day 2024
Flow Your Strategy at Flight Levels Day 2024
 
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...Global Scenario On Sustainable  and Resilient Coconut Industry by Dr. Jelfina...
Global Scenario On Sustainable and Resilient Coconut Industry by Dr. Jelfina...
 
Call Girls Miyapur 7001305949 all area service COD available Any Time
Call Girls Miyapur 7001305949 all area service COD available Any TimeCall Girls Miyapur 7001305949 all area service COD available Any Time
Call Girls Miyapur 7001305949 all area service COD available Any Time
 
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
Call Girls In Sikandarpur Gurgaon ❤️8860477959_Russian 100% Genuine Escorts I...
 
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deckPitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
Pitch Deck Teardown: Geodesic.Life's $500k Pre-seed deck
 
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City GurgaonCall Us 📲8800102216📞 Call Girls In DLF City Gurgaon
Call Us 📲8800102216📞 Call Girls In DLF City Gurgaon
 
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
Lowrate Call Girls In Sector 18 Noida ❤️8860477959 Escorts 100% Genuine Servi...
 
Annual General Meeting Presentation Slides
Annual General Meeting Presentation SlidesAnnual General Meeting Presentation Slides
Annual General Meeting Presentation Slides
 
Market Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 EditionMarket Sizes Sample Report - 2024 Edition
Market Sizes Sample Report - 2024 Edition
 
Corporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information TechnologyCorporate Profile 47Billion Information Technology
Corporate Profile 47Billion Information Technology
 

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.