|
| 1 | +# Ra log compaction |
| 2 | + |
| 3 | +This is a living document capturing current work on log compaction. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | + |
| 8 | +Compaction in Ra is intrinsically linked to the snapshotting |
| 9 | +feature. Standard Raft snapshotting removes all entries in the Ra log |
| 10 | +that precedes the snapshot where the snapshot is a full representation of |
| 11 | +the state machine state. |
| 12 | + |
| 13 | + |
| 14 | +### Ra Server log worker responsibilities |
| 15 | + |
| 16 | +* Write checkpoints and snapshots |
| 17 | +* Perform compaction runs |
| 18 | +* report segments to be deleted back to the ra server (NB: the worker does |
| 19 | +not perform the segment deletion itself, it needs to report changes back to the |
| 20 | +ra server first). The ra server log worker maintains its own list of segments |
| 21 | +to avoid double processing |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +### Compacted segments: naming |
| 26 | + |
| 27 | +Segment files in a Ra log have numeric names incremented as they are written. |
| 28 | +This is essential as the order is required to ensure log integrity. |
| 29 | + |
| 30 | + |
| 31 | +Retain immutability, entries will never be deleted from a segment. |
| 32 | + |
| 33 | +do we need levels? |
| 34 | + |
| 35 | +how about 0000001.segment.1 where each segment has an ordered number of items |
| 36 | +but segments themselves can have non ordered ranges. Newer segments can completely |
| 37 | + |
| 38 | +eg. |
| 39 | + |
| 40 | +``` |
| 41 | +[{0, 5}, {7, 22}] -> compacted to [{0, 5}, {7, 22}, {3, 20}] meaning |
| 42 | +{0, 5} can be deleted. |
| 43 | +
|
| 44 | +
|
| 45 | +```mermaid |
| 46 | +sequenceDiagram |
| 47 | + participant segment-writer |
| 48 | + participant ra-server |
| 49 | + participant ra-server-log |
| 50 | +
|
| 51 | + segment-writer--)ra-server: new segments |
| 52 | + ra-server-)+ra-server-log: new segments |
| 53 | + ra-server-log->>ra-server-log: phase 1 compaction |
| 54 | + ra-server-log-)-ra-server: segment changes (new, to be deleted) |
| 55 | + ra-server-)+ra-server-log: new snapshot |
| 56 | + ra-server-log->>ra-server-log: write snapshot |
| 57 | + ra-server-log->>ra-server-log: phase 1 compaction |
| 58 | + ra-server-log-)-ra-server: snapshot written, segment changes |
| 59 | +``` |
| 60 | + |
0 commit comments