Primary Site Two-Phase Locking

IT 위키

Primary Site Two-Phase Locking (2PL) is a variant of the Two-Phase Locking protocol used in distributed databases. In this approach, one node is designated as the primary site for each data item, and it coordinates the locking and transaction processing to ensure serializability across the system.

Key Concepts[편집 | 원본 편집]

  • Primary Site: A designated node that manages all lock requests for a specific data item.
  • Global Serializability: Ensures that all transactions across distributed nodes maintain a serializable schedule.
  • Coordination: The primary site acts as the single authority for granting or releasing locks, reducing complexity in lock management.

How Primary Site 2PL Works[편집 | 원본 편집]

The Primary Site 2PL protocol operates as follows:

  1. Each data item in the distributed database is assigned to a primary site.
  2. Transactions request locks from the primary site of the data item they wish to access.
  3. The primary site uses the Two-Phase Locking protocol:
    • Growing Phase: Locks are granted to transactions but not released.
    • Shrinking Phase: Locks are released, but no new locks are granted.
  4. Once the primary site grants a lock, the transaction can proceed to access the data at any replica site.

Advantages[편집 | 원본 편집]

  • Centralized Coordination: Simplifies lock management by delegating responsibility to primary sites.
  • Ensures Consistency: By centralizing lock control, Primary Site 2PL ensures consistency across distributed transactions.
  • Scalability: Each primary site manages its own subset of data, reducing bottlenecks.

Limitations[편집 | 원본 편집]

  • Single Point of Failure: If a primary site fails, the data it manages becomes unavailable.
  • Communication Overhead: Lock requests and responses require network communication, increasing latency.
  • Limited Concurrency: Centralized lock management may limit the level of parallelism.

Example of Primary Site 2PL[편집 | 원본 편집]

Consider a distributed database where:

  • Node 1 is the primary site for data item A.
  • Node 2 is the primary site for data item B.

Scenario[편집 | 원본 편집]

Transaction T1 and T2 execute as follows:

Step Transaction T1 Transaction T2 Primary Site Action
1 BEGIN TRANSACTION BEGIN TRANSACTION Both transactions start.
2 READ(A) - T1 requests a shared lock for A from Node 1 (primary site for A).
3 - WRITE(A) T2 requests an exclusive lock for A from Node 1 but must wait as T1 holds a shared lock.
4 COMMIT - T1 releases the lock on A.
5 - WRITE(A) T2 acquires the exclusive lock on A and writes.
6 COMMIT - T2 releases the lock.

Applications[편집 | 원본 편집]

Primary Site 2PL is used in distributed systems where:

  • Global Consistency: A strict guarantee of serializability is required.
  • Low Update Rates: Environments with fewer updates to data items to minimize contention.
  • Simplified Lock Management: Centralized control is beneficial for simpler coordination.

Comparison with Other 2PL Variants[편집 | 원본 편집]

Feature Primary Site 2PL Centralized 2PL Distributed 2PL
Lock Management Delegated to primary sites for each data item Centralized at a single node Fully distributed across all nodes
Fault Tolerance Affected by primary site failure Single point of failure Higher fault tolerance
Communication Overhead Moderate (lock requests to primary sites) Low (single coordinator) High (peer-to-peer communication)
Scalability High (multiple primary sites) Limited High

See Also[편집 | 원본 편집]