mirror of https://github.com/prometheus/prometheus
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
6.0 KiB
89 lines
6.0 KiB
7 years ago
|
# WAL Disk Format
|
||
|
|
||
6 years ago
|
The write ahead log operates in segments that are numbered and sequential,
|
||
7 years ago
|
e.g. `000000`, `000001`, `000002`, etc., and are limited to 128MB by default.
|
||
|
A segment is written to in pages of 32KB. Only the last page of the most recent segment
|
||
|
may be partial. A WAL record is an opaque byte slice that gets split up into sub-records
|
||
|
should it exceed the remaining space of the current page. Records are never split across
|
||
7 years ago
|
segment boundaries. If a single record exceeds the default segment size, a segment with
|
||
|
a larger size will be created.
|
||
6 years ago
|
The encoding of pages is largely borrowed from [LevelDB's/RocksDB's write ahead log.](https://github.com/facebook/rocksdb/wiki/Write-Ahead-Log-File-Format)
|
||
7 years ago
|
|
||
|
Notable deviations are that the record fragment is encoded as:
|
||
|
|
||
7 years ago
|
```
|
||
7 years ago
|
┌───────────┬──────────┬────────────┬──────────────┐
|
||
|
│ type <1b> │ len <2b> │ CRC32 <4b> │ data <bytes> │
|
||
|
└───────────┴──────────┴────────────┴──────────────┘
|
||
7 years ago
|
```
|
||
7 years ago
|
|
||
6 years ago
|
The type flag has the following states:
|
||
|
|
||
|
* `0`: rest of page will be empty
|
||
|
* `1`: a full record encoded in a single fragment
|
||
|
* `2`: first fragment of a record
|
||
|
* `3`: middle fragment of a record
|
||
|
* `4`: final fragment of a record
|
||
|
|
||
7 years ago
|
## Record encoding
|
||
|
|
||
|
The records written to the write ahead log are encoded as follows:
|
||
|
|
||
|
### Series records
|
||
|
|
||
6 years ago
|
Series records encode the labels that identifies a series and its unique ID.
|
||
7 years ago
|
|
||
7 years ago
|
```
|
||
7 years ago
|
┌────────────────────────────────────────────┐
|
||
|
│ type = 1 <1b> │
|
||
|
├────────────────────────────────────────────┤
|
||
|
│ ┌─────────┬──────────────────────────────┐ │
|
||
|
│ │ id <8b> │ n = len(labels) <uvarint> │ │
|
||
|
│ ├─────────┴────────────┬─────────────────┤ │
|
||
|
│ │ len(str_1) <uvarint> │ str_1 <bytes> │ │
|
||
|
│ ├──────────────────────┴─────────────────┤ │
|
||
|
│ │ ... │ │
|
||
|
│ ├───────────────────────┬────────────────┤ │
|
||
|
│ │ len(str_2n) <uvarint> │ str_2n <bytes> │ │
|
||
|
│ └───────────────────────┴────────────────┘ │
|
||
|
│ . . . │
|
||
|
└────────────────────────────────────────────┘
|
||
7 years ago
|
```
|
||
7 years ago
|
|
||
|
### Sample records
|
||
|
|
||
|
Sample records encode samples as a list of triples `(series_id, timestamp, value)`.
|
||
|
Series reference and timestamp are encoded as deltas w.r.t the first sample.
|
||
6 years ago
|
The first row stores the starting id and the starting timestamp.
|
||
|
The first sample record begins at the second row.
|
||
7 years ago
|
|
||
7 years ago
|
```
|
||
7 years ago
|
┌──────────────────────────────────────────────────────────────────┐
|
||
|
│ type = 2 <1b> │
|
||
|
├──────────────────────────────────────────────────────────────────┤
|
||
6 years ago
|
│ ┌────────────────────┬───────────────────────────┐ │
|
||
|
│ │ id <8b> │ timestamp <8b> │ │
|
||
|
│ └────────────────────┴───────────────────────────┘ │
|
||
7 years ago
|
│ ┌────────────────────┬───────────────────────────┬─────────────┐ │
|
||
|
│ │ id_delta <uvarint> │ timestamp_delta <uvarint> │ value <8b> │ │
|
||
|
│ └────────────────────┴───────────────────────────┴─────────────┘ │
|
||
|
│ . . . │
|
||
|
└──────────────────────────────────────────────────────────────────┘
|
||
7 years ago
|
```
|
||
7 years ago
|
|
||
|
### Tombstone records
|
||
|
|
||
|
Tombstone records encode tombstones as a list of triples `(series_id, min_time, max_time)`
|
||
|
and specify an interval for which samples of a series got deleted.
|
||
|
|
||
7 years ago
|
```
|
||
7 years ago
|
┌─────────────────────────────────────────────────────┐
|
||
|
│ type = 3 <1b> │
|
||
|
├─────────────────────────────────────────────────────┤
|
||
|
│ ┌─────────┬───────────────────┬───────────────────┐ │
|
||
|
│ │ id <8b> │ min_time <varint> │ max_time <varint> │ │
|
||
|
│ └─────────┴───────────────────┴───────────────────┘ │
|
||
|
│ . . . │
|
||
|
└─────────────────────────────────────────────────────┘
|
||
7 years ago
|
```
|