liveBook · Manning

Three-way merge

As explained in Data-Oriented Programming: Reduce software complexity

A three-way merge combines changes by comparing two divergent versions with their common predecessor.

When concurrent mutations update shared state, the commit phase must reconcile divergent results. A three-way merge compares the mutation’s starting state, the current state, and its proposed next state. section 5.2

Use the three states to choose the reconciliation path:

  • Previous is the state used for calculation; current is the state at commit time; next is the calculation result. section 5.2
  • If current and previous are identical, fast-forward by returning next. section 5.5
  • Otherwise, calculate changes from previous to current and from previous to next. Disjoint changes can be patched into current; overlapping changes conflict. section 5.5
  • Abort conflicting mutations instead of requiring manual conflict resolution. section 5.2

A mutation commit

SystemConsistency.reconcile(current, previous, next) first checks for a fast-forward, then invokes threeWayMerge when another mutation changed the state. The implementation uses immutable data so identical references can be compared quickly; its shown implementation is safe for a single-threaded event-loop environment, while multi-threaded safety is deferred. section 5.5

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Defines three states, fast-forwarding, diff intersection, patching, and aborting, but defers multi-threaded safety.
Examples
Uses concurrent Git branches, previous/current/next system states, nested hash maps, and SystemConsistency code.
What it assumes
Assumes familiarity with concurrent mutations and Git merges while introducing the three system-state roles from their interaction.
What you can do after
Apply the reconciliation flow and diagnose when concurrent mutations can be fast-forwarded, merged, or aborted.
How it connects
Connects Git merges, optimistic concurrency control, immutable data, diffs, fast-forwarding, and conflict resolution.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.