- Model question
Concurrency control methods compared
Short answer
Concurrency control coordinates concurrent transactions to achieve serializability. Locking uses shared/exclusive locks with strict two-phase locking; timestamp ordering aborts later transactions to enforce order; optimistic control validates after execution. Locking can cause deadlocks, timestamp ordering incurs restarts, and optimistic excels when conflicts are rare.
Define concurrency control. Explain the different methods of concurrency control. Also make a comparison among them.
Concurrency control
Concurrency control coordinates concurrent transactions on shared data so that the result is equivalent to a serial execution (serial equivalence), avoiding lost updates, inconsistent retrievals and cascading aborts.
Methods
A lock is a variable associated with a data item that controls concurrent access. A transaction must obtain the lock before it reads or writes the item, and releases it when finished. Common modes are read (shared) lock and write (exclusive) lock; several transactions can hold read locks together, but a write lock excludes all others. In two-phase locking (2PL) a transaction has a growing phase (acquires locks) followed by a shrinking phase (releases locks, never acquires again). Strict 2PL holds all locks until commit or abort, which prevents dirty reads and cascading aborts.
| Lock held \ requested | Read | Write |
|---|---|---|
| None | OK | OK |
| Read | OK | Wait |
| Write | Wait | Wait |
Timestamp ordering gives each transaction a unique timestamp when it starts (a Lamport clock or a global timestamp from server id and local clock in a distributed system). Conflicting operations are executed in timestamp order, so the result is equivalent to running transactions serially in timestamp order. No locks are used, so no deadlock.
Each object keeps a write timestamp (of the last committed write) and read timestamps (of transactions that read it). For a transaction T with timestamp Tc:
- Write rule: T's write is allowed only if Tc ≥ the maximum read timestamp of the object and Tc > the write timestamp of the committed version. Otherwise T is aborted (it would invalidate a later read).
- Read rule: T's read is allowed if Tc > the write timestamp of the committed version; if a tentative version from an earlier transaction exists, T waits until it commits or aborts. If Tc is smaller than the write timestamp, T is too late and is aborted.
An aborted transaction restarts with a new, later timestamp. Timestamp ordering is deadlock-free, but it causes restarts; keeping multiple versions of objects reduces the number of aborts.
Optimistic concurrency control (Kung and Robinson) assumes conflicts are rare, so transactions proceed without locks and are checked for conflicts only when they want to commit. A transaction goes through three phases.
- Working phase: it reads and writes tentative copies of objects (private versions). Reads see the last committed values; no locks are taken. The system records the read set and write set.
- Validation phase: when the client requests commit, the server checks for conflicts with other transactions that overlapped in time. If validation fails, the transaction is aborted (or conflict resolution is used).
- Update phase: if validation succeeds, tentative versions are made permanent (written to permanent storage) and the transaction commits.
Validation (backward validation): transaction Tv is checked against earlier overlapping transactions Ti that committed before Tv started validation. Rules:
- If Ti writes an object that Tv reads (Ti's write set ∩ Tv's read set ≠ ∅), validation fails, because Tv read stale data.
- Otherwise Tv passes validation. (Writes are applied in commit order, so write-write conflicts cannot occur.)
Forward validation checks Tv's write set against the read sets of still-active transactions; it allows a choice of aborting Tv or the others.
In a distributed system, each server validates its own part of the transaction during the first phase of two-phase commit, and all servers must validate in the same global order to avoid commitment deadlock and inconsistent serial orders.
Advantages
- No locking, so no deadlock and no lock overhead.
- High concurrency when conflicts are rare; with forward validation, read-only transactions always pass validation.
- Abort is cheap because nothing was written permanently.
Disadvantages
- Under heavy conflicts many transactions abort and restart; starvation is possible.
- Wasted work for aborted transactions.
Comparison
| Point | Locking | Timestamp ordering | Optimistic |
|---|---|---|---|
| Approach | Pessimistic; prevent conflicts | Order by timestamps | Detect conflicts at the end |
| Conflict handling | Wait | Abort and restart | Abort and restart |
| Deadlock | Possible | None | None |
| Overhead | Lock table, lock calls | Timestamps on objects | Read/write sets, validation |
| Best when | Many conflicts | Moderate conflicts | Few conflicts, mostly reads |
| Weakness | Reduced concurrency, deadlock | Many restarts, cascading aborts | Wasted work under heavy conflict |
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Distributed concurrency control methods · Distributed System, chapter 8
- Flat/nested transactions; concurrency control · Distributed System, chapter 8
- Concurrency control goals and mechanisms · Distributed System, chapter 8
- Comparison of G-S and N-R load flow · Power System Analysis II, chapter 2 · asked 3×
- Series versus parallel circuit comparison · Basic Electrical Engineering, chapter 1
- AC vs DC transmission comparison · Transmission and Distribution System Design, chapter 1
- Comparison of DC shunt and series generators · Electrical Machines I, chapter 3