{"record":{"id":"98fe791fc00e2beb","repo":"hashicorp/nomad","slug":"failed-to-fetch-first-index-v","errorCode":null,"errorMessage":"failed to fetch first index: %v","messagePattern":"failed to fetch first index: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/raftutil/state.go","lineNumber":69,"sourceCode":"\topts := raftboltdb.Options{\n\t\tPath: p,\n\t\tBoltOptions: &bbolt.Options{\n\t\t\tReadOnly: true,\n\t\t\tTimeout:  1 * time.Second,\n\t\t},\n\t\tMsgpackUseNewTimeFormat: true,\n\t}\n\ts, err := raftboltdb.New(opts)\n\tif err != nil {\n\t\tif strings.HasSuffix(err.Error(), \"timeout\") {\n\t\t\treturn nil, 0, 0, errAlreadyOpen\n\t\t}\n\t\treturn nil, 0, 0, fmt.Errorf(\"failed to open raft logs: %v\", err)\n\t}\n\n\tfirstIdx, err = s.FirstIndex()\n\tif err != nil {\n\t\treturn nil, 0, 0, fmt.Errorf(\"failed to fetch first index: %v\", err)\n\t}\n\n\tlastIdx, err = s.LastIndex()\n\tif err != nil {\n\t\treturn nil, 0, 0, fmt.Errorf(\"failed to fetch last index: %v\", err)\n\t}\n\n\treturn s, firstIdx, lastIdx, nil\n}\n\nfunc raftStateInfoWAL(p string) (store RaftStore, firstIdx uint64, lastIdx uint64, err error) {\n\ts, err := raftwal.Open(p)\n\tif err != nil {\n\t\treturn nil, 0, 0, fmt.Errorf(\"failed to open WAL logs: %v\", err)\n\t}\n\n\tfirstIdx, err = s.FirstIndex()\n\tif err != nil {","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/raftutil/state.go#L51-L87","documentation":"After successfully opening the BoltDB store, raftStateInfoBoltDB calls s.FirstIndex() to read the lowest persisted Raft log index. This error wraps a failure of that read — the store opened but its log index data is unreadable or the underlying Bolt transaction failed.","triggerScenarios":"s.FirstIndex() erroring on an opened raftboltdb store: BoltDB bucket ('logs') missing or corrupt, I/O error reading the meta/index pages, or database pages damaged such that index queries fail.","commonSituations":"raft.db from a crashed node with damaged meta/logs buckets, a raft.db truncated by disk-full conditions, or a file that opens as BoltDB but is not a Consul Raft store (different schema).","solutions":["Check the embedded error: BoltDB 'invalid database' or bucket errors mean corruption — restore from a verified snapshot.","Run against a consistent copy of raft.db taken while the agent was stopped.","Try consul's built-in recovery/verify tooling on the raft.db before manual inspection.","If only the logs bucket is damaged but a snapshot exists, rebuild state from the snapshot instead."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"store, first, _, err := raftutil.RaftStateInfo(raftDB)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to fetch first index\") {\n        log.Printf(\"log index unreadable (likely corruption): %v — restore from snapshot\", err)\n        return\n    }\n    defer store.Close()\n}","preventionTips":["Take clean copies of raft.db with the agent stopped.","Keep ample disk headroom to avoid truncation from ENOSPC.","Validate the DB with BoltDB integrity checks before index queries.","Maintain verified snapshots as the recovery path."],"tags":["raft","boltdb","corruption","go"],"backgroundTag":"bolt-db-open-failed","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}