Coordinating Programs Writing One File

Shared file writes need a policy defining who may update the content and how another reader learns that an update is complete.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Trace independent edits
  2. Choose an ownership rule
  3. Trace a read-modify-write race
  4. Test your coordination mechanism under overlap

Trace independent edits

Two report generators can both read an old version and prepare distinct changes. The last whole-file replacement can discard the other change. Atomic visibility alone does not merge updates. See complete file replacement.

Choose an ownership rule

A single writer, a documented lock protocol, or a storage system with version checks can coordinate the updates. Test two overlapping ordinary writes with the expected contract. State transitions identify which edits are allowed.[1]

Trace a read-modify-write race

Two processes read a shared counter file containing five. Each computes six and publishes its own update. Both operations could complete without restoring the missing increment. Coordinating just the final write cannot protect the read phase of this update. See exclusive transition policies in code.

A reads 5, B reads 5
A writes 6, B writes 6
Desired result for two increments: 7
Serialize the full update or use an atomic operation under a supported storage contract

Test your coordination mechanism under overlap

A lock should have a defined scope, owner and release behavior if the process fails. Atomic file replacement alone prevents partial observations but does not by itself combine concurrent edits. Test two writers beginning at the same value.

References

  1. Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau, Operating Systems: Three Easy Pieces ↩