Transactions Flashcards
What are transactions
These are used for controlling operations on persistent shared information.
Transaction properties and definitions
Atomicity
Consistency
Independence
Durability
Atomicity
All or nothing. This state ensures automatic recovery of a system to its prior state in the event of failure
Consistency
Serialisability. This ensures transactions are scheduled to run without interference
Independence
Containment. This ensures all updates done by a transaction are visible to all to other transactions before it terminates
Durability
Persistence. All results produced by a successfully completed terminated transactions are not affected by subsequent failures
Transaction primatives
Begin transaction
End transaction
Abort
Begin transaction
Command indicating the start of a transaction
End transaction
This can have 2 outcomes
Normal termination: Normal ending where all changes made are saved and stored to disk
Abnormal termination: No results produced from transaction termination. This means failures occurred
Abort
Explicitly aborting transaction under control of program
Read lock
reading can be shared. A read lock is permitted provided object is not write locked
Write lock
Writing is exclusive so a write lock is permitted if there is no read or write lock on the object
Deadlocks
If a transactions response to a conflict is to wait for the lock, then there is a danger for deadlocking as it can lead to wait for cycles
2 Phase locking rules
(i) A transaction must obtain a lock on an object before using it;
(ii) growing phase: locks are acquired and acquired locks are not released;
(iii) shrinking phase: acquired locks are released and no new locks are acquired.
Lock point
A transaction at some point in time must hold all the locks on objects
it is using in its computation. This point is called the lock point
Dirty read and cascade abort
(i) Transaction T1 updates object O1 and then releases its write lock, later T1 is aborted, and in the mean time, a transaction T2 puts a read lock on O1
(ii) T2 is reading dirty data as modifications of O1 made by T1 are cancelled when T1 aborts
(iii) This means T2 will have to abort, leading to cascade aborts.
Strict 2 phase locking
The shrinking phase is made logically instantaneous as all locks are released together. This ensures independence property as a transaction can abort without causing cascade aborts.
Simple deadlock prevention
Transaction never waits. If the transaction requesting a lock cannot obtain the lock (due to conflict), then the requesting transaction aborts
Careful deadlock prevention
To permit waiting only if there is no danger of a deadlock. Transactions are assigned numbers (timestamps) using logical or physical clocks, such that transactions numbers are totally ordered
Wait Die scheme
This is where an older transaction waits for a lock held by the younger one, and a younger transaction aborts if it wants a lock currently held by an older transaction.
Let Tr denote the transaction requesting a lock and Th denote the holder of the
lock, with whom the conflict occurs
if timestamp of Tr< timestamp of Th then Tr is old and waits else Tr is young and aborts
Wound wait scheme
This is where only young waits for old, if an old transaction succeeds forcing its way to completion
Let Tr denote the transaction requesting a lock and Th denote the holder of the
lock, with whom the conflict occurs
if timestamp of Tr< timestamp of Th then Tr is old and waits else Tr is young and aborts
2 Phase commit requirements
- The termination of the transaction is carried out under the control
of the client . The first phase is used by the coordinator to determine the outcome for the transaction, the second phase is used to enforce the decision taken by the coordinator
-Every node maintains a file called the ‘transaction log’ or ‘intentions list’ on stable store. The log maintains information about the transactions that node is taking part.
- Every node has a recovery manager process that is executed during crash recovery of the node. The recovery manager scans the transaction log and tries to terminate the transactions that were interrupted by the crash.
2PC algorithm
Client:
Phase1
send ‘get ready’ to all servers;
wait on timeout;
IF all reply ‘yes’ THEN {verdict := commit;
write verdict, transaction identifier, server
node addresses on the transaction log}
ELSE verdict := abort
Phase 2
Send verdict to all servers
Server
Phase 1
Wait on timeout for ‘get ready’ command;
IF none coming THEN abort;
IF command received and server wants to commit
THEN {copy new version of objects on the stable
store; write transaction identifier, coordinator
node address on the transaction log; send ‘yes’
to the coordinator} ELSE {send ‘no’; abort}
Phase 2
wait for the ‘verdict’; carry out the command;
IF no verdict coming THEN keep on checking
with the recovery manager of the coordinator
for the decision.