Structures

Complexity Introductory

TwoPSet

A GSet can record every camera the hikers find, but it cannot remove one. The hikers add a second GSet for permanent removals. Together, those two grow-only sets form a TwoPSet.

An open folio keeps a camera sketch and retirement tag beside a removed camera and its empty, unbuckled strap.

A second page for removals

The hikers make the same move the PN-counter made: when a structure can only grow, they record the undo on a second page. Each page is a GSet. The additions page records every camera name a hiker has received. The removals page records every name a hiker knows is permanently retired. Both pages only grow and merge by union.

This is a TwoPSet, short for two-phase set. A name is visible only when it is on the additions page and not on the removals page. A name can be added, then removed, and never added again.

Before they set out again, Alice's Eagle Creek report has reached all three hikers. Alice, Bob, and Carol each have Eagle Creek on the additions page and an empty removals page, so all three still show the camera on their visible lists.

Alice and Bob write on different pages

Alice finds that the old Eagle Creek camera is gone, so she writes Eagle Creek on her removals page. Bob has not received Alice's record. He finds a replacement with the same name and writes Eagle Creek on his additions page, where the name is already present. Carol makes no change.

That retained removal record is a tombstone. It prevents a delayed or repeated addition record from making the retired camera visible again.

Step Notebook Additions page Removals page Visible list
Before retirement Alice { Eagle Creek } {} Eagle Creek
Bob { Eagle Creek } {} Eagle Creek
Carol { Eagle Creek } {} Eagle Creek
Notes in transit Alice { Eagle Creek } { Eagle Creek } empty
Bob { Eagle Creek } {} Eagle Creek
Carol { Eagle Creek } {} Eagle Creek
After the notes arrive Alice { Eagle Creek } { Eagle Creek } empty
Bob { Eagle Creek } { Eagle Creek } empty
Carol { Eagle Creek } { Eagle Creek } empty
Each hiker computes the visible list from the two pages in that notebook. Bob's replacement does not create a new set member because the same name is already on the additions page.

Whichever note arrives first, each notebook ends with Eagle Creek on both pages, so all three visible lists are empty. A delayed or repeated addition note cannot undo the retained removal.

Three field notebooks

Race retirement against replacement

Alice retires Eagle Creek while Bob reports the same name again. The permanent tombstone must win at all three notebooks.

Merge rule Union additions and removals; removal wins forever.

Alice

Eagle Creek is active

Visible camera list

Eagle Creek

Checkpoint note Removals page: Eagle Creek

Bob

Eagle Creek is active

Visible camera list

Eagle Creek

Checkpoint note Additions page: Eagle Creek

Carol

Eagle Creek is active

Visible camera list

Eagle Creek

Checkpoint note No note in this race

Trail relay No ordering decision 0 notes shared

Mechanism evidence No retirement tombstone yet.

  1. No notes shared yet.

Enable JavaScript to run the demo. The starting state and expected result remain in the lesson.

Eagle Creek is active. Race Alice's retirement against Bob's replacement report.

A removed name can never return

Bob's replacement camera is real, but the hikers can never list it. A TwoPSet cannot tell two installations with the same name apart.

The next lesson, the observed-remove set, gives every addition its own identity, so Alice can remove the old camera while Bob's replacement survives.

Add again after everybody saw the removal

All three hikers know Eagle Creek. Alice removes it; only after that removal reaches everyone does Bob add it again.

TwoPSet permanently retires the name. An observed-remove set permits a fresh addition after removal.

NotebookTwoPSetObserved-remove set
Alice Eagle Creek Eagle Creek
Bob Eagle Creek Eagle Creek
Carol Eagle Creek Eagle Creek

Ready: both paths have the same starting input.

Inspect the decision evidence

TwoPSet

Addition and permanent-removal sets; delivered sequence 6.

Observed-remove set

Bob's new add follows delivery of Alice's removal; delivered sequence 6.

Enable JavaScript to run the comparison. The starting state and expected lesson remain above.

Sources and implementation

Sources: Watershed's TwoPSet kernel stores additions and permanent removals as two grow-only sets. The two-phase set is described in A comprehensive study of Convergent and Commutative Replicated Data Types.

Implementation: The demo calls the Watershed kernel through the site's Gleam toolkit. The trail relay carries notes without ordering them.