thanos-io/thanos · error
failed to finalize the block
Error message
failed to finalize the block %s
What it means
Wraps the finalization step for a compacted result block — writing Thanos metadata via metadata.InjectThanos and finalizing files on disk after the index passed health checks. Failure here means the block exists on disk but is not upload-ready, so the compaction attempt is retried.
Solutions
- Check write permissions on the block dir
- Inspect the wrapped metadata error
- Re-run compaction for this group
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at pkg/compact/compact.go:1342 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07).
Data as JSON: /api/errors/1cab77581c7ba93d.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/compact/compact.go:1342
return false, nil, halt(errors.Wrapf(err, "invalid result block %s", bdir))
}
thanosMeta := metadata.Thanos{
Labels: cg.labels.Map(),
Downsample: metadata.ThanosDownsample{Resolution: cg.resolution},
Source: metadata.CompactorSource,
SegmentFiles: block.GetSegmentFiles(bdir),
Extensions: cg.Extensions(),
}
if stats.ChunkMaxSize > 0 {
thanosMeta.IndexStats.ChunkMaxSize = stats.ChunkMaxSize
}
if stats.SeriesMaxSize > 0 {
thanosMeta.IndexStats.SeriesMaxSize = stats.SeriesMaxSize
}
newMeta, err = metadata.InjectThanos(cg.logger, bdir, thanosMeta, nil)
if err != nil {
return false, nil, errors.Wrapf(err, "failed to finalize the block %s", bdir)
}
// Ensure the output block is not overlapping with anything else,
// unless vertical compaction is enabled.
if !cg.enableVerticalCompaction {
if err := cg.areBlocksOverlapping(newMeta, toCompact...); err != nil {
return false, nil, halt(errors.Wrapf(err, "resulted compacted block %s overlaps with something", bdir))
}
}
begin = time.Now()
err = tracing.DoInSpanWithErr(ctx, "compaction_block_upload", func(ctx context.Context) error {
return block.Upload(ctx, cg.logger, cg.bkt, bdir, cg.hashFunc, objstore.WithUploadConcurrency(cg.blockFilesConcurrency))
})
if err != nil {
return false, nil, retry(errors.Wrapf(err, "upload of %s failed", compID))
}
level.Info(cg.logger).Log("msg", "uploaded block", "result_block", compID, "duration", time.Since(begin), "duration_ms", time.Since(begin).Milliseconds())View on GitHub (pinned to 35b8b99117)