Logging Flashcards
Logging
Writes down important things that happens during transactions, like states etc.
Logging with system failure
Logging should work even if the system fails, but sometimes logging is not enough.
Therefore we rely on undo logging, redo logging and combinations of both.
Operations for Log Manager
- writing x just writes to the buffer
- output(x) -> copy database item x from buffer to the database itself
- flush_log -> write log entries that are residing in main memory to the log
Undo Logging
Undo logging logs activities with the goal of restoring a previous database state.
Log Records for Undo Loggging
- <START>
</START> - <COMMIT>
</COMMIT> - <ABORT>
</ABORT> - <T, X , v>
<START>
</START>
Transaction t has started.
<COMMIT>
</COMMIT>
Transaction t has committed.
<ABORT>
</ABORT>
Transaction t was aborted.
<T, X, v>
Transaction t has updated value of database item x, with the old value being v.
Rules for Undo Logging
- If transaction t updates item x and old value was v, then T, X, v must be written to the log on disk before x is written to disk.
- If transaction t commits, commit t must be written as soon as all database elements changed by t have been written to disk.
System Failure with no commits
If the system fails and we have not committed (and if there is no abort for the specific transaction, which means it would have already been reverted), we have to undo all changes done, with each v replacing x which was recorded on the logs. If it has committed, then no changes are required.
Recovery Manager
The recovery manager restores the last consistent database state in an error occurs, traversing the undo log backwards.
Once all undone, we write abort t for each uncommitted transaction t that was not previously aborted (when traversing back through the undo log, if we also have an aborted transaction, we do not have to write up that transaction again) and call flush_log.
Redo Logging
Logs activities with the goal of restoring committed transactions.
Log Records for Redo Logging
Only one record has changed:
<T, X , v> -> transaction t has updated value of database item x, with the NEW value being v.
Essentially, we intend to get a value which has been committed, not undoing a value.
Rules for Redo Logging
Rules:
- T first writes all log records for all updates
- T writes commit t to the log on disk
- T writes all committed updates to disk