WAL files are generated with increasing sequence number in the WAL directory. In order to reconstruct the state of the database, these files are read in the order of sequence number. WAL manager provides the abstraction for reading the WAL files as a single unit. Internally, it opens and reads the files using Reader or Writer abstraction.

Writer provides an abstraction for appending log records to a log file. The medium specific internal details are handled by WriteableFile interface. Similarly, Reader provides an abstraction for sequentially reading log records from the log file. The internal medium specific details are handled by SequentialFile interface.

Log file consists of a sequence of variable length records. Records are grouped by kBlockSize. If a certain record cannot fit into the leftover space, then the leftover space is padded with empty (null) data. The writer writes and the reader reads in chunks of kBlockSize.

The record layout format is as shown below.

Record Format Details

The log file contents are a sequence of 32KB blocks. The only exception is that the tail of the file may contain a partial block.

A record never starts within the last six bytes of a block (since itwon't fit). Any leftover bytes here form the trailer, which must consist entirely of zero bytes and must be skipped by readers.

More types may be added in the future. Some Readers may skip record types they do not understand, others may report that some data was skipped.

The record contains the contents of an entire user record.

FIRST, MIDDLE, LAST are types used for user records that have beensplit into multiple fragments (typically because of block boundaries).FIRST is the type of the first fragment of a user record, is thetype of the last fragment of a user record, and MID is the type of allinterior fragments of a user record.

A will be stored as a FULL record in the first block.

B will be split into three fragments: first fragment occupies the rest of the first block, second fragment occupies the entirety of the second block, and the third fragment occupies a prefix of the third block. This will leave six bytes free in the third block, which will be left empty as the trailer.

will be stored as a FULL record in the fourth block.

Some benefits over the recordio format:

  • Splitting at approximate boundaries (e.g., for mapreduce) is simple: find the next block boundary and skip records until we hit a FULL or record.
  • We do not need extra buffering for large records.

Some downsides compared to recordio format:

  • No packing of tiny records. This could be fixed by adding a new record type, so it is a shortcoming of the current implementation, not necessarily the format.