Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transactions and Concurrency Control. Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness.

Similar presentations


Presentation on theme: "Transactions and Concurrency Control. Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness."— Presentation transcript:

1 Transactions and Concurrency Control

2 Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness

3 Operations of the Account Interface Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

4 Operations of the Branch Interface Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

5 Transactions (on Objects) The basic concept: a sequence of client requests performed as an indivisible unit. Properties: Atomicity, Consistency, Isolation, and Durability. Means to maximize concurrency: serializable interleavings

6 A Client’s Bank Transaction Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

7 A Failure Model Writes to permanent storage may fail Processors may crash Messages may be delayed or even lost The faults are assumed to be detectable.

8 Operations in the Coordinator Interface Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

9 Transaction Life Histories Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

10 The Lost Update Problem Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

11 The Inconsistent Retrievals Problem Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

12 Serializable Interleavings Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

13 Serializable Interleavings (cont’d) Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

14 Ensuring Serializability All pairs of conflicting operations of two transactions should be executed in the same order to ensure serializability. (Two operations conflict if their combined effect depends on the order in which they are executed.)

15 Conflict Rules for Read and Write Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

16 A Non-Serializable Interleaving Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

17 Recoverability from Aborts Dirty reads Cascading aborts Premature writes Strict executions of transactions Use of tentative versions

18 A Dirty Read Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

19 Overwriting Uncommitted Values Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

20 Nested Transactions Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

21 Advantages of Nested Transactions Subtransactions at the same level may run concurrently Subtransactions can commit or abort independently

22 Methods of Concurrency Control Locking: locks are used to order transactions according to the order of arrival of their operations at the same data item Optimistic concurrency control: transactions are allowed to proceed until they are ready to commit, whereupon a check is made to see whether they have performed conflicting operations Timestamp ordering: timestamps are used to order transactions according to their starting times

23 Exclusive Locks Exclusive locks are a simple serializing mechanism: Two-phase locking: all locks are acquired in the first phase and released in the second Strict two-phase locking: locks are held until the transaction commits or aborts. Granularity is an important issue.

24 Using Exclusive Locks Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

25 Locking A pair of read operations on the same data item do not conflict. Exclusive locks reduce concurrency more than is necessary. The “many reader/single write” scheme distinguishes two types of lock: read (shared) locks and write locks. Two-phase locking or strict two-phase locking still applies for ensuring serializability.

26 Lock Compatibility Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

27 Lock Management Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

28 A Lock Implementation Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

29 A Lock Implementation (cont’d) Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

30 A Lock Manager Implementation Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

31 Deadlocks The use of locks may lead to deadlock. Deadlock is a state in which each member of a group of transactions is waiting for some other member to release a lock. A wait-for graph can be used to represent the waiting relationships between concurrent transactions at a server.

32 A Deadlock Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

33 A Wait-For Graph Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

34 A Cycle in a Wait-For Graph Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

35 Another Wait-For Graph Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

36 Deadlock Prevention Techniques Lock (in one atomic step) all data items used by a transaction when it starts. Every transaction requests locks on data items in a predefined order. Each lock is given a limited period, after which it becomes vulnerable.

37 Deadlock Detection Deadlocks may be detected by finding cycles in the wait-for graph. Two design issues: * Frequency of checking the existence of a cycle * Choice of transactions to be aborted

38 Resolving a Deadlock Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

39 Increasing Concurrency Two-version locking: allows one transaction to write tentative versions of data items while other transactions read from the committed version of the same data item; read operations wait only if another transaction is currently committing the same data item Hierarchic locks: at each level, the setting of a parent lock has the same effect as setting all the equivalent child locks

40 Lock Compatibility Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

41 A Lock Hierarchy Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

42 Compatibility of Hierarchical Locks Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

43 Drawbacks of Locking Overhead of lock maintenance: some locks may be unnecessary Reduced concurrency due to * deadlock prevention * holding locks until the end of a transaction (to avoid cascade aborts) In some applications, the likelihood of conflict is low.

44 Optimistic Concurrency Control Transactions are allowed to proceed as though there were no possibility of conflict with other transactions until the client issues a CloseTransaction request. When a conflict is detected, some transaction is aborted.

45 Optimistic Concurrency Control (cont’d) Each transaction has three phases: Read phase: use a tentative version for each updated data item Validation phase: checking if there is a conflict Write phase: if validated, all tentative versions are made permanent

46 Naive Read/Write Rules Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

47 Validation Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

48 Validation of Transactions For validation purposes, each transaction is assigned (in an ascending order) a transaction number when it enters the validation phase. A transaction always finishes its read phase after all transactions with lower numbers.

49 Validation of Transactions (cont’d) Validation phases may overlap (but transaction numbers should be assigned sequentially). All write phases are executed sequentially according to their transaction numbers so that there is no need to check write-write conflicts. * Reuse of transaction numbers (as suggested in the book) is not a very good idea.

50 Validation Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

51 Comparing Backward and Forward Validation Backward: abort the transaction being validated Forward: three options: * defer the validation until the conflicting (and active) transactions have finished * abort all the conflicting active transactions and commit the one being validated * abort the transaction being validated

52 Comparing Backward and Forward Validation (cont’d) Backward: must retain the write sets of committed transactions that may conflict with active transactions Forward: must allow for new transactions to start during validation Backward: compare a possibly large read set against old write sets Forward: compare a small write set against the read sets of active transactions

53 Timestamp Ordering Each transaction is assigned a unique timestamp value when it starts. Every operation bears the timestamp of its issuing transaction and is validated when it is carried out. If the operation cannot be validated, then the transaction is aborted immediately.

54 Read/Write Rules Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

55 Writes and Timestamp Ordering Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

56 Write Rules in Timestamp Ordering Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

57 Reads and Timestamp Ordering Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

58 Read Rules in Timestamp Ordering Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

59 Timestamp Ordering Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

60 Relaxing the Write Rule If a write is too late it can be ignored instead of aborting the transaction, because if it had arrived in time its effects would have been overwritten anyway. However, if another transaction has read the data item, the transaction with the late write fails due to the read timestamp on the item.

61 Multiversion Timestamp Ordering The server keeps old committed versions as well as tentative versions in its list of versions of data items. With the list, Read operations that arrive too late need not be rejected. A Read operation of a transaction is directed to the version with the largest write timestamp less than the transaction timestamp.

62 A Late Write Invalidating a Read Source: G. Coulouris et al., Distributed Systems: Concepts and Design, Third Edition.

63 Comparison


Download ppt "Transactions and Concurrency Control. Concurrent Accesses to an Object Multiple threads Atomic operations Thread communication Fairness."

Similar presentations


Ads by Google