{"record":{"id":"a9bd69a39e131acd","repo":"thanos-io/thanos","slug":"chunk-read","errorCode":null,"errorMessage":"chunk read","messagePattern":"chunk read","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/index.go","lineNumber":624,"sourceCode":"\t\tseries   = []seriesRepair{}\n\t)\n\n\tvar builder labels.ScratchBuilder\n\tvar chks []chunks.Meta\n\tfor all.Next() {\n\t\tid := all.At()\n\n\t\tif err := indexr.Series(id, &builder, &chks); err != nil {\n\t\t\treturn errors.Wrap(err, \"series\")\n\t\t}\n\t\t// Make sure labels are in sorted order.\n\t\tbuilder.Sort()\n\n\t\tfor i, c := range chks {\n\t\t\t// Ignore iterable as it should be nil.\n\t\t\tchks[i].Chunk, _, err = chunkr.ChunkOrIterable(c)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrap(err, \"chunk read\")\n\t\t\t}\n\t\t}\n\n\t\tchks, err := sanitizeChunkSequence(chks, meta.MinTime, meta.MaxTime, ignoreChkFns)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif len(chks) == 0 {\n\t\t\tcontinue\n\t\t}\n\n\t\tseries = append(series, seriesRepair{\n\t\t\tlset: builder.Labels(),\n\t\t\tchks: chks,\n\t\t})\n\t}\n","sourceCodeStart":606,"sourceCodeEnd":642,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/index.go#L606-L642","documentation":"This error wraps a failure from ChunkReader.ChunkOrIterable(c) in block.Rewrite (pkg/block/index.go:624) while loading each chunk referenced by a series. It means a chunk referenced from the index cannot be read from the chunk segment files — the chunk reference is invalid, the segment file is missing/truncated, or chunk data fails integrity checks. This is the most common corruption symptom because chunk data lives in separate segments/ files.","triggerScenarios":"chunkr.ChunkOrIterable(c) returning an error when the chunk ref (segment index + offset) points outside an existing segment, the segments/ file is truncated, or the chunk fails XOR chunk decoding/integrity validation.","commonSituations":"Missing or truncated segments/NNN files after interrupted copy or disk full during head compaction; blocks moved between nodes without all segment files; storage-level corruption (bad sectors); repairing blocks where ignoreChkFns should have been supplied to drop known-bad chunks.","solutions":["Restore the affected block's segments/ files from backup or another replica; the index may be fine while chunk data is missing.","Run the repair with ignoreChkFns that filter the unreadable chunk series so sanitizeChunkSequence drops them instead of failing the rewrite.","Verify all segments/ files are present and complete (sizes match, no partial transfers) after any block copy; re-copy if truncated.","Check dmesg/storage health for disk errors; move TSDB data to healthy storage and re-sync the block.","As last resort, quarantine the block and re-ingest or backfill the affected time range from remote storage."],"exampleFix":"// before: rewrite aborts on any unreadable chunk\nchks[i].Chunk, _, err = chunkr.ChunkOrIterable(c)\nif err != nil { return errors.Wrap(err, \"chunk read\") }\n// after: repair path ignores known-bad chunk ranges via ignoreChkFns\nignore := func(m chunks.Meta, _ int64, _ int64) bool {\n    return m.MinTime >= badRangeStart && m.MaxTime <= badRangeEnd\n}\nerr := block.Rewrite(ctx, meta, src, dst, indexr, chunkr, []block.IgnoreChunkFunc{ignore})","handlingStrategy":"fallback","validationCode":"entries, err := os.ReadDir(filepath.Join(blockDir, \"chunks\"))\nif err != nil || len(entries) == 0 { return fmt.Errorf(\"chunk segments missing for block %s\", blockDir) }","typeGuard":"func isChunkReadError(err error) bool { return err != nil && strings.Contains(err.Error(), \"chunk read\") }","tryCatchPattern":"if err := block.Rewrite(ctx, meta, src, dst, indexr, chunkr, nil); err != nil {\n    if strings.Contains(err.Error(), \"chunk read\") {\n        // fall back to rewrite with ignoreChkFns dropping unreadable chunk ranges\n    }\n    return err\n}","preventionTips":["Always copy complete block directories (meta.json, index, chunks/*) atomically; verify segment file count and sizes","Supply ignoreChkFns covering known-bad time ranges when repairing blocks with known data loss","Monitor disk health (SMART/dmesg) on TSDB storage nodes","Keep replicas (or remote storage backfill) available for restoring missing segments/ files"],"tags":["tsdb","chunks","corruption","repair"],"backgroundTag":"file-read-failed","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}