Transactions and Recovery (lecture 9)
code:
Part 1: Transactions
Transaction - logical unit of work, read and writes, i think its an entire chunk of code that you send off
Recovery - if system failure, allows to gets the transactions back
Logs - record the transactions
/Untitled.png)
Transaction Manager
Does the following:
- Commits
- Rollbacks
- Begin Transaction - starts when you boot up, commit or rollback
A transaction must be (ACID)
- Atomic - all of it is submitted or none of it is
- consistent - takes the database to one state to another
- isolated - not seen by other transactions until it is commited
- durable - survive in a system crash
System model
/Untitled%201.png)
Database buffer = ram = working database
local buffer = cpu area = current operations
database instance - the data stored in the buffer
For best speed the database buffer must:
- Store a queue of transactions in the local buffer, (he mentioned fastest job first)
- Keep data or a part of the database in the local buffer for as long as you can, until it must be changed
Memory or database buffer
- fast
- small
- volatile
- Store things working on
Disk
- slow
- big
- non-volatile
- Store things persistantly
Buffer is flushed when a commit is made
Part 2: Log files
Log file - A way to undo an update, records the old and new values
Stored on Disk
ONLY STORES THE WRITES
Write-ahead Log
Stores the:
- <Transaction, What value is changing, old value, new value>
- ALSO STORES COMMITS, only once everything is on disk
- Logs are stored before the transaction
- Before a commit all Logs must be in stable storeage
Example
/Untitled%202.png)
Part 3: Falure
Local failure - error with a single transaction i.e. deadlock
System failure - something that effects all transactions, local buffer is lost i.e power falure
Media failure - Catastrophic failure, have things stored on different disks i.e. issue with disk
What must be done after a crash
- UNDO - Undo any transactions that were executing
- REDO - Some transactions may have to be redone, that were not uploaded
Undo if not committed yet - since now in disk
Redo if committed but not finished - never left database buffer
Transaction Checkpoint Record
- Stores the log buffers onto the physical log
- Flushing database buffers onto the disk
- Writing a checkpoint record to the log, list all transactions in progress
Example
/Untitled%203.png)
T1 is okay
T2 & T4 - committed but data maybe inconsitant - checkpoint must be made... thus must be redone
T3 & T5 - never finished... thus must be undone