{"record":{"id":"043772cf539d7f5f","repo":"thanos-io/thanos","slug":"write-index-header-043772","errorCode":null,"errorMessage":"write index header","messagePattern":"write index header","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/indexheader/lazy_binary_reader.go","lineNumber":120,"sourceCode":"\tpostingOffsetsInMemSampling int,\n\tmetrics *LazyBinaryReaderMetrics,\n\tbinaryReaderMetrics *BinaryReaderMetrics,\n\tonClosed func(*LazyBinaryReader),\n\tlazyDownload bool,\n) (*LazyBinaryReader, error) {\n\tif dir != \"\" && !lazyDownload {\n\t\tindexHeaderFile := filepath.Join(dir, id.String(), block.IndexHeaderFilename)\n\t\t// If the index-header doesn't exist we should download it.\n\t\tif _, err := os.Stat(indexHeaderFile); err != nil {\n\t\t\tif !os.IsNotExist(err) {\n\t\t\t\treturn nil, errors.Wrap(err, \"read index header\")\n\t\t\t}\n\n\t\t\tlevel.Debug(logger).Log(\"msg\", \"the index-header doesn't exist on disk; recreating\", \"path\", indexHeaderFile)\n\n\t\t\tstart := time.Now()\n\t\t\tif _, err := WriteBinary(ctx, bkt, id, indexHeaderFile, binaryReaderMetrics.downloadDuration); err != nil {\n\t\t\t\treturn nil, errors.Wrap(err, \"write index header\")\n\t\t\t}\n\n\t\t\tlevel.Debug(logger).Log(\"msg\", \"built index-header file\", \"path\", indexHeaderFile, \"elapsed\", time.Since(start))\n\t\t}\n\t}\n\n\treturn &LazyBinaryReader{\n\t\tctx:                         ctx,\n\t\tlogger:                      logger,\n\t\tbkt:                         bkt,\n\t\tdir:                         dir,\n\t\tid:                          id,\n\t\tpostingOffsetsInMemSampling: postingOffsetsInMemSampling,\n\t\tmetrics:                     metrics,\n\t\tbinaryReaderMetrics:         binaryReaderMetrics,\n\t\tusedAt:                      atomic.NewInt64(time.Now().UnixNano()),\n\t\tonClosed:                    onClosed,\n\t\tlazyDownload:                lazyDownload,","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/indexheader/lazy_binary_reader.go#L102-L138","documentation":"NewLazyBinaryReader wraps errors from WriteBinary when the index-header file is missing on disk and must be (re)built from the object store. It means Thanos could not produce or persist the index-header — download failure, object not found, or local write failure.","triggerScenarios":"Index-header missing locally and lazyDownload=true (or non-lazy path after stat shows not-exist): WriteBinary(ctx, bkt, id, ...) fails because the object-store download errors, the block doesn't exist in the bucket, or the local file write fails.","commonSituations":"Block deleted from bucket while still referenced; expired/insufficient object-storage credentials; network outage to the bucket; read-only cache directory preventing the write.","solutions":["Check object storage connectivity and credentials (try listing/downloading the block manually)","Verify the block still exists in the bucket (it may have been deleted/compacted away)","Ensure the local cache directory is writable","Retry — transient network failures are common; Thanos will rebuild the index-header on next attempt"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if _, err := bkt.Exists(ctx, filepath.Join(id.String(), block.IndexFilename)); err != nil { /* block missing in bucket; don't attempt lazy download */ }","typeGuard":null,"tryCatchPattern":"r, err := indexheader.NewLazyBinaryReader(...)\nif err != nil && strings.Contains(err.Error(), \"write index header\") { retry with backoff; verify bucket creds and disk space }","preventionTips":["Ensure object-storage credentials allow Get on block objects","Keep the cache directory writable and with free space","Use retries with backoff for transient bucket errors","Confirm block lifecycle policies don't delete blocks still served"],"tags":["object-storage","index-header","download","write"],"backgroundTag":"file-write-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"}