{"record":{"id":"3bd0077379f2e511","repo":"thanos-io/thanos","slug":"unknown-segment-file-for-index-d","errorCode":null,"errorMessage":"unknown segment file for index %d","messagePattern":"unknown segment file for index (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/bucket.go","lineNumber":2529,"sourceCode":"\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"get range reader\")\n\t}\n\tdefer runutil.CloseWithLogOnErr(logger, r, \"readIndexRange close range reader\")\n\n\t// Preallocate the buffer with the exact size so we don't waste allocations\n\t// while progressively growing an initial small buffer. The buffer capacity\n\t// is increased by MinRead to avoid extra allocations due to how ReadFrom()\n\t// internally works.\n\tbuf := bytes.NewBuffer(make([]byte, 0, length+bytes.MinRead))\n\tif _, err := buf.ReadFrom(r); err != nil {\n\t\treturn nil, errors.Wrap(err, \"read range\")\n\t}\n\treturn buf.Bytes(), nil\n}\n\nfunc (b *bucketBlock) readChunkRange(ctx context.Context, seq int, off, length int64, chunkRanges byteRanges, logger log.Logger) (*[]byte, error) {\n\tif seq < 0 || seq >= len(b.chunkObjs) {\n\t\treturn nil, errors.Errorf(\"unknown segment file for index %d\", seq)\n\t}\n\n\t// Get a reader for the required range.\n\treader, err := b.bkt.GetRange(ctx, b.chunkObjs[seq], off, length)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"get range reader\")\n\t}\n\tdefer runutil.CloseWithLogOnErr(logger, reader, \"readChunkRange close range reader\")\n\n\t// Get a buffer from the pool.\n\tchunkBuffer, err := b.chunkPool.Get(chunkRanges.size())\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"allocate chunk bytes\")\n\t}\n\n\t*chunkBuffer, err = readByteRanges(reader, *chunkBuffer, chunkRanges)\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":2511,"sourceCodeEnd":2547,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/bucket.go#L2511-L2547","documentation":"bucketBlock.readChunkRange validates the segment index against the block's chunkObjs list before reading. If seq is negative or >= len(chunkObjs), meaning the caller asked for a segment file that does not exist in this block's index-header/meta, it returns 'unknown segment file for index %d'. It signals a caller/contract violation or a stale block view, not a storage failure.","triggerScenarios":"Calling readChunkRange with a seq outside [0, len(b.chunkObjs)); happens when a cached ChunkObj/AggrChunk reference points to a segment that is no longer listed in the block's index header, or bad partition arithmetic on compound chunks.","commonSituations":"Store-gateway caching series/chunks across block reloads, corrupted or partially-uploaded index header, blocks replaced/deleted in the bucket while cached references persist, bugs in external tools computing chunk offsets.","solutions":["Reload block metadata (remove stale cached blocks via store-gateway reload or restart) so chunkObjs matches the actual bucket state.","Verify the index header file for the block lists the expected segment; re-download or use Thanos tools to inspect.","Check for concurrent block deletion/compaction racing with reads; ensure compactor retention/cleanup is not removing blocks mid-query.","If reproducible on a healthy block, file a bug with the block ID and query; it indicates internal index math went wrong."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if seq < 0 || seq >= len(block.ChunkObjs()) {\n\t// refresh block metadata before retrying\n\terr := block.Reload(ctx)\n}","typeGuard":"func validSegment(seq int, objs []string) bool { return seq >= 0 && seq < len(objs) }","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"unknown segment file\") {\n\t// reload block list / resync store-gateway before retry\n}","preventionTips":["Keep store-gateway block sync interval low so cached refs track bucket state","Avoid deleting blocks while queries are in flight","Validate index-header integrity during block sync"],"tags":["index-out-of-range","thanos-store-gateway","chunks"],"backgroundTag":"index-out-of-range","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"}