{"record":{"id":"1cab77581c7ba93d","repo":"thanos-io/thanos","slug":"failed-to-finalize-the-block-s","errorCode":null,"errorMessage":"failed to finalize the block %s","messagePattern":"failed to finalize the block (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compact/compact.go","lineNumber":1342,"sourceCode":"\t\t\treturn false, nil, halt(errors.Wrapf(err, \"invalid result block %s\", bdir))\n\t\t}\n\n\t\tthanosMeta := metadata.Thanos{\n\t\t\tLabels:       cg.labels.Map(),\n\t\t\tDownsample:   metadata.ThanosDownsample{Resolution: cg.resolution},\n\t\t\tSource:       metadata.CompactorSource,\n\t\t\tSegmentFiles: block.GetSegmentFiles(bdir),\n\t\t\tExtensions:   cg.Extensions(),\n\t\t}\n\t\tif stats.ChunkMaxSize > 0 {\n\t\t\tthanosMeta.IndexStats.ChunkMaxSize = stats.ChunkMaxSize\n\t\t}\n\t\tif stats.SeriesMaxSize > 0 {\n\t\t\tthanosMeta.IndexStats.SeriesMaxSize = stats.SeriesMaxSize\n\t\t}\n\t\tnewMeta, err = metadata.InjectThanos(cg.logger, bdir, thanosMeta, nil)\n\t\tif err != nil {\n\t\t\treturn false, nil, errors.Wrapf(err, \"failed to finalize the block %s\", bdir)\n\t\t}\n\t\t// Ensure the output block is not overlapping with anything else,\n\t\t// unless vertical compaction is enabled.\n\t\tif !cg.enableVerticalCompaction {\n\t\t\tif err := cg.areBlocksOverlapping(newMeta, toCompact...); err != nil {\n\t\t\t\treturn false, nil, halt(errors.Wrapf(err, \"resulted compacted block %s overlaps with something\", bdir))\n\t\t\t}\n\t\t}\n\n\t\tbegin = time.Now()\n\n\t\terr = tracing.DoInSpanWithErr(ctx, \"compaction_block_upload\", func(ctx context.Context) error {\n\t\t\treturn block.Upload(ctx, cg.logger, cg.bkt, bdir, cg.hashFunc, objstore.WithUploadConcurrency(cg.blockFilesConcurrency))\n\t\t})\n\t\tif err != nil {\n\t\t\treturn false, nil, retry(errors.Wrapf(err, \"upload of %s failed\", compID))\n\t\t}\n\t\tlevel.Info(cg.logger).Log(\"msg\", \"uploaded block\", \"result_block\", compID, \"duration\", time.Since(begin), \"duration_ms\", time.Since(begin).Milliseconds())","sourceCodeStart":1324,"sourceCodeEnd":1360,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/compact/compact.go#L1324-L1360","documentation":"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.","triggerScenarios":"Thrown at pkg/compact/compact.go:1342 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check write permissions on the block dir","Inspect the wrapped metadata error","Re-run compaction for this group"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}