{"record":{"id":"7975998959842730","repo":"thanos-io/thanos","slug":"write-index-header","errorCode":null,"errorMessage":"write index header","messagePattern":"write index header","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/indexheader/binary_reader.go","lineNumber":582,"sourceCode":"\tpostingOffsetsInMemSampling int\n\n\tmetrics *BinaryReaderMetrics\n}\n\n// NewBinaryReader loads or builds new index-header if not present on disk.\nfunc NewBinaryReader(ctx context.Context, logger log.Logger, bkt objstore.BucketReader, dir string, id ulid.ULID, postingOffsetsInMemSampling int, metrics *BinaryReaderMetrics) (*BinaryReader, error) {\n\tif dir != \"\" {\n\t\tbinfn := filepath.Join(dir, id.String(), block.IndexHeaderFilename)\n\t\tbr, err := newFileBinaryReader(binfn, postingOffsetsInMemSampling, metrics)\n\t\tif err == nil {\n\t\t\treturn br, nil\n\t\t}\n\n\t\tlevel.Debug(logger).Log(\"msg\", \"failed to read index-header from disk; recreating\", \"path\", binfn, \"err\", err)\n\n\t\tstart := time.Now()\n\t\tif _, err := WriteBinary(ctx, bkt, id, binfn, metrics.downloadDuration); err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"write index header\")\n\t\t}\n\n\t\tlevel.Debug(logger).Log(\"msg\", \"built index-header file\", \"path\", binfn, \"elapsed\", time.Since(start))\n\t\treturn newFileBinaryReader(binfn, postingOffsetsInMemSampling, metrics)\n\t} else {\n\t\tbuf, err := WriteBinary(ctx, bkt, id, \"\", metrics.downloadDuration)\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"generate index header\")\n\t\t}\n\n\t\treturn newMemoryBinaryReader(buf, postingOffsetsInMemSampling, metrics)\n\t}\n}\n\nfunc newMemoryBinaryReader(buf []byte, postingOffsetsInMemSampling int, metrics *BinaryReaderMetrics) (bw *BinaryReader, err error) {\n\tr := &BinaryReader{\n\t\tb:                           realByteSlice(buf),\n\t\tc:                           nil,","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/indexheader/binary_reader.go#L564-L600","documentation":"When loading an index-header, WriteBinaryToDisk-style logic first tries to read the existing index-header file from disk; if that fails it logs a debug message and regenerates it via WriteBinary (downloading index-header info from the bucket). This error wraps any failure of that regeneration step, so the root cause is inside WriteBinary (bucket download, size-limit error, file creation error, etc.).","triggerScenarios":"NewBinaryReader/LoadBinaryReader path with a cache filename: the cached .index-header file is missing/corrupt on disk, then WriteBinary fails — e.g., bucket download error, object not found, 64GiB size limit hit, or permission failure creating the cache file.","commonSituations":"Object store outage or wrong credentials causing the index download to fail; corrupted cached index-header being recreated; disk full when writing the regenerated cache file.","solutions":["Inspect the wrapped (cause) error: if it's a download/object error, verify object-store credentials, endpoint, and that the block's index files exist in the bucket.","If the cache file was corrupt, delete the cache file and retry — it will be regenerated.","Check free disk space and permissions on the cache directory.","Retry the store gateway query; transient bucket errors are often temporary."],"exampleFix":"null","handlingStrategy":"retry","validationCode":"// ensure cache dir usable before attempting regeneration\nif err := os.MkdirAll(cacheDir, 0o755); err != nil {\n    return fmt.Errorf(\"cache dir unusable: %w\", err)\n}\nif fi, err := os.Stat(cachePath); err == nil && fi.Size() == 0 {\n    os.Remove(cachePath)\n}","typeGuard":"null","tryCatchPattern":"b, err := WriteBinaryToDisk(ctx, bkt, id, cachePath, metrics.DownloadDuration)\nvar netErr net.Error\nif err != nil && errors.As(err, &netErr) {\n    return retry.WithBackoff(ctx, func() error {\n        _, err = WriteBinaryToDisk(ctx, bkt, id, cachePath, metrics.DownloadDuration)\n        return err\n    })\n}","preventionTips":["Check object-store credentials and endpoint before load.","Configure a disk cache so regeneration is rare.","Monitor bucket error rates and add retry/backoff.","Delete corrupt cache files promptly instead of blocking."],"tags":["object-storage","index-header","download","thanos"],"backgroundTag":"http-request-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"}