Jump to content

2 Phase Locking and Deadlocks in DBMS


Recommended Posts

I have a question about the functioning of 2PL and deadlocks. I'm not sure why this is so difficult for me to grasp, but I tried drawing a pseudo sequence diagram to help. Is my understanding of 2PL correct? I am aware that deadlock handling is not exclusive to 2PL.

Is it accurate that if T1 acquires a writelock (exclusive) and T2 tries to acquire a readlock, T2 is obliged to wait? I realise that only one transaction may have a writelock, however according to 2PL, if a transaction is updating (has the writelock), another transaction cannot read (acquire the readlock).

Looking forward

Edited by Phi for All
commercial link removed by moderator
Link to comment
Share on other sites

I can't see the deadlock video('Something went wrong. Please refresh'). Could you post your diagram?

I assume you understand deadlocks in one single RDBMS, but reading in itself usually does not lock any rows (except SQL Server when you are not running it in 'Read Committed Snapshot Isolation Level'. For Oracle this is the default isolation level.

However, in  a distributed transaction between 2 databases, the whole transaction must be prepared until the last 'commit readiness', in such a way that so to speak only one bit must be sent, meaning 'commit now'. This reduces the time gap that can occur via the network. Nothing is allowed to interfer in this time gap. Does that already help? Otherwise, be more specific. You diagram might help.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.