Types of locks, Database Management System

Types of Locks

There are two necessary types of locks:

  • Binary lock: This locking mechanism has two states for to a data item: locked or unlocked
  • Multiple-mode locks: In this locking type every data item can be in 3 states read locked or shared locked, write locked or exclusive locked or unlocked.

Let us first take an instance for binary locking and describes how it solves the concurrency related troubles. Let us reconsider the transactions T1 and T2 for this purpose; though we will add to needed binary locks to them.

Schedule

T1

T2

Lock X

Lock X

 

Read X

Read X

 

Subtract 100

Subtract 100

 

Write X

Write X

 

Unlock X

Unlock X

 

Lock X

 

Lock X

Lock Y

 

Lock Y

Read X

 

Read X

Read Y

 

Read Y

Display X+Y

 

Display X+Y

Unlock X

 

Unlock X

Unlock Y

 

Unlock Y

Lock Y

Lock Y

 

Read Y

Read Y

 

Add 100

Add 100

 

Write Y

Write Y

 

Unlock Y

Unlock Y

 

 

 

 

                                                         Figure: An incorrect locking implementation

Does the locking as completed above solve the problem of concurrent transactions? No the similar problems still remains. Try working with the old value. Therefore, locking should be completed with some logic in order to make sure that locking results in no concurrency related problem. One such answer is given below:

Schedule

T1

T2

Lock X

Lock X

 

Lock Y

Lock Y

 

Read X

Read X

 

Subtract 100

Subtract 100

 

Write X

Write X

 

Lock X (issued by

T2)

Lock X: denied as T1 holds the lock.

The transaction T2 Waits and T1 continues.

Read Y

Read Y

 

Add 100

Add 100

 

Write Y

Write Y

 

Unlock X

Unlock X

 

 

The lock request of T2 on X can now

be granted it can resumes by locking X

Unlock Y

Unlock Y

 

Lock Y

 

Lock Y

Read X

 

Read X

Read Y

 

Read Y

Display X+Y

 

Display X+Y

Unlock X

 

Unlock X

Unlock Y

 

Unlock Y

                                                              Figure: A correct but restrictive locking implementation

Therefore, the locking as above when you get all the locks at the starting of the transaction and release them at the end ensures that transactions are implemented with no concurrency related problems. Though, such a scheme limits the concurrency. We will talk about a two-phase locking method in the next subsection that gives sufficient concurrency. Though, let us first discuss multiple mode locks.

Posted Date: 3/12/2013 2:36:18 AM | Location : United States







Related Discussions:- Types of locks, Assignment Help, Ask Question on Types of locks, Get Answer, Expert's Help, Types of locks Discussions

Write discussion on Types of locks
Your posts are moderated
Related Questions
What are aggregate functions? And list the aggregate functions supported by SQL? Aggregate functions are functions that take a collection of values as input and return a one va


4. Describe three ways to handle missing field values

Which database level is closest to the users? External database level is closest to the users.

Explain the difference between using functions along with and without grouping attributes in relational algebra. Give examples. Ans: Group functions are used to group data of

Explain the term - Control as Concurrent Tasks As we know, any object can be implemented as a task in programming language or operating system. This is the most general approa

When is UPDATE_STATISTICS command used? - When processing of large data is done, this command is used. - Whenever large number of modification, deletions or copy takes place

Components of database manager The above functions are reached by the database manager. The major elements of a database manager are: Authorisation control: This mod

Define entity integrity and referential integrity.  How does SQL allow specification of  these? Ans: Entity Integrity Rule- If the attribute A of relation R is a prime attribut

Recovery Techniques: After Reading the types of failures and database errors, let us talk about how to recover from the failures. Recovery can be complete using/restoring the previ