{"record":{"id":"47f8df803bdbeb52","repo":"thanos-io/thanos","slug":"write-index-header-toc","errorCode":null,"errorMessage":"write index header TOC","messagePattern":"write index header TOC","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/indexheader/binary_reader.go","lineNumber":154,"sourceCode":"\n\tif err := ir.CopySymbols(bw.SymbolsWriter(), buf); err != nil {\n\t\treturn nil, err\n\t}\n\n\tif err := bw.writer.Flush(); err != nil {\n\t\treturn nil, errors.Wrap(err, \"flush\")\n\t}\n\n\tif err := ir.CopyPostingsOffsets(bw.PostingOffsetsWriter(), buf); err != nil {\n\t\treturn nil, err\n\t}\n\n\tif err := bw.writer.Flush(); err != nil {\n\t\treturn nil, errors.Wrap(err, \"flush\")\n\t}\n\n\tif err := bw.WriteTOC(); err != nil {\n\t\treturn nil, errors.Wrap(err, \"write index header TOC\")\n\t}\n\n\tif err := bw.writer.Flush(); err != nil {\n\t\treturn nil, errors.Wrap(err, \"flush\")\n\t}\n\n\tif err := bw.writer.Sync(); err != nil {\n\t\treturn nil, errors.Wrap(err, \"sync\")\n\t}\n\n\tif tmpFilename != \"\" {\n\t\t// Create index-header in atomic way, to avoid partial writes (e.g during restart or crash of store GW).\n\t\treturn nil, os.Rename(tmpFilename, filename)\n\t}\n\n\treturn bw.Buffer(), nil\n}\n","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/indexheader/binary_reader.go#L136-L172","documentation":"WriteTOC writes the Table-Of-Contents section (offsets to symbols, postings table, etc.) at the end of the index-header stream. This error wraps a failure from bw.WriteTOC(), typically a write/flush error inside the TOC serialization (buffered writer write failure) rather than a data-content problem.","triggerScenarios":"WriteBinary -> bw.WriteTOC() failing because the underlying bufio.Writer write inside WriteTOC fails (disk full, EIO, closed writer). Reached only after both earlier flushes in WriteBinary succeeded.","commonSituations":"Persistent volume filled up mid-write (earlier flushes consumed the last free bytes); storage device failure late in the write; test/benchmark environments with a tmpfs that ran out of space.","solutions":["Check remaining disk space; TOC writes fail when the volume filled during earlier writes.","Inspect storage health for late-stage I/O errors (dmesg).","Retry the operation after freeing space; delete stale .tmp index-header files.","If it persists, verify the Thanos version for known binary-writer bugs and upgrade."],"exampleFix":"// before\nif err := bw.WriteTOC(); err != nil {\n    return nil, errors.Wrap(err, \"write index header TOC\")\n}\n// after\nif err := bw.WriteTOC(); err != nil {\n    return nil, errors.Wrapf(err, \"write index header TOC for block %s (disk full?)\", id)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Go: inspect the wrapped cause for space/device errors\n_, err := indexheader.WriteBinary(ctx, bkt, id, dst)\nif err != nil && strings.Contains(err.Error(), \"write index header TOC\") {\n    switch {\n    case errors.Is(err, syscall.ENOSPC):\n        log.Error(\"disk full while writing TOC\")\n    case errors.Is(err, syscall.EIO):\n        log.Error(\"I/O error while writing TOC; check device health\")\n    }\n    return err\n}","preventionTips":["Alert on disk fills; TOC is the last write so failures here mean space ran out mid-build.","For tmpfs-based test environments, size tmpfs for expected index-header sizes.","Clean up orphaned .tmp files after crashes to reclaim space.","Keep Thanos updated; binary-writer I/O handling has been improved over releases."],"tags":["io","toc","thanos","index-header"],"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"}