thanos-io/thanos · error
iterate chunk while re-encoding
Error message
iterate chunk while re-encoding
What it means
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.
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
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-validate block chunk files before compaction with modifiers
if err := tsdb.CheckChunks(blockDir); err != nil {
return err
} Try / catch
if err := comp.WriteSeries(ctx, readers, sWriter, progress); err != nil {
if strings.Contains(err.Error(), "iterate chunk while re-encoding") {
logger.Error("chunk iteration failed during re-encode", "err", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07).
Data as JSON: /api/errors/87c19cf0eea14cd2.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/compactv2/modifiers.go:329
return false
}
p.curr = p.currChkMeta
if p.currDelIter == nil {
return true
}
// Re-encode the chunk if iterator is provider. This means that it has some samples to be deleted or chunk is opened.
newChunk := chunkenc.NewXORChunk()
app, err := newChunk.Appender()
if err != nil {
p.err = err
return false
}
if p.currDelIter.Next() == chunkenc.ValNone {
if err := p.currDelIter.Err(); err != nil {
p.err = errors.Wrap(err, "iterate chunk while re-encoding")
return false
}
// Empty chunk, this should not happen, as we assume full deletions being filtered before this iterator.
p.err = errors.Wrap(err, "populateWithDelChunkSeriesIterator: unexpected empty chunk found while rewriting chunk")
return false
}
t, v := p.currDelIter.At()
p.curr.MinTime = t
app.Append(t, v)
for p.currDelIter.Next() != chunkenc.ValNone {
t, v = p.currDelIter.At()
app.Append(t, v)
}
if err := p.currDelIter.Err(); err != nil {
p.err = errors.Wrap(err, "iterate chunk while re-encoding")View on GitHub (pinned to 35b8b99117)