Avoiding In Place Writes
A traditional B tree edits pages in place, which risks a half written page after a crash. A copy on write B tree, also called a shadow paging tree, never modifies an existing page. Instead it writes a fresh copy of any page it changes.
How an Update Works
To change a leaf, the engine copies that leaf to a new location with the change applied. Its parent must now point to the new leaf, so the parent is copied too, and so on up to the root.
- Every modified page is written to free space.
- The chain of copies reaches the root.
- The new root pointer is written last, which atomically publishes the whole change.
Benefits
- A crash before the root swap leaves the old tree fully intact, so recovery is simple.
- Old versions remain readable, giving cheap snapshots and consistent reads without blocking writers.
Costs
- Writing a path of copies per update raises write amplification.
- Reclaiming superseded pages requires tracking which old versions are still needed.
Key idea
A copy on write B tree writes new page copies up to a fresh root and swaps one pointer to commit, giving crash safety and snapshots at the cost of higher write amplification.