Read the underlying implementation of simpledb logs

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.