2.3 Recovery based on Logging - KeonYeong/LKY GitHub Wiki

Overview :

In order to endure the crash, logging is added and recovery skill is implemented.


Data Structure:

  • Log Structure

    • Log is composed of the features designed in the project pdf file. Specially the length of the records (or images) are fixed rather than variable. Hence the size of the Log is fixed to 296 bytes.
    • Log buffer's Size is 1 Mega bytes. Hence there are 3542 log entries in the buffer maximum.
    • Transaction structure is rather simple. It consists of the transaction number and transaction beginning LSN in order to store the BEGIN LSN of transaction so that makes aborting easier. Also flag telling whethere transaction started or not is included.

update:

  • At first find the record with the given key, and update the new value. Before updating the value logging is always preceded and then the data is changed.

log_update:

  • when appending log, old value of the record and the new value of the records are stored. Moreover LSN, previous LSN, page number and the offset of the record are also appended. This is only for UPDATE case. When BEGIN or COMMIT case, only LSN things are changed.

Transactions:

  • Begin_transaction only turns on the transaction mode, and appends begin log to log buffer.
  • Commit_transaction turns off the transaction mode, and appends commit log to log buffer. After that it flush the log Buffer to the disk so that durability is safe.
  • Abort_transaction also turns off the transaction mode, and appends abort log to log buffer. After then it undo all the action that current transaction made. Finally it also flush the log buffer to disk.

Recovery:

  • Redo Pass redo all the logs in log file and finishes. Logs are fetched onto the log buffer from log file.

  • Undo Pass undo only the uncommitted transactions. When it meets UPDATE log at the beginning of the transaction. It starts undoing every log entries until it meets BEGIN log of that transactions. Logs are also fetched onto the log buffer from log file.

  • When all redo/undo finish, the log buffer is flushed again and page buffer is also flushed so that dirty pages are ensured to exist on disk.


Others:

  • WAL policy is used. when dirty pages are evicted, log buffer is flushed!

  • Log buffer is dynamically allocated using calloc() method, and the curLog variable is used to index the log buffer.


return