Local history
Territory: Mechanisms
Separate the events at a replica from the history it learns through messages.
No background sheet listed
On this sheet
Continue reading
A delayed message can contain old news
Alice writes a draft trail report and sends a copy to Bob. The message takes time to arrive. Before it reaches Bob, Alice publishes the report.
Bob receives the draft. Bob has no news of the published report. Receiving a message does not mean having the latest information.
Two computers that keep copies of a document can have the same problem. One can change its copy while a message is on the way. The copies can differ even if no message is lost.
Each hiker in this lesson stands for a computer with a copy of the report. We call each computer a replica; Lamport’s paper calls it a process. The lab labels Alice’s replica A and Bob’s replica B. You can see both panels, but neither hiker can read the other’s.
Separate what happened from what is known
A local history is an ordered record of events at one replica. An event is an action there, such as writing a draft or receiving a message.
The lab uses short names for these events:
a1: A writes the draft.a2: A publishes the report.b1: B receives the message.
A records a1 before a2. B records b1, because B received the draft.
B did not write it.
An observation is information that a replica has from its own events or messages it receives.
After delivery, compare B’s two fields:
- Local history lists
b1. This answers “What happened here?” - Observed events lists
a1andb1. This answers “Which events does B know about?”
- Alice (A)
a1: draft, sendm1, thena2: publish- Message m1 from A to B
- Copy made when A sends:
a1 - Bob (B)
- Receive as
b1; observea1, b1
In this lab, a hiker sends a copy of the events they know about. The receiver adds those events to Observed events and records its own receive event.
The lab records the send action without a separate event name.
A’s Local history still lists only a1 after the send. This keeps the
example small. Sending can count as an event in other models.
Hold the message while A changes
Use Guided run and its Next: button for these four steps. Choose Reset lab first if you have used other controls.
- Record the draft at A. A’s local history and observed events both contain
a1. B’s records are still empty. - Send from A to B. Find
m1in Queued messages, where messages wait for delivery. It containsa1. B has not received it. - Record publication at A. A now lists
a1, a2. Inspectm1again: it must still contain onlya1. - Deliver
m1. B recordsb1. Compare Local history and Observed events for each hiker.
Use Next: to get the event names in this example. The separate delivery
button gives the receive event a different name instead of b1.
Before step 4, predict whether B will learn that A published the report. After delivery, check B’s records as well as the queue.
Without JavaScript, the lab shows empty starting records. You can follow the example in the figures above and below without using the controls.
Local history lab
Alice (A)
- Visible value
- No local values
- Local history
- No local events
- Observed events
- No events observed
- Predecessors
- No predecessors
No events observed
Bob (B)
- Visible value
- No local values
- Local history
- No local events
- Observed events
- No events observed
- Predecessors
- No predecessors
No events observed
Each replica starts with an empty local history. No messages have been delivered.
Invariant checks
- Local history is ordered: yes
- Observed events have causal paths: yes
Check what B knows
B learns nothing from m1 until it arrives. When A publishes the report,
A’s record changes. The copy in m1 stays the same.
After delivery, B knows about the draft (a1) and its own receive (b1).
It has no record of A publishing the report (a2).
| Hiker | Local history | Observed events |
|---|---|---|
| Alice (A) | a1, a2 | a1, a2 |
| Bob (B) | b1 | a1, b1 |
An empty queue does not mean both hikers have the same information. You delivered the earlier copy. B sends no reply in this run, so A does not know that B received it.
To tell B about a2, choose Send from A to B after the guided run.
Deliver the new message. B learns that A published the report and records
a new receive event. The first receive event stays in B’s history.
Break it: read the sender at delivery
Suppose the lab read A’s current record when you delivered m1.
B would learn about both the draft and the published report.
That would be wrong: A sent m1 before publishing.
Check m1 at steps 2 and 3. It must still contain only a1 after A changes.
Then check B after step 4. B should have no record of a2.
The delivery worked; the message had no news of that event.
The cost of an explicit history
The lab names events so you can check what each hiker knows. Longer runs need more space for records and larger messages. Real applications do not have to send their full history in each message.
You control when messages arrive. Sending a message does not guarantee that it arrives. A delay is enough to leave B with an old record; the network does not have to fail.
Field notes
Use this short record to check the result:
A records draft a1.
A sends m1 containing a1.
A records publication a2.
B receives m1 as b1 and learns about a1.
B has not learned about a2.A local history records what happened at one replica. Observations also include events learned from messages. B can learn what A sent in a message, but it cannot use that message to learn about A’s later changes.
For further reading, Leslie Lamport’s Time, Clocks, and the Ordering of Events in a Distributed System explains how events and messages set the order of events across computers. You do not need those formal rules for this lesson.
The lab also shows an event comparison. You can leave that aside here. Partial order explains those comparisons in the next lesson.