Two Phases Locking - 2PL
Two phases locking (2PL) the transactions handles its locking in 2 phases:
- The expanding phase: No lock can be released
- The shrinking phase: No lock can be acquired Locking rules are:
- Read operations will be granted Shared Locks (meaning reads operations can be executed concurrently on the same item)
- Write operations will be grant Exclusive Locks (meaning they are not compatible with any other operations regardless of their types) As this protocol can introduce Deadlock, it was extended to a variant called Conservative 2PL (C2PL), where transactions obtain all the locked required before actually beginning -> they won’t have to wait for other locks. However, due to its greediness, it often causes overhead in light-lock contention. Another variant, Strong strict two-phase locking (SS2PLP) put another constraint in which locks (regardless of type) are released only after transactions end. This implicitly renders the Protocol no longer “2 phases” by “removing phase 2”. This is the one being widely adopted due to its Serializability and Cascadeless Recoverability).