|
Zero
0.1.0
|
How Log Sequence Numbers are Used. More...
Classes | |
| class | lsn_t |
| Log Sequence Number. See Log Sequence Numbers (LSN). More... | |
How Log Sequence Numbers are Used.
A log sequence number generally points to a record in the log. It consists of two parts:
A savepoint (sm_save_point_t) is an lsn_t. It tells how far back a transaction should undo its actions when ss_m::rollback_work is called.
Each page has an lsn_t that acts as a timestamp; it is the lsn of the last log record that describes an update to the page.
In recovery, when a page is read in, all log records with sequence numbers less than the page lsn have been applied, and redo of these log records is not necessary.
The storage manager has other special cases: lsn_t(0,1) – this is in page.cpp, fixable_page_h::_format(), and indicates a freshly formatted page <<<>>> with no further updates.
Pages have two copies of their page lsn; one at the head and one at the end of the page. Presumably if the two match, the page is uncorrupted, though that is no guarantee. Certainly if they do not match, something is wrong.
The buffer pool's control blocks (bfcb_t) contain an lsn_t, the "recovery lsn" or rec_lsn. This is a timestamp that can be compared with the page lsns to determine if the copy in the buffer pool is up-to-date or not.
A recovery lsn is a lower bound on the lsn of a log record that updated the page in the frame. A clean page in the buffer pool has a rec_lsn of lsn_t::null. Each time a page is fixed in EX mode, the buffer control block ensures that the rec_lsn is not lsn_t::null, thereby indicating that this page is probably dirty and needs flushing or, possibly, is being flushed. The rec_lsn is set to the tail of the log at the time the fix is done; this ensures that any log record written for an update to the page has at least the rec_lsn sequence number. There might be several updates to the page before the page is cleaned, so the rec_lsn is indeed a lower bound, and that's all we can know about it.
Special cases of log sequence numbers:
1.8.12