{"record":{"id":"5850a7311593538a","repo":"weaviate/weaviate","slug":"write-segment-file-indexes-w","errorCode":null,"errorMessage":"write segment file indexes: %w","messagePattern":"write segment file indexes: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"adapters/repos/db/lsmkv/segmentindex/segment_file.go","lineNumber":240,"sourceCode":"\n\treturn 0, nil\n}\n\n// WriteIndexes writes the indexes struct to the underlying writer.\n// This method uses the written data to further calculate the checksum.\nfunc (f *SegmentFile) WriteIndexes(indexes *Indexes) (int64, error) {\n\tif f.writer == nil {\n\t\treturn 0, fmt.Errorf(\" SegmentFile not initialized with a reader, \" +\n\t\t\t\"try adding one with segmentindex.WithBufferedWriter(*bufio.Writer)\")\n\t}\n\n\tif f.checksumsDisabled {\n\t\treturn indexes.WriteTo(f.writer)\n\t}\n\n\tn, err := indexes.WriteTo(f.checksumWriter)\n\tif err != nil {\n\t\treturn n, fmt.Errorf(\"write segment file indexes: %w\", err)\n\t}\n\tf.writtenTo = true\n\treturn n, nil\n}\n\n// WriteChecksum writes checksum itself to the segment file.\n// As mentioned elsewhere in SegmentFile, the header is added to the checksum last.\n// This method finally adds the header to the hash, and then writes the resulting\n// checksum to the segment file.\nfunc (f *SegmentFile) WriteChecksum() (int64, error) {\n\tif f.writer == nil {\n\t\treturn 0, fmt.Errorf(\" SegmentFile not initialized with a reader, \" +\n\t\t\t\"try adding one with segmentindex.WithBufferedWriter(*bufio.Writer)\")\n\t}\n\n\tvar n int\n\tvar err error\n","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/adapters/repos/db/lsmkv/segmentindex/segment_file.go#L222-L258","documentation":"SegmentFile.WriteIndexes serializes the segment's primary/secondary index structures (Indexes.WriteTo) through the checksumming writer. The error wraps any error returned by Indexes.WriteTo — either an underlying write I/O failure or an internal size-mismatch error raised inside writeDirectly.","triggerScenarios":"Calling sf.WriteIndexes(indexes) (via writeIndexes during flush or flushDataInverted during compaction) when the underlying writer errors (disk full, I/O) or when Indexes.WriteTo hits a primary/secondary index size mismatch due to inconsistent key state.","commonSituations":"Disk exhaustion during flush of a bucket with many keys; interrupted storage; inconsistent precomputed index sizes in a compactor path.","solutions":["Unwrap the cause: if it's a size mismatch, see the size-mismatch entry (key set mutated after size computation); if it's an I/O error, fix disk space/storage.","Check disk space on the segment's volume before large flushes.","Retry the flush/compaction; source data is still in the memtable or original segments.","Verify no writer is shared/concurrently used by two flush goroutines."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if diskFree(dir) < minRequiredBytes { return errors.New(\"insufficient disk space for index write\") }\nif !sizesConsistent(indexes) { return errors.New(\"precomputed index sizes inconsistent with key set\") }","typeGuard":"func indexesConsistent(idx *segmentindex.Indexes) bool {\n    return !idx.SizesPrecomputed || len(idx.PrecomputedSecondaryIndexSizes) == int(idx.SecondaryIndexCount)\n}","tryCatchPattern":"if _, err := sf.WriteIndexes(indexes); err != nil {\n    if strings.Contains(err.Error(), \"size mismatch\") {\n        return fmt.Errorf(\"index size inconsistency, recompute and retry: %w\", err)\n    }\n    return fmt.Errorf(\"index write I/O failure: %w\", err)\n}","preventionTips":["Ensure the key set is final before any size precomputation","Monitor free disk space on segment volumes","Never share one SegmentFile/buffered writer between goroutines"],"tags":["lsmkv","segmentindex","io","disk"],"backgroundTag":"disk-io-error","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"}