The WAL frame

The WAL frame is essentially a B-tree structured page with a frame header. The frame header contains 6 big-endian 32-bit integers:

Byte offset

Value

Description

0-3

Page number

This is the frame or page number in the WAL file.

4-7

Database Size

This is the size of the database in pages for commit records.

8-11

Salt-1

This is copied from the WAL header at the time of writing the frame.

12-15

Salt-2

This is copied from the WAL header at the time of writing the frame.

16-19

Checksum-1

This is the cumulative checksum including this frame.

20-23

Checksum-2

This is the second part of the checksum.

 

The Salt-1 value is simply the Salt-1 value in the WAL header at the time of creating the frame. We used this value stored in the frame to determine the time of events in the previous example. The page number is an integer starting at zero, where zero is the first frame in the WAL file.

Following the frame header are the contents of a single page in the database, starting with the page header. The page header consists of two 8-bit and three 16-bit big-endian integers:

Byte offset

Value

Description

0

B-Tree flag

This is the type of B-tree node

1-2

Freeblocks

This is the number of freeblocks in the page.

3-4

Cell count

This is the number of cells in the page.

5-6

Cell offset

This is the byte offset to the first cell relative to the start of this header.

7

Fragments

These are the number of fragmented freeblocks in the page.

 

With this information, we now know how many cells we're dealing with and the offset to the first cell. Following this header are N big-endian 16-bit integers specifying the offset for each of the cells. The cell offsets are relative to the start of the page header.