{"record":{"id":"715e419d6474c1b1","repo":"thanos-io/thanos","slug":"open-block-v","errorCode":null,"errorMessage":"open block %v","messagePattern":"open block (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/thanos/tools_bucket.go","lineNumber":1259,"sourceCode":"\t\tctx, cancel := context.WithCancel(context.Background())\n\t\tg.Add(func() error {\n\t\t\tchunkPool := chunkenc.NewPool()\n\t\t\tchangeLog := compactv2.NewChangeLog(io.Discard)\n\t\t\tstubCounter := promauto.With(nil).NewCounter(prometheus.CounterOpts{})\n\t\t\tfor _, id := range ids {\n\t\t\t\t// Delete series from block & modify.\n\t\t\t\tlevel.Info(logger).Log(\"msg\", \"downloading block\", \"source\", id)\n\t\t\t\tif err := block.Download(ctx, logger, insBkt, id, filepath.Join(tbc.tmpDir, id.String())); err != nil {\n\t\t\t\t\treturn errors.Wrapf(err, \"download %v\", id)\n\t\t\t\t}\n\n\t\t\t\tmeta, err := metadata.ReadFromDir(filepath.Join(tbc.tmpDir, id.String()))\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn errors.Wrapf(err, \"read meta of %v\", id)\n\t\t\t\t}\n\t\t\t\tb, err := tsdb.OpenBlock(logutil.GoKitLogToSlog(logger), filepath.Join(tbc.tmpDir, id.String()), chunkPool, nil)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn errors.Wrapf(err, \"open block %v\", id)\n\t\t\t\t}\n\n\t\t\t\tp := compactv2.NewProgressLogger(logger, int(b.Meta().Stats.NumSeries))\n\t\t\t\tnewID := ulid.MustNew(ulid.Now(), rand.Reader)\n\t\t\t\tmeta.ULID = newID\n\t\t\t\tmeta.Thanos.Rewrites = append(meta.Thanos.Rewrites, metadata.Rewrite{\n\t\t\t\t\tSources:          meta.Compaction.Sources,\n\t\t\t\t\tDeletionsApplied: deletions,\n\t\t\t\t\tRelabelsApplied:  relabels,\n\t\t\t\t})\n\t\t\t\tmeta.Compaction.Sources = []ulid.ULID{newID}\n\t\t\t\tmeta.Thanos.Source = metadata.BucketRewriteSource\n\n\t\t\t\tif err := os.MkdirAll(filepath.Join(tbc.tmpDir, newID.String()), os.ModePerm); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\n\t\t\t\tif *provideChangeLog {","sourceCodeStart":1241,"sourceCodeEnd":1277,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/tools_bucket.go#L1241-L1277","documentation":"Wraps tsdb.OpenBlock failing when the rewrite command opens the downloaded block to read its index and chunks. OpenBlock validates the block's index format, chunk encoding, and internal consistency; a failure means the block data on disk is corrupt, from an incompatible TSDB version, or incompletely downloaded.","triggerScenarios":"Block index or chunks corrupted in object store or during download; block written by a newer Prometheus/Thanos version using unsupported index format; truncated files on disk due to disk pressure; not enough memory to load index.","commonSituations":"Upgrading thanos binary behind the block format produced by a newer Prometheus; damaged object after manual object-store manipulation; interrupted earlier download; index file zero-length after a failed upload previously accepted by a broken uploader.","solutions":["Re-run with a fresh tmpDir to rule out a partial download, then retry.","Verify block integrity with `thanos tools bucket verify` and check the block against its meta.json hash; restore the block from a backup if corrupted.","Upgrade (or downgrade) the thanos binary so its embedded TSDB version supports the block's index format."],"exampleFix":"// before\nthanos tools bucket rewrite --objstore.bucket=b ID\n// after (fresh temp dir and current binary)\nthanos tools bucket rewrite --objstore.bucket=b --tmp.dir=$(mktemp -d) ID","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"b, err := tsdb.OpenBlock(slog, dir, chunkPool, nil)\nif err != nil {\n    level.Error(logger).Log(\"msg\", \"corrupt block\", \"id\", id, \"err\", err)\n    return errors.Wrapf(err, \"open block %v; consider bucket verify/restore\", id)\n}","preventionTips":["Run `thanos tools bucket verify` periodically to detect corrupt blocks","Keep the thanos binary compatible with the Prometheus version writing blocks","Use fresh tmpDir to rule out partial downloads"],"tags":["thanos","tsdb","corruption","block-index"],"backgroundTag":"file-read-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"}