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
Example :; transfers transfer_amount from x's account to y's account ; Supposes x&y both accounts exist TRANSACTION (x, y, transfer_amount) Start transaction IF X AND Y

In object oriented design, which steps must designer take to adjust inheritance? To readjust inheritance following steps should be taken: i)  Rearrange and adjust the classe

Draw an ER diagram that represents the information described below. Show all entity sets, relationship sets, primary keys, and the mapping cardinality of the relationship sets.

How external/conceptual mapping and conceptual /internal mapping is performed

What are views? Explain how views are different from tables? A view in SQL terminology is a one table in which is derived from other tables. These other tables could be base t

Explain the term- Query. Queries are used to repossess and show specific records in a table. They can also be used to show specific fields of specific records, which meet the co

Explain the term- Data Flows Data Flows: A data flow connects output of an object or process to input of another process or object. It represents an in-between data value wit

(a) Data Mining Process : In the context of this cluster analysis project , and in your own words , explain how you would execute the first stage of data mining, namely the "P

Explain the Difference between DROP and DELETE DELETE deletes one or more than one tuples of a particular relation from the database. DROP is employed to remove a table from th

Critically evaluate the bulleted list of information-related items in this case study. How are each contradictory to the notion of being an information-literate knowledge worker?