Skip to content

A3-1: Implement BboltPersistentState and BboltConsensusLog #150

Closed as not planned

Description

@scttfrdmn

Summary

Add go.etcd.io/bbolt to go.mod and implement persistent Raft storage (BboltConsensusLog, BboltPersistentState) in internal/distributed/log/bbolt.go. This is the production Raft safety upgrade: node restarts no longer violate Raft's durability guarantees.

Background

The ConsensusLog and PersistentState interfaces were defined in A1-1 and A1-3 with in-memory defaults. This issue swaps in durable bbolt-backed implementations. The interface is already in place — no other packages change.

Implementation

New file: internal/distributed/log/bbolt.go

// BboltConsensusLog implements ConsensusLog backed by bbolt.
// Log entries are keyed by big-endian uint64 index for ordered iteration.
type BboltConsensusLog struct {
    db     *bbolt.DB
    bucket []byte
    mu     sync.RWMutex
}

// BboltPersistentState implements PersistentState backed by bbolt.
// SaveTerm writes term+votedFor atomically in a single transaction.
type BboltPersistentState struct {
    db     *bbolt.DB
    bucket []byte
}

Default data path:

${OBJECTFS_DATA_DIR:-/var/lib/objectfs}/<node-id>/raft.db

Enabled by config:

cluster:
  persistent_log: true  # default: false
  data_dir: /var/lib/objectfs

When persistent_log = false (default), MemoryLog and MemoryPersistentState are used — existing behavior unchanged.

Key implementation details:

  • Log entries keyed as 8-byte big-endian uint64 (ensures lexicographic = numeric order in bbolt)
  • SaveTerm writes term + votedFor in a single transaction (atomicity requirement)
  • TruncateSuffix(index) deletes all keys > index in one transaction
  • Slice(lo, hi) uses a cursor for efficient range reads

New dependency

go get go.etcd.io/bbolt

Acceptance Criteria

  • TestBboltRoundTrip: open DB, append 100 entries, close, reopen, verify all 100 present with correct index/term/data
  • TestPersistentStateSurvivesRestart: write term+votedFor, construct new BboltPersistentState on same DB, verify LoadTerm returns same values
  • TestBboltTruncateSuffix: append 50 entries, truncate at 25, verify only 25 remain
  • go test -race ./internal/distributed/log/... passes
  • When persistent_log = false, only in-memory impls are instantiated (no bbolt dep loaded)

Dependencies

  • Requires A1-1 (ConsensusLog interface in internal/distributed/log/interface.go)
  • Requires A1-3 (PersistentState interface; injection into ConsensusEngine)

Activity

  1. added
    type: enhancement
    priority: high
    area: distributed
    on Apr 7, 2026
  2. added
    effort: large
    on Aug 3, 2026
  3. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    This issue's dependencies were closed on 2026-08-03 and it is now unimplementable as written. Flagging rather than closing, because it was not in the approved closure set — see below.

    The CAS recommendation in #169 / docs/design/conditional-writes-vs-raft.md was adopted. The Raft build-out is closed: #128 (ConsensusLog), #130 (PersistentState), #133 (proposal broadcast), #151 (log compaction).

    This issue's own Background names its dependency exactly:

    The ConsensusLog and PersistentState interfaces were defined in A1-1 and A1-3 with in-memory defaults. This issue swaps in durable bbolt-backed implementations. The interface is already in place — no other packages change.

    A1-1 is #128 and A1-3 is #130. Neither interface is going to exist, so there is nothing here to back with bbolt. Two further reasons it does not survive in reduced form:

    • It would add go.etcd.io/bbolt to go.mod and a ${OBJECTFS_DATA_DIR:-/var/lib/objectfs}/<node-id>/raft.db data path. CAS needs neither: coordination state is an object in the bucket guarded by If-Match / If-None-Match, so there is no local durability requirement and no new dependency.
    • Its stated purpose — "node restarts no longer violate Raft's durability guarantees" — is the obligation §1 of the doc shows does not arise here. A node that restarts has nothing to remember because it never held authoritative state.

    Why still open: the direction decision authorized closing four specific issues (#128, #130, #133, #151). §5 of the design doc omitted #150 from its closure list — an omission in the doc, which I have corrected in the doc itself and noted on #169 — so closing it would be extending the approved scope on my own inference. It needs an explicit call. My recommendation is to close it as resolution: wontfix alongside the other four.

    It is also still on the v0.13.0 milestone, whose title I have changed from "Cache Warming, Raft Persistence & Operational Excellence" to "Cache Warming & Operational Excellence" — this issue and #151 were the "Raft Persistence" part.

  4. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Closing as not-the-direction, per the CAS decision on #169 — confirmed explicitly, since this issue was outside the originally approved closure set.

    The reasoning is in the comment above: this issue's own Background states "The ConsensusLog and PersistentState interfaces were defined in A1-1 and A1-3 with in-memory defaults. This issue swaps in durable bbolt-backed implementations." A1-1 is #128 and A1-3 is #130, both closed as not-the-direction, so there is nothing left to back with bbolt. It would also have added go.etcd.io/bbolt and a /var/lib/objectfs data path that the CAS direction does not need — coordination state is an object in the bucket guarded by If-Match/If-None-Match, so there is no local durability requirement.

    Closed alongside #128, #130, #133 and #151. The v0.13.0 milestone has been retitled from "Cache Warming, Raft Persistence & Operational Excellence" — this issue and #151 were the Raft Persistence.

  5. 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: largepriority: highresolution: wontfixtype: enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions