Chapter 13 “Distributed Systems: Concepts and Design” Coulouris, Dollimore, Kindberg A transaction is a point where there is interaction with the database A transaction is generally atomic The state of the transaction being done is not visible. If it is not done completely, any changes it made will be undone. This is known as rollback It’s common to talk about transactions in banking systems Ex: A transfer between accounts. The money should be transferred as well as withdrawn To make sure both things are done concurrency control is used Concurrency – multiple users want to access the same data at the same time Concurrency control (CC) ensures that correct results for parallel operations are generated CC provides rules, methods, design methodologies and theories to maintain the consistency of components operating simultaneously while interacting with the same object Concurrency control is needed because there are a lot of things that can go wrong Each transaction itself can be okay, but the concurrency generates problems such as: The lost update problem The dirty read problem The incorrect summary problem Figur 13.9 There are many methods for concurrency control The main methods are: Locks Optimistic concurrency control Timestamp ordering Locks are used to order transactions that access the same objects according to the order of arrival of their operations at the objects Mechanism for enforcing limits on access to the object If the access to the object is locked other users have to wait until it’s unlocked Figur 13.15 The use of locks can lead to deadlocks Ex: Two transactions are waiting and each is dependent on the other to release a lock so it can resume Held by Waits for A T U Waits for Figur 13.20 U T B Held by Optimistic concurrency control (OCC) is based on the assumption that two transactions won’t occur at the same time OCC is generally used in environments with low data contention Begin Working phase Validation Update phase phase Begin: Record a timestamp marking the transaction's beginning Working phase: Read and write database values to a copy of the transaction which is not yet bound to the object. Several different transactions of this type may coexist Validate phase: Controls if the transaction conflicts with another transaction on the same object Update phase: Committed: If there is no conflict, make all changes part of the official state of the database Aborted: If there is a conflict, resolve it, typically by aborting the transaction, although other resolution schemes are possible Whenever a transaction starts, it is given a timestamp The timestamp tells in which order that the transactions are supposed to be applied in The transaction with the earliest timestamp is executed first Every object in the database has a read timestamp and a write timestamp Serializability Recoverability Distribution The goal with serializability is that the result of the parallel transactions is the same as if though the transactions were preformed serially Recoverability means that committed transactions do not read data written by aborted transactions Distributed The serializability serializability concept Commitment Ordering allows to effectively achieve global serializability across multiple Database Systems, that may use different concurrency control mechanisms.