{"record":{"id":"f45e2eb11b2a876b","repo":"hashicorp/nomad","slug":"failed-to-fetch-last-index-v","errorCode":null,"errorMessage":"failed to fetch last index: %v","messagePattern":"failed to fetch last index: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/raftutil/state.go","lineNumber":74,"sourceCode":"\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 {\n\t\ts.Close()\n\t\treturn nil, 0, 0, fmt.Errorf(\"failed to fetch first index: %v\", err)\n\t}\n\n\tlastIdx, err = s.LastIndex()","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/raftutil/state.go#L56-L92","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"store, _, last, err := raftutil.RaftStateInfo(raftDB)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to fetch last index\") {\n        log.Printf(\"log tail unreadable (likely corruption): %v — recover from snapshot\", err)\n        return\n    }\n    defer store.Close()\n}","preventionTips":["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."],"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"}