4.1 Log Sequence Numbers



next up previous
Next: 4.2 Log records Up: 4 Log Manager Interface Previous: 4 Log Manager Interface

4.1 Log Sequence Numbers

 

Every log record is assigned a unique Log Sequence Number (LSN). There must be a way to create unique LSNs. Also, the recovery subsystem will supply an LSN and expect the log manager to read the corresponding log record. Thus, LSNs must encode some notion of position within the log.

The functionality for creating and using LSNs is provided by class lsn_t (header file: lsn.h). The default constructor of this class initializes the LSN to an invalid LSN. An invalid LSN is one that can be uniquely detected and does not denote any valid position in the log. It is very useful for error returns. For ease of use, lsn.h declares a constant LSN called invalid_lsn that can be used wherever an invalid LSN is required.

Class lsn_t provides methods for setting and retrieving the individual parts of an LSN. The methods for setting the LSN are private so that unintentional modification of the LSN by external code is prevented. Operator << has been overloaded to recognize LSNs and output them in a human-readable form.

The recovery subsystem needs a way to compare LSNs for equality. It also needs to be able to decide whether the page LSN field of a page is less than the log record's LSN to determine whether to redo an update. Class lsn_t overloads the operators ==, !=, <, >, <=, and >= to handle this. While invalid LSNs can be compared against other LSNs for equality and inequality, they cannot be meaningfully compared using any of the other comparison operators.

Class log is a friend of class lsn_t so that it can manipulate LSNs in anyway it wants. The log manager sets the LSN for every log record written and hence, needs to be able to access the methods that set the various parts of an LSN.



next up previous
Next: 4.2 Log records Up: 4 Log Manager Interface Previous: 4 Log Manager Interface



ajitk@cs.wisc.edu, cjin@cs.wisc.edu