Sunday, 23 February 2014

Database Transaction, Isolation Levels and Locking Mechanism

 

 

image

 

 

image

 

 

image

 

 

 

Bad data Issues

 

Dirty Read

 

image

 

The below are the initial and sample data of this experiment.

 

image

 

 

 

Some sample transactions which changed the value of the records from one value to some other value.

 

image

 

 

First Issue:

Here, the highlighted value “40”  and the second record from last value has been inter changed by the transaction while other transactions reading it.  So, 40$ doesn’t reflected anywhere in our second record set.

 

image

 

 

Second Issue:

Here, the highlighted record “33” in the second records set, this was not committed yet.

image

 

 

 

Third Issue:

Here, the value 15$ red twice by the second transaction and reflected the same in result set.

 

image

 

 

 

Other type of Bad Data issues

image

 

 

 

Locks

image

 

 

image

 

 

SQL Server Lock manager will do the Dynamic locking based on the transaction load.  So, developers does not need to use Lock Hints, which is not preferable.

 

image

 

 

image

 

image

 

image

image

image

 

image

 

 

 

image

 

 

 

Isolation Levels

 

image

 

image

 

image

 

 

image

 

 

 

image

 

 

image

 

 

As per below chart some transaction requires Exclusive Lock (X) on objects, Shared Lock (S) is not possible on the same objects if other transaction requires it.  In our example, No Shared locks requested

 

image

 

 

image

 

 

 

image

 

 

 

image

 

 

image

 

 

 

Dead Lock

 

image

 

 

image

 

 

image

 

image

 

 

 

image

 

 

 

image

 

 

 

Blogger Labels: Database,Transaction,Isolation,Levels,Mechanism,data,Issues,Read,Some,transactions,Issue,Here,Second,Third,Locks,Server,Lock,manager,Dynamic,developers,Hints,Exclusive,example,Dead

No comments:

Post a Comment