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

  1. Inspect the embedded BoltDB error for corruption indicators and restore from a verified snapshot if confirmed.
  2. Stop the agent and take a consistent copy of raft.db; retry inspection on the copy.
  3. If the tail of the log is damaged but an earlier snapshot exists, recover from the snapshot and let the cluster re-replicate.
  4. 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

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


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/f45e2eb11b2a876b. Report an issue: GitHub.