340 likes | 430 Views
Locks with Constrained Sharing. Presentation by Maya Arbel for Seminar in Distributed Algorithms Spring 2013. Model. A database is a collection of objects . Users invokes transactions .
E N D
Locks with Constrained Sharing Presentation by Maya Arbel for Seminar in Distributed Algorithms Spring 2013
Model • A databaseis a collection of objects. • Users invokes transactions. • A transaction is a sequence of read and write operations that are executed atomically on the objects.
Correctness Criteria • Consider a set of transactions T • A historyH over T is the order in which all operations of transactions in T were executed, denoted by . • A serialhistoryis a history such that for every pair of transactions and either all operations executed by precede all operations executed by or vice versa.
Correctness Criteria • Two operations conflictif they both operate on the same object, and one of them is a write. • A history is conflict-preserving serializableif there exists some serial history • over the same set of transactions • if and conflict and then . • The class of all conflict-preserving serializable histories is denoted as CPSR.
Example
Checking For Correctness • We can determine whether a history is serializable by analyzing the serialization graph. • The serialization graph for , denoted • nodes are transactions in • edges if one of s operations precedes and conflicts with one of s operations. • A history is conflict-preserving serializable is acyclic.
Real Time Order and Conflict-Preserving Serializability • CPSR does not preserve real time order of operations.
Locking and Locking Protocols • In the locking approach, each object has associated with it a read and a write lock. • Before a transaction can execute an operation it must acquire a lock of its type. Lock holder Lock requester
Locking Protocol • A protocol is a set of rules on the manner in which locks are acquired. • The goal is to define a protocol such that all histories that are produced by the protocol are conflict-preserving serializable.
Two Phase Locking Protocol (2PL) • Atransaction is not allowed to acquire any locks once it has released a single lock. • Separate the transaction into a locking phase and a release phase.
Correctness of 2PL • Theorem 1: For any history produced by the two phase locking protocol is acyclic. • Proof: Later in the lecture.
Limitations of 2PL • The following history is conflict serializable but do not follow the 2PL protocol. • We would like to find a protocol that captures both the conflict and the order relationship between operations. must release its lock on object before acquiring a lock on object .
Ordered Sharing • Three locking modes: shared, ordered sharedand exclusive. • An ordered shared relationship between and , implies that if two transactions acquire these locks in some order, the operations must be executed in the same order. • Ordered sharing is denoted by .
Ordered Sharing • Assume , a lock is saidto be on holdif it was acquired by a transaction after another transaction had acquired , but before hasreleased the lock on . is on hold …
Ordered Sharing Protocol • An extension of the 2PL protocol i.e., a transaction may not acquire a lock on any object once it has relinquished at least one lock. • Not enough, example (using table ): • Lock Relinquishing Rule: A transaction may not release any locks as long as any of its locks are on hold.
Correctness of Ordered Sharing • Lemma 1: If then there exists an unlock operation such that for all unlock operations . • Proof: ,
Correctness of Ordered Sharing • Lemma 1: If then there exists an unlock operation such that for all unlock operations . • Proof: , is on hold until Lock Relinquishing Rule
Correctness of Ordered Sharing • Lemma 2: If there is a path then there exists an unlock operation such that for all unlock operations • Proof: By induction on n. • The base case follows from Lemma 1. • Assume correctness for
Correctness of Ordered Sharing • Theorem 2: For any history produced by the two phase locking protocol with ordered shared locks is acyclic • Proof: Assume there exists a cycle • Note: This proof also holds for 2PL without ordered shared locks • Contradiction!
Relationship of Lock Tables • Let be a 2PL protocol with ordered sharing using one of the lock tables except . • Let be a 2PL protocol with ordered sharing using a table with at least one more ordered sharing entrance then . • Theorem 3: Every history produced by must also been produced by .
Relationship of Lock Tables • Theorem 3: Every history produced by must also been produced by . • Proof: assume • The ordered sharing acquisition rule: then
Relationship of Lock Tables • Theorem 3: Every history produced by must also been produced by . • Proof: assume • The lock relinquishing rule. then
A Protocol for Conflict Preserving Serializability • Theorem 4: • Proof: • follows immediately from Theorem 2. • : Let be a history such that We will show lock and unlock steps for that follow • As allows locking at any point locks can be obtained immediately preceding the operations in . • The is acyclic thus induces an order on let this order be Order all unlock operations after all operations in according to the order .
Deadlocks • 2PL protocol is not deadlock free • Example: both write to variables . • 2PL with ordered sharing is not deadlock free • Example: both are on hold:
Implementation of Ordered Sharing Protocol • Each object maintains a FIFO queue of transactions. • Acquiring a lock is implemented as a enqueue operation. • The transaction at the top of the queue is the only one that can operate on the object. • A transaction is on hold if it is in an object’s queue but not as the top transaction. • Unlock operation is a dqueue operation and is only permitted if the transaction is not on hold.
Summary • The use of locking protocols to achieve conflict-preservingserializable histories of concurrent programs. • A family of protocols, the most permissive recognizes all conflict-preserving serializable histories.
References • Conflict serializability: • P. A. Bernstein, D. W. Shipman, and W. S. Wong. Formal aspects of serializability in database concurrency control. • C. H. Papadimitriou. The serializabilityof concurrent database updates. • Two phase locking: • K. P. Eswaran, J. N. Gray, R. A. Lorie, and I. L.Traiger. The Notion of Consistency and Predicate Locks in Database System. • Ordered sharing: • D.Agrawaland A.E.Abbadi. Locks with Constrained Sharing.