Skip to content

A1-1: Define ConsensusLog interface and in-memory implementation #128

Closed as not planned

Description

@scttfrdmn

Context

ConsensusEngine in internal/distributed/consensus.go stores the Raft log as a bare []*LogEntry slice. This makes it impossible to swap in a persistent backing store without touching the consensus engine directly, which precludes the bbolt WAL planned for v0.13.0.

What to implement

Create internal/distributed/log/interface.go with a ConsensusLog interface:

type ConsensusLog interface {
    Append(entry *LogEntry) error
    Get(index uint64) (*LogEntry, error)
    Slice(lo, hi uint64) ([]*LogEntry, error)
    LastIndex() uint64
    LastTerm() uint64
    TruncateSuffix(fromIndex uint64) error
    TruncatePrefix(upToIndex uint64) error  // needed for log compaction (v0.13.0)
}

Interface doc comment must explicitly note it is designed to accept a bbolt or etcd-raft backing store as a future drop-in.

Create internal/distributed/log/memory.go with MemoryLog implementing the interface (wraps the existing []*LogEntry logic).

Replace the ce.log []*LogEntry field in ConsensusEngine with ce.log ConsensusLog. Inject via NewConsensusEngine, defaulting to log.NewMemoryLog(). Update all index arithmetic (getLastLogIndex, getLastLogTerm, becomeLeader, handleNetworkAppendEntries, sendAppendEntries) to go through interface methods.

Acceptance criteria

  • ConsensusLog interface exists with documented design intent
  • MemoryLog passes table-driven unit tests covering: Append, Get, Slice, TruncateSuffix, TruncatePrefix, LastIndex/LastTerm
  • All existing consensus tests pass with -race: go test -race ./internal/distributed/...
  • No behavior changes — this is a pure refactor

Sequencing

Must land before A1-3 (PersistentState uses the same log package) and A2-1 (FUSE wiring requires stable interfaces).

Activity

  1. added
    type: technical-debt
    priority: critical
    area: distributed
    on Apr 7, 2026
  2. added
    effort: medium
    on Aug 3, 2026
  3. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Closing as not-the-direction, per the decision on #169.

    The evaluation in docs/design/conditional-writes-vs-raft.md recommends per-key S3 conditional writes (CAS) over a replicated log, and that recommendation has been adopted. §1 of the doc is the reason this specific issue goes: there is nothing to replicate. S3 is the sole source of truth, every node reaches it, and no node holds authoritative state that a log would be recovering. A ConsensusLog would order entries that nothing appends — applyLogEntry (consensus.go) is three empty comment arms today, and nothing appends EntryTypeOperation at all.

    What replaces it: per-key compare-and-swap for coordination, gossip for membership. See the four issues opened under §5, in particular the Backend.PutObjectIf work.

    Not closing because the issue is badly specified — it isn't. Closing because the layer it belongs to is not being built.

    Reference: https://github.com/scttfrdmn/objectfs/blob/main/docs/design/conditional-writes-vs-raft.md

  4. added
    resolution: wontfix
    on Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: distributedeffort: mediumpriority: criticalresolution: wontfixtype: technical-debt

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions