{"record":{"id":"87c19cf0eea14cd2","repo":"thanos-io/thanos","slug":"iterate-chunk-while-re-encoding","errorCode":null,"errorMessage":"iterate chunk while re-encoding","messagePattern":"iterate chunk while re-encoding","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compactv2/modifiers.go","lineNumber":329,"sourceCode":"\t\treturn false\n\t}\n\n\tp.curr = p.currChkMeta\n\tif p.currDelIter == nil {\n\t\treturn true\n\t}\n\n\t// Re-encode the chunk if iterator is provider. This means that it has some samples to be deleted or chunk is opened.\n\tnewChunk := chunkenc.NewXORChunk()\n\tapp, err := newChunk.Appender()\n\tif err != nil {\n\t\tp.err = err\n\t\treturn false\n\t}\n\n\tif p.currDelIter.Next() == chunkenc.ValNone {\n\t\tif err := p.currDelIter.Err(); err != nil {\n\t\t\tp.err = errors.Wrap(err, \"iterate chunk while re-encoding\")\n\t\t\treturn false\n\t\t}\n\n\t\t// Empty chunk, this should not happen, as we assume full deletions being filtered before this iterator.\n\t\tp.err = errors.Wrap(err, \"populateWithDelChunkSeriesIterator: unexpected empty chunk found while rewriting chunk\")\n\t\treturn false\n\t}\n\n\tt, v := p.currDelIter.At()\n\tp.curr.MinTime = t\n\tapp.Append(t, v)\n\n\tfor p.currDelIter.Next() != chunkenc.ValNone {\n\t\tt, v = p.currDelIter.At()\n\t\tapp.Append(t, v)\n\t}\n\tif err := p.currDelIter.Err(); err != nil {\n\t\tp.err = errors.Wrap(err, \"iterate chunk while re-encoding\")","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/compactv2/modifiers.go#L311-L347","documentation":"Inside the populateWithDelChunkSeriesIterator.Next, after advancing the deletion-filtered chunk iterator, any iterator error is wrapped as \"iterate chunk while re-encoding\". The chunk was being rewritten (e.g. with tombstones/time-window modifiers applied) and the source iterator failed mid-iteration.","triggerScenarios":"currDelIter.Next() returns ValNone and currDelIter.Err() is non-nil — a decoding error, corrupted chunk data, or I/O error while reading chunk samples during chunk rewriting with deletion modifiers.","commonSituations":"Corrupted source chunk data in a block being compacted with a deletion/time-range modifier; I/O errors reading chunk segments mid-compaction; incompatible chunk encoding discovered during re-encode.","solutions":["Inspect the inner error from currDelIter.Err() to identify the corrupt chunk/series","Validate or remove the source block containing the failing chunk","Check storage I/O health; retry compaction if transient","If a modifier (e.g. deleting a time range) triggers it, verify the deletion window against actual chunk boundaries"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-validate block chunk files before compaction with modifiers\nif err := tsdb.CheckChunks(blockDir); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":"if err := comp.WriteSeries(ctx, readers, sWriter, progress); err != nil {\n    if strings.Contains(err.Error(), \"iterate chunk while re-encoding\") {\n        logger.Error(\"chunk iteration failed during re-encode\", \"err\", err)\n    }\n    return err\n}","preventionTips":["Run block verification before destructive compactions with modifiers","Ensure deletion ranges are applied through the intended pre-filtering pipeline","Monitor storage for read errors during compaction"],"tags":["go","tsdb","chunks","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"}