hashicorp/nomad · error
failed to fetch last index: %v
Error message
failed to fetch last index: %v
What it means
raftStateInfoBoltDB calls s.LastIndex() to read the highest persisted Raft log index after FirstIndex succeeds. This error wraps a failure of that read — same family as the FirstIndex failure: the opened store's log data cannot be queried.
Source
Thrown at helper/raftutil/state.go:74
},
MsgpackUseNewTimeFormat: true,
}
s, err := raftboltdb.New(opts)
if err != nil {
if strings.HasSuffix(err.Error(), "timeout") {
return nil, 0, 0, errAlreadyOpen
}
return nil, 0, 0, fmt.Errorf("failed to open raft logs: %v", err)
}
firstIdx, err = s.FirstIndex()
if err != nil {
return nil, 0, 0, fmt.Errorf("failed to fetch first index: %v", err)
}
lastIdx, err = s.LastIndex()
if err != nil {
return nil, 0, 0, fmt.Errorf("failed to fetch last index: %v", err)
}
return s, firstIdx, lastIdx, nil
}
func raftStateInfoWAL(p string) (store RaftStore, firstIdx uint64, lastIdx uint64, err error) {
s, err := raftwal.Open(p)
if err != nil {
return nil, 0, 0, fmt.Errorf("failed to open WAL logs: %v", err)
}
firstIdx, err = s.FirstIndex()
if err != nil {
s.Close()
return nil, 0, 0, fmt.Errorf("failed to fetch first index: %v", err)
}
lastIdx, err = s.LastIndex()View on GitHub (pinned to 482b49bf1a)
Solutions
- Inspect the embedded BoltDB error for corruption indicators and restore from a verified snapshot if confirmed.
- Stop the agent and take a consistent copy of raft.db; retry inspection on the copy.
- If the tail of the log is damaged but an earlier snapshot exists, recover from the snapshot and let the cluster re-replicate.
- Ensure adequate disk space and clean shutdown procedures to avoid further tail corruption.
Defensive patterns
Strategy: try-catch
Try / catch
store, _, last, err := raftutil.RaftStateInfo(raftDB)
if err != nil {
if strings.Contains(err.Error(), "failed to fetch last index") {
log.Printf("log tail unreadable (likely corruption): %v — recover from snapshot", err)
return
}
defer store.Close()
} Prevention
- Ensure clean agent shutdowns; tail corruption usually comes from crashes or disk-full during writes.
- Monitor disk space on the raft volume.
- Validate raft.db integrity on copies before relying on last-index values.
- Always close the returned store (defer Close) only when err == nil.
When it happens
Trigger: s.LastIndex() erroring on an opened raftboltdb store: corrupt logs bucket/pages, Bolt transaction I/O failure, or damaged index entries at the tail of the log.
Common situations: Disk-full event truncated the tail of raft.db, crashed write left BoltDB pages inconsistent, or the file belongs to a different tool's schema so index reads fail.
Related errors
- failed to open raft logs: %v
- failed to fetch first index: %v
- failed to open raft store %v: %v
- failed to read log entry at index %d: %v
- failed to open BoltDB store: %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/f45e2eb11b2a876b.
Report an issue: GitHub.