Replication
UD's replication engine lets each node accept writes and merge updates from other nodes. Nodes with the same updates derive the same directory view, regardless of the order in which those updates arrive.
In version 0.1.0, this protocol runs between nodes in the test harness.
The daemon does not exchange directory updates over GIP. GIP links and the
ud/msgs service are separate from directory replication. The console shows
local replication metadata, but it does not connect daemons into a replicated
domain.
Node identities and update coordinates #
A node has a permanent node ID and an invocation ID identifying one
incarnation of its database. Each update receives a local update sequence
number (USN). The pair (invocationId, usn) identifies that update's
position
in the originating stream.
Changing the invocation ID prevents a recovered database from presenting new updates as positions in an older stream. The local counter continues; the new invocation supplies a distinct coordinate space.
Merging updates #
Replication transfers merge atoms: existence, placement, individual attribute values, and the shred latch. Each ordinary atom carries a stamp, ordered by version, timestamp, then origin. The atom with the greater stamp wins.
An identical value and stamp produce no write. An identical value with a stronger stamp updates the stamp, so later comparisons agree across nodes. Replicated writes bypass local schema validation: a definition needed by an incoming object might arrive later. The derived view handles those incomplete states.
An incoming record with the same GUID but a different class or system flag is rejected. The journal records the mismatch and the sync cursor stops at that record. The engine does not choose between inconsistent identities.
Pulling updates #
A node pulls updates above a partner-specific high watermark, expressed in that partner's USN space. It also sends an up-to-dateness vector recording which coordinates it holds from each originating invocation. The sender uses that vector to omit updates already received through other partners.
Responses arrive in chunks. Even an empty chunk can advance the watermark. Vector coverage advances only when a stream completes; a partial transfer must not claim that missing updates were received.
Initial synchronization starts with a zero watermark and an empty vector. The node discovers the root from incoming records. Incomplete schema components remain quarantined, and objects whose classes have not arrived remain ghosts. Those objects reject local writes until their definitions arrive. A pull between nodes with different root GUIDs is rejected because the nodes belong to different domains.
Deriving a consistent view #
Independently valid writes can conflict after merging. UD resolves these conflicts in the derived view without generating repair writes:
- Colliding sibling names retain the earliest claim; later claims receive a conflict name (CNF).
- Objects with missing parents and objects involved in move cycles appear
under
/LostAndFound. - Incomplete schema definitions remain quarantined.
The same stored atoms produce the same repairs on each node. A repair ceases to apply when an ordinary update removes the conflict.
Replicating deletion #
The deletion lifecycle uses stamped existence transitions for soft deletion and restoration. Shredding additionally sets an irreversible latch, so a concurrent edit or restore cannot recover shredded data through replication.
Restore and purge deadlines derive from timestamps and replicated configuration. A partner whose watermark is older than retained deletion knowledge receives a full-resynchronization requirement. Incremental sync cannot safely omit deletions that have already been purged.
Detecting rollback #
A restored node can retain an old invocation ID while losing some updates from that invocation. A partner's vector or watermark can expose this: it claims coordinates from the restored node's stream beyond the node's own counter. Both pull requests and responses carry evidence used by this check.
On detecting rollback, the engine changes invocation ID, assigns its holdings to the new stream, suspends originating writes, and records an alarm. With persistence, it publishes a salvage snapshot. A completed healing pull clears the suspension.
Detection does not increase claimed coverage of the old invocation. The local counter might already have advanced after restoration, so it cannot prove which old updates remain. The healing pull supplies that evidence.
Zero-record probes check partners before the node applies or originates updates. This preserves the opportunity to detect rollback before new local USNs obscure the difference between the restored counter and partner evidence.
Observing and testing replication #
The console exposes local identity, counters, vectors, and journal entries. The in-process scenario and simulation tests exercise synchronization, partitions, clock skew, power loss, and restored storage. They check convergence using the persistence implementation. These tests do not qualify network replication, which the daemon does not implement.