{"record":{"id":"2e293d256b04ce2f","repo":"thanos-io/thanos","slug":"get-all-postings","errorCode":null,"errorMessage":"get all postings","messagePattern":"get all postings","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/index.go","lineNumber":228,"sourceCode":"\t}\n\treturn n.sum / n.cnt\n}\n\n// GatherIndexHealthStats returns useful counters as well as outsider chunks (chunks outside of block time range) that\n// helps to assess index health.\n// It considers https://github.com/prometheus/tsdb/issues/347 as something that Thanos can handle.\n// See HealthStats.Issue347OutsideChunks for details.\nfunc GatherIndexHealthStats(ctx context.Context, logger log.Logger, fn string, minTime, maxTime int64) (stats HealthStats, err error) {\n\tr, err := index.NewFileReader(fn, index.DecodePostingsRaw)\n\tif err != nil {\n\t\treturn stats, errors.Wrap(err, \"open index file\")\n\t}\n\tdefer runutil.CloseWithErrCapture(&err, r, \"gather index issue file reader\")\n\n\tkey, value := index.AllPostingsKey()\n\tp, err := r.Postings(ctx, key, value)\n\tif err != nil {\n\t\treturn stats, errors.Wrap(err, \"get all postings\")\n\t}\n\tvar (\n\t\tlset     labels.Labels\n\t\tprevLset labels.Labels\n\t\tbuilder  labels.ScratchBuilder\n\n\t\tchks []chunks.Meta\n\n\t\tseriesLifeDuration                          = newMinMaxSumInt64()\n\t\tseriesLifeDurationWithoutSingleSampleSeries = newMinMaxSumInt64()\n\t\tseriesChunks                                = newMinMaxSumInt64()\n\t\tchunkDuration                               = newMinMaxSumInt64()\n\t\tchunkSize                                   = newMinMaxSumInt64()\n\t\tseriesSize                                  = newMinMaxSumInt64()\n\t)\n\n\tlnames, err := r.LabelNames(ctx)\n\tif err != nil {","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/index.go#L210-L246","documentation":"GatherIndexHealthStats reads a block's index via Postings(ctx, index.AllPostingsKey(), \"\") to iterate every series. If the postings list for the all-postings key cannot be read (corrupt/truncated index file, missing postings table section, or context cancellation), the underlying error is wrapped with \"get all postings\". It signals the block index is unreadable at the postings level.","triggerScenarios":"Calling GatherIndexHealthStats (directly or via VerifyIndex or processDownsampling) on a block whose index file has a damaged or missing postings section, or whose context is cancelled/times out while reading postings.","commonSituations":"Blocks corrupted by incomplete uploads to object storage, disk corruption on compacted blocks, interrupted block downloads, or cancelled/short-timeout contexts during verification of many blocks.","solutions":["Re-download or restore the block from object storage or a backup; the index is likely corrupt","Run VerifyIndex on the block to confirm and localize index corruption","Check ctx timeouts/deadlines are long enough when verifying large blocks","Delete the corrupt block (it will typically be re-synced/re-compacted) if it cannot be repaired"],"exampleFix":"// before\nstats, err := block.GatherIndexHealthStats(ctx, bdir) // fails: get all postings\n// after\nif err := block.VerifyIndex(ctx, bdir, defaultVerifyIndexConcurrency); err != nil {\n    logger.Log(\"msg\", \"corrupt block, removing\", \"dir\", bdir, \"err\", err)\n    os.RemoveAll(bdir)\n}","handlingStrategy":"try-catch","validationCode":"f, err := os.Open(filepath.Join(bdir, \"index\"))\nif err != nil { return err }\nfi, _ := f.Stat(); f.Close()\nif fi.Size() == 0 { return fmt.Errorf(\"index file empty in %s\", bdir) }","typeGuard":"func hasIndexFile(bdir string) bool {\n    fi, err := os.Stat(filepath.Join(bdir, \"index\"))\n    return err == nil && !fi.IsDir() && fi.Size() > 0\n}","tryCatchPattern":"stats, err := block.GatherIndexHealthStats(ctx, bdir)\nif err != nil && strings.Contains(err.Error(), \"get all postings\") {\n    return fmt.Errorf(\"block %s index unreadable, re-sync from object storage: %w\", bdir, err)\n}","preventionTips":["Use bounded contexts with realistic timeouts when scanning many blocks","Verify blocks after download/upload (VerifyIndex) before serving","Enable object storage checksum validation to catch truncated uploads","Alert on corrupt blocks and tombstone them automatically"],"tags":["corruption","index","storage"],"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"}