{"record":{"id":"faab5920df21e2e6","repo":"weaviate/weaviate","slug":"unsupported-strategy-in-segment-w","errorCode":null,"errorMessage":"unsupported strategy in segment: %w","messagePattern":"unsupported strategy in segment: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"adapters/repos/db/lsmkv/segment.go","lineNumber":320,"sourceCode":"\t\tunMapContents = true\n\t} else { // read the file into memory if it's small enough and we have enough memory\n\t\tmeteredF := diskio.NewMeteredReader(file, diskio.MeteredReaderCallback(metrics.ReadObserver(\"readSegmentFile\")))\n\t\tbufio.NewReader(meteredF)\n\t\tcontents, err = io.ReadAll(meteredF)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"read file: %w\", err)\n\t\t}\n\t\tunMapContents = false\n\t\treadFromMemory = true\n\t\tuseBloomFilter = false\n\t}\n\theader, err := segmentindex.ParseHeader(contents[:segmentindex.HeaderSize])\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"parse header: %w\", err)\n\t}\n\n\tif err := segmentindex.CheckExpectedStrategy(header.Strategy); err != nil {\n\t\treturn nil, fmt.Errorf(\"unsupported strategy in segment: %w\", err)\n\t}\n\n\tif header.Version >= segmentindex.SegmentV1 && cfg.enableChecksumValidation {\n\t\tfile.Seek(0, io.SeekStart)\n\t\theaderSize := int64(segmentindex.HeaderSize)\n\t\tif header.Strategy == segmentindex.StrategyInverted {\n\t\t\theaderSize += int64(segmentindex.HeaderInvertedSize)\n\t\t}\n\t\tsegmentFile := segmentindex.NewSegmentFile(segmentindex.WithReader(file))\n\t\tif err := segmentFile.ValidateChecksum(size, headerSize); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"validate segment %q: %w\", path, err)\n\t\t}\n\t}\n\n\tprimaryIndex, err := header.PrimaryIndex(contents)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"extract primary index position: %w\", err)\n\t}","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/adapters/repos/db/lsmkv/segment.go#L302-L338","documentation":"Thrown in newSegment (segment.go:320) when segmentindex.CheckExpectedStrategy rejects header.Strategy. The header parsed fine, but the segment's strategy identifier isn't one the bucket expects (replace/set/map/inverted), indicating the file is either corrupt or belongs to a bucket of a different strategy configuration.","triggerScenarios":"Loading a segment into a bucket whose expected strategy (from segmentConfig) doesn't match the strategy stamped in the segment header — e.g. a segment written as 'map' (BM25) opened where 'replace' is expected, a strategy byte corrupted after write, or a foreign/garbage file renamed to look like a segment.","commonSituations":"Pointing a bucket at a directory mixing segments from different bucket types (manual file moves between object and inverted-index buckets); storage corruption flipping the strategy field; restoring partial backups that mix segment files; hand-crafted test data with invalid strategy constants.","solutions":["Identify the segment's actual strategy (decode the header) and move it back to the bucket directory of the matching strategy/object store.","If the strategy byte is corrupted (bitrot), treat the segment as corrupt: drop the shard and restore from backup or rebuild from replicas.","Never manually relocate segment files between bucket directories; use Weaviate's backup/restore tooling.","Upgrade-in-place scenarios: confirm both source and target Weaviate versions use the same strategy identifiers.","Re-ingest the affected collection if no backup exists."],"exampleFix":"// before: inverted-index segment accidentally placed in the object bucket dir\nmv segment-3 /var/lib/weaviate/.../shard/lsm/objects/\n// after: keep each strategy's segments in their own bucket directories\nmv segment-3 /var/lib/weaviate/.../shard/lsm/inverted/\n","handlingStrategy":"type-guard","validationCode":"func segmentMatchesBucket(path string, expected segmentindex.Strategy) error {\n    f, err := os.Open(path)\n    if err != nil {\n        return err\n    }\n    defer f.Close()\n    buf := make([]byte, segmentindex.HeaderSize)\n    if _, err := io.ReadFull(f, buf); err != nil {\n        return err\n    }\n    h, err := segmentindex.ParseHeader(buf)\n    if err != nil {\n        return err\n    }\n    return segmentindex.CheckExpectedStrategy(h.Strategy)\n}","typeGuard":"func strategyIsKnown(s segmentindex.Strategy) bool {\n    switch s {\n    case segmentindex.StrategyReplace,\n        segmentindex.StrategySet,\n        segmentindex.StrategyMap,\n        segmentindex.StrategyInverted:\n        return true\n    default:\n        return false\n    }\n}","tryCatchPattern":"if err := segmentindex.CheckExpectedStrategy(header.Strategy); err != nil {\n    return nil, fmt.Errorf(\"segment %q strategy %v misplaced or corrupt: %w\", path, header.Strategy, err)\n}","preventionTips":["Never move segment files between bucket directories (objects vs inverted index); each bucket dir belongs to one strategy.","Restore shards only through Weaviate's backup module, not manual file copying.","Validate the whole shard directory (header check per segment) after any manual recovery operation.","Keep all cluster nodes on the same Weaviate version so strategy identifiers match."],"tags":["go","lsmkv","corruption","segment","validation"],"backgroundTag":"unsupported-segment-strategy","analyzedSha":"75aa4b6d11f8818305aafd4440b4e32794f7ca04","analyzedAt":"2026-09-04T14:58:20.392Z","contentChangedAt":"2026-09-04T14:58:20.392Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}