The log class diagram is as follows:
Figure 1 log class diagram
> Basiclogrecord
The most basic log read/write class. Provides methods to read a log record. However, these types are limited to reading an int value or a string value in order in the page. The granularity of basiclogrecord operations is the field, that is, the value of the read field in a logrecord. Therefore, in addition to this class object, you need components to understand the type and number of values in a logrecord and manage operations in this class.
The member parameters are page-type PG (where to read data) and INT-type pos (pointers used for data reading ). The initial POS point to the location where the logrecord is stored.
Nextint () and nextstring () return the field value of the logrecord pointed to by the POs pointer.
> Logmgr
The underlying log manager is mainly responsible for writing records to log files. Regardless of the semantic information of the log records, the log records are stored in the file as a mix of integers and strings. The recovery manager of the transaction management module is responsible for the semantic information of logs.
In a log file, the log record is used as an element to maintain a circular linked list. Shows the data structure of the linked list at a coarse granularity:
Figure 2 log record the data structure of the circular linked list
AccordingCode:
Figure 3 key code
Add the first and second records from an empty log file, for example:
Figure 4 Examples of log writing
The preceding figure shows the write records.
> Logiterator
Log iterator provides a mechanism for reading log records in reverse order in log files. It is mainly responsible for reading.
Based on the data structure of the reverse linked list, the log records are read from the log file once. Due to the special data structure, in the process of sequential reading, the log semantics is implemented from the latest time forward.Reverse Order.
The following example shows how records are read.
First look at the code
A. the reset () first called by the constructor ()
B. movenext ()
C. Read the current of the record
Figure 5 key code for log reading
Example of reading records:
Figure 6 Example of log reading
The implementation of the underlying log storage structure is roughly described above. The log semantic information will be included in recovery management and introduced.