Repository navigation
Description
Summary
RaftNameService::publish_index treats "this node is not the leader" as success. A non-leader that builds an index therefore pays the full cost of the build, is told the publish succeeded, resolves its waiters with a Completed outcome — and advances no index head anywhere in the cluster.
fluree-db-consensus/src/raft/nameservice.rs:344:
async fn publish_index(&self, ledger_id: &str, index_t: i64, index_id: &ContentId) -> Result<()> {
let cmd = build_advance_index_command(ledger_id, index_t, index_id)?;
match self.raft.client_write(cmd).await {
Ok(resp) => map_advance_index_response(resp.data),
// A stepped-down leader's straggling publish call. The
// new leader will run its own build; nothing for us to
// do except not propagate the error.
Err(RaftError::APIError(ClientWriteError::ForwardToLeader(_))) => Ok(()),
...client_write on a non-leader returns ForwardToLeader — openraft does not auto-forward — so the command is never proposed and never applies.
The swallow is correct for the case its comment describes: a leader that steps down mid-build, where the new leader will build again. It does not hold for a node that was never the leader, which is the common case below.
Why non-leaders build
Index builds are initiated on every node, not just the leader:
build_direct_fluree(fluree-db-server/src/state.rs) spawns a node-scopeBackgroundIndexerWorkeron every raft node wheneverindexing_enabled— the default. It gets theRaftNameServiceas itsIndexingNameService.- Writes are not executed by the leader.
WorkerSupervisor(fluree-db-consensus/src/raft/commit_worker.rs) runs one commit worker per branch "on whichever node the rendezvous-hash owner resolves to", on every node. - That worker finishes with
finalize_local_state→Fluree::finalize_commit→trigger_reindex_if_needed(fluree-db-api/src/tx_builder.rs:1424), which triggers that node's node-scope worker.
So for every branch whose rendezvous-hash owner is not the current leader, indexing is initiated on a follower and discarded. On an N-node cluster that is roughly (N-1)/N of branches.
Separately, the leader-scope worker (fluree-db-server/src/lib.rs, spawned inside leader_tasks) is subscribed to the consensus event bus and triggers on every LedgerCommitPublished emitted by ApplyHead (fluree-db-consensus/src/raft/app.rs:332), ungated by reindex_min_bytes. That worker's publishes do land, which is why indexing under raft works at all. The net effect is that most ledgers are indexed twice — once usefully on the leader, once uselessly on the owning follower.
Impact
Wasted work. The follower runs a complete build: CPU, sort buffers, and index leaves, branches and root written to shared CAS. Nothing references those objects, so they sit as orphans until GC.
No convergence. Because the nameservice index_t never advances, the follower re-reads the same stale record on its next trigger and builds again. Today that is once per qualifying commit. It becomes once per sweep interval, forever, if catch-up sweeps are ever enabled on node-scope workers — see the note on #1662 below.
A false success, which is the part I would rate highest. On the success path (fluree-db-indexer/src/orchestrator.rs, post-build) the worker resolves waiters from the build result, not from a re-read of the nameservice:
let outcome = IndexOutcome::Completed {
index_t: index_result.index_t,
root_id: Some(index_result.root_id.clone()),
fuel: index_result.fuel,
};
state.resolve_waiters_below(index_result.index_t, outcome);
state.last_index_t = index_result.index_t;
state.retry_count = 0;
state.next_retry_at = None;
state.last_error = None;So a caller on that node that awaited indexing is handed Completed naming an index_t and a root_id that no nameservice record points at, and the worker records an advance that did not happen. Reads still resolve through the nameservice record, so this is not data corruption — but "indexing completed at t=N with root R" is not true when it is returned, and nothing distinguishes it from a publish that actually landed. There is no log line and no metric: the one error arm that would have shown it is the arm that returns Ok(()).
Suggested direction
Distinguish the two cases the single ForwardToLeader arm currently conflates:
- Was the leader, stepped down mid-publish — the existing swallow is right, but should log so the discarded build is visible.
- Never the leader — this build should not have been started. Either refuse it early (the node-scope worker knows its own leadership state, or can be told it does not own publishing) or surface the refusal as an error so the waiter sees a failure rather than a fabricated success.
The cheaper half is not initiating the build at all: a node-scope worker under raft has no publish path that lands, so triggering it post-commit is work that can never pay off. admin::reindex / admin::trigger_index on a follower have the same problem and go through publish_index_allow_equal, which — correctly — does not swallow, and returns propose_unresolved instead. That asymmetry is worth reconciling.
Relationship to #1662
Pre-existing and independent; #1662 neither causes nor fixes it. It matters there because #1662 adds start-up and periodic catch-up sweeps to BackgroundIndexerWorker::run, which would have turned this from "once per commit on the owning follower" into "every node, every sweep interval, forever". The fix on fix/indexer-wedged-novelty-recovery gates those sweeps to a single owner per nameservice, so it avoids making this worse — but the underlying swallow, the duplicate builds, and the false Completed outcome all remain exactly as they are on main.
Verification
Read on main at a3b4376. Not reproduced on a live cluster — the reasoning is from the call graph above, so the specific claim worth checking on hardware is that a follower-owned branch's build really does reach publish_index and get ForwardToLeader rather than being refused earlier.
Activity