도움말닫기
편집할 때 기술적인 문제가 발생했다면 보고해 주세요.
알림 2개닫기

경고: 로그인하지 않았습니다. 편집을 하면 IP 주소가 공개되게 됩니다. 로그인하거나 계정을 생성하면 편집자가 사용자 이름으로 기록되고, 다른 장점도 있습니다.

이 편집기가 공식적으로 지원하지 않는 브라우저를 사용하고 있습니다.

Primary Copy Two-Phase Locking

IT 위키

Primary Copy Two-Phase Locking (2PL) is a concurrency control protocol used in distributed database systems where a primary copy of each data item is designated for lock management. Transactions must obtain locks from the primary copy of the data item to ensure consistency and serializability across the system.

1 Key Concepts[편집 | 원본 편집]

  • Primary Copy: A specific node in the distributed system is designated as the authoritative source for managing locks for a particular data item.
  • Consistency: By managing locks through the primary copy, the system ensures that all transactions follow a serializable schedule.
  • Two-Phase Locking: The protocol adheres to the Two-Phase Locking rules:
    • Growing Phase: Transactions acquire locks but do not release them.
    • Shrinking Phase: Transactions release locks but do not acquire new ones.

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

The Primary Copy 2PL protocol operates as follows:

  1. Each data item is associated with a primary copy stored at a specific node.
  2. Transactions interact with the primary copy to acquire and release locks.
  3. The primary copy follows the standard Two-Phase Locking protocol to manage locks.
  4. Once a lock is granted by the primary copy, the transaction can read or write the data item at any replica site.

3 Advantages[편집 | 원본 편집]

  • Centralized Lock Management per Item: Simplifies lock management by delegating responsibility to the primary copy.
  • Consistency Guarantee: Ensures serializability by centralizing lock decisions at the primary copy.
  • Improved Performance: Reduces lock management overhead compared to fully distributed locking.

4 Limitations[편집 | 원본 편집]

  • Single Point of Failure: If the primary copy node fails, the data item becomes unavailable for transactions.
  • Communication Overhead: Lock requests and updates must be routed through the primary copy, increasing network traffic.
  • Limited Scalability: High contention for locks on frequently accessed data items can lead to bottlenecks.

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

Consider a distributed database where:

  • Node 1 hosts the primary copy of data item A.
  • Node 2 hosts the primary copy of data item B.

5.1 Scenario[편집 | 원본 편집]

Transaction T1 and T2 execute as follows:

Step Transaction T1 Transaction T2 Primary Copy Action
1 BEGIN TRANSACTION BEGIN TRANSACTION Both transactions start.
2 READ(A) - T1 requests a shared lock for A from Node 1 (primary copy 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.

6 Applications[편집 | 원본 편집]

Primary Copy 2PL is used in distributed systems where:

  • Global Consistency: Strict transaction isolation and serializability are required.
  • Read-Heavy Workloads: Reduces contention for locks by allowing transactions to read from replicas while acquiring locks from the primary copy.
  • Simplified Locking: Centralizing lock management for each data item simplifies implementation.

7 Comparison with Primary Site 2PL[편집 | 원본 편집]

Feature Primary Copy 2PL Primary Site 2PL
Lock Management Delegated to primary copy for each data item Centralized for all operations on the primary site
Fault Tolerance Affected by failure of the primary copy Affected by failure of the primary site
Communication Overhead Moderate (per data item) Potentially higher for all transactions
Scalability High (per data item) Moderate (site-wide management)

8 Challenges[편집 | 원본 편집]

Primary Copy 2PL faces the following challenges:

  • Replication Coordination: Ensuring consistency between the primary copy and replicas requires additional communication.
  • Hotspots: Frequently accessed data items can create contention on their primary copy.
  • Recovery Complexity: Managing recovery after a primary copy failure requires synchronization with replicas.

9 See Also[편집 | 원본 편집]

Primary Copy Two-Phase Locking (2PL) is a concurrency control protocol used in distributed database systems where a primary copy of each data item is designated for lock management. Transactions must obtain locks from the primary copy of the data item to ensure consistency and serializability across the system.

Key Concepts

  • Primary Copy: A specific node in the distributed system is designated as the authoritative source for managing locks for a particular data item.

  • Consistency: By managing locks through the primary copy, the system ensures that all transactions follow a serializable schedule.

  • Two-Phase Locking: The protocol adheres to the Two-Phase Locking rules:

    • Growing Phase: Transactions acquire locks but do not release them.

    • Shrinking Phase: Transactions release locks but do not acquire new ones.

How Primary Copy 2PL Works

The Primary Copy 2PL protocol operates as follows:

  1. Each data item is associated with a primary copy stored at a specific node.

  2. Transactions interact with the primary copy to acquire and release locks.

  3. The primary copy follows the standard Two-Phase Locking protocol to manage locks.

  4. Once a lock is granted by the primary copy, the transaction can read or write the data item at any replica site.

Advantages

  • Centralized Lock Management per Item: Simplifies lock management by delegating responsibility to the primary copy.

  • Consistency Guarantee: Ensures serializability by centralizing lock decisions at the primary copy.

  • Improved Performance: Reduces lock management overhead compared to fully distributed locking.

Limitations

  • Single Point of Failure: If the primary copy node fails, the data item becomes unavailable for transactions.

  • Communication Overhead: Lock requests and updates must be routed through the primary copy, increasing network traffic.

  • Limited Scalability: High contention for locks on frequently accessed data items can lead to bottlenecks.

Example of Primary Copy 2PL

Consider a distributed database where:

  • Node 1 hosts the primary copy of data item A.

  • Node 2 hosts the primary copy of data item B.

Scenario

Transaction T1 and T2 execute as follows:

Step

Transaction T1

Transaction T2

Primary Copy Action

1

BEGIN TRANSACTION

BEGIN TRANSACTION

Both transactions start.

2

READ(A)

-

T1 requests a shared lock for A from Node 1 (primary copy 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 Copy 2PL is used in distributed systems where:

  • Global Consistency: Strict transaction isolation and serializability are required.

  • Read-Heavy Workloads: Reduces contention for locks by allowing transactions to read from replicas while acquiring locks from the primary copy.

  • Simplified Locking: Centralizing lock management for each data item simplifies implementation.

Comparison with Primary Site 2PL

Feature

Primary Copy 2PL

Primary Site 2PL

Lock Management

Delegated to primary copy for each data item

Centralized for all operations on the primary site

Fault Tolerance

Affected by failure of the primary copy

Affected by failure of the primary site

Communication Overhead

Moderate (per data item)

Potentially higher for all transactions

Scalability

High (per data item)

Moderate (site-wide management)

Challenges

Primary Copy 2PL faces the following challenges:

  • Replication Coordination: Ensuring consistency between the primary copy and replicas requires additional communication.

  • Hotspots: Frequently accessed data items can create contention on their primary copy.

  • Recovery Complexity: Managing recovery after a primary copy failure requires synchronization with replicas.

See Also