REPOSITORY CODING · MEDIUM
Truncate conflicting uncommitted suffixes
AppendEntries replacing the second log entry must remove that conflicting entry and every later uncommitted entry before appending the new suffix. Matching prefixes must retain unrelated existing tails.
Consensus log transitionsReplicated log protocol workbench
Work through a real codebase.
Choose an environment, investigate the existing implementation and use the tests to check your change. Sign in to open a workspace; execution and Ono usage follow your plan’s allowances.
Task requirements and environments
Go · 55 minute session
- This offline replicated-log protocol workbench models RequestVote, AppendEntries, leader acknowledgement and local append transitions, not timers, transport or a full consensus cluster. Initialize 3..5 uniquely identified nodes, each with a nonnegative term, follower/leader role, optional votedFor, monotonic-term log and commit prefix. Logs have at most 40 entries and events at most 60.
- Observe a strictly higher RPC term before consistency checks: step down, clear votedFor and discard leader acknowledgement state. Vote at most once per term except repeated requests by the same candidate. Compare candidate logs by last term first and last index second.
- AppendEntries requires a matching previous index/term. Preserve an existing suffix when all received entries match; truncate only at the first conflicting uncommitted entry, then append incoming entries. Never overwrite committed entries. A successful append sets follower commit to max(oldCommit,min(leaderCommit,lastNewIndex)), where an empty append lastNewIndex is prevIndex.
- Leader acknowledgements are monotonic per peer and ignored when stale or no longer leader. Advance leader commit only for an entry in the current term replicated on a strict majority, thereby committing its earlier prefix. Apply each committed value once in log order. Explicitly seeded leader roles are rehearsal inputs, not an election certificate.
- Return sorted immutable node snapshots and event results. Malformed events return stable event-indexed errors. Requests are independent, snapshots include term, role, vote, log, matches, commit and applied values, and no operating-system/network state is changed.