{"record":{"id":"86d39e501e3d93dc","repo":"thanos-io/thanos","slug":"chunk-iter","errorCode":null,"errorMessage":"chunk iter","messagePattern":"chunk iter","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compactv2/chunk_series_set.go","lineNumber":209,"sourceCode":"\t// Iterate over all sorted chunk series.\n\tfor populatedSet.Next() {\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\treturn ctx.Err()\n\t\tdefault:\n\t\t}\n\n\t\ts := populatedSet.At()\n\t\tchksIter := s.Iterator(nil)\n\t\tchks = chks[:0]\n\t\tfor chksIter.Next() {\n\t\t\t// We are not iterating in streaming way over chunk as it's more efficient to do bulk write for index and\n\t\t\t// chunk file purposes.\n\t\t\tchks = append(chks, chksIter.At())\n\t\t}\n\n\t\tif chksIter.Err() != nil {\n\t\t\treturn errors.Wrap(chksIter.Err(), \"chunk iter\")\n\t\t}\n\n\t\t// Skip the series with all deleted chunks.\n\t\tif len(chks) == 0 {\n\t\t\t// All series will be ignored.\n\t\t\tp.SeriesProcessed()\n\t\t\tcontinue\n\t\t}\n\n\t\tif err := sWriter.WriteChunks(chks...); err != nil {\n\t\t\treturn errors.Wrap(err, \"write chunks\")\n\t\t}\n\t\tif err := sWriter.AddSeries(ref, s.Labels(), chks...); err != nil {\n\t\t\treturn errors.Wrap(err, \"add series\")\n\t\t}\n\t\tfor _, chk := range chks {\n\t\t\t// ChunkPool is used by tsdb.OpenBlock BlockReader.\n\t\t\tif err := w.chunkPool.Put(chk.Chunk); err != nil {","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/compactv2/chunk_series_set.go#L191-L227","documentation":"During per-series chunk accumulation in write(), chksIter.Err() was non-nil after draining the series' chunk iterator. The error means enumerating a series' chunks (from the populated lazy set) failed mid-way — typically an error chunk from the deferred population of chunk data.","triggerScenarios":"write() appends chunks from populatedSet's chksIter per series; a previous lazyPopulatableChunk.populate failure surfaces here as the iterator's error (e.g. unreadable chunk bytes), or the chunk list iterator itself failed.","commonSituations":"Corrupt or truncated source chunk files, partially uploaded blocks in object storage, disk read errors on the compactor node.","solutions":["Follow the wrapped cause to the failing chunk Ref; validate and repair/replace the corrupt source block.","Re-sync blocks from object storage to rule out truncated uploads (verify file sizes/checksums).","Retry compaction; if persistent, remove the bad block from the compaction set.","Check compactor host disk health (dmesg, SMART) for underlying IO errors."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-check chunk files of the source block before building the set\nif err := verifyChunkSegmentFiles(blockDir); err != nil {\n    excludeFromCompaction(blockDir, err)\n}","typeGuard":"func chunkIterHealthy(it chunkIterable) bool { return it.Err() == nil }","tryCatchPattern":"if err := WriteSeries(ctx, set, symbols); err != nil {\n    if isChunkCorruption(err) {\n        markBlockForRepair(sourceBlockID)\n    }\n    return err\n}","preventionTips":["Verify chunk file integrity after block downloads/uploads","Track and alert on truncated segments from object storage","Check compactor host disk health (SMART, dmesg) periodically","Exclude blocks with known corruption from the compaction plan"],"tags":["go","tsdb","chunk","iterator"],"backgroundTag":"database-query-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"}