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

Transaction Manager

Does the following:

A transaction must be (ACID)

  1. Atomic - all of it is submitted or none of it is
  1. consistent - takes the database to one state to another
  1. isolated - not seen by other transactions until it is commited
  1. durable - survive in a system crash

System model

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:

  1. Store a queue of transactions in the local buffer, (he mentioned fastest job first)
  1. 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

Disk

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:

Example

Left is an example of the log

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

  1. UNDO - Undo any transactions that were executing
  1. 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

Example

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