weaviate/weaviate · error

write segment file indexes: %w

Error message

write segment file indexes: %w

What it means

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.

Source

Thrown at adapters/repos/db/lsmkv/segmentindex/segment_file.go:240

	return 0, nil
}

// WriteIndexes writes the indexes struct to the underlying writer.
// This method uses the written data to further calculate the checksum.
func (f *SegmentFile) WriteIndexes(indexes *Indexes) (int64, error) {
	if f.writer == nil {
		return 0, fmt.Errorf(" SegmentFile not initialized with a reader, " +
			"try adding one with segmentindex.WithBufferedWriter(*bufio.Writer)")
	}

	if f.checksumsDisabled {
		return indexes.WriteTo(f.writer)
	}

	n, err := indexes.WriteTo(f.checksumWriter)
	if err != nil {
		return n, fmt.Errorf("write segment file indexes: %w", err)
	}
	f.writtenTo = true
	return n, nil
}

// WriteChecksum writes checksum itself to the segment file.
// As mentioned elsewhere in SegmentFile, the header is added to the checksum last.
// This method finally adds the header to the hash, and then writes the resulting
// checksum to the segment file.
func (f *SegmentFile) WriteChecksum() (int64, error) {
	if f.writer == nil {
		return 0, fmt.Errorf(" SegmentFile not initialized with a reader, " +
			"try adding one with segmentindex.WithBufferedWriter(*bufio.Writer)")
	}

	var n int
	var err error

View on GitHub (pinned to 75aa4b6d11)

Solutions

  1. 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.
  2. Check disk space on the segment's volume before large flushes.
  3. Retry the flush/compaction; source data is still in the memtable or original segments.
  4. Verify no writer is shared/concurrently used by two flush goroutines.
Defensive patterns

Strategy: try-catch

Validate before calling

if diskFree(dir) < minRequiredBytes { return errors.New("insufficient disk space for index write") }
if !sizesConsistent(indexes) { return errors.New("precomputed index sizes inconsistent with key set") }

Type guard

func indexesConsistent(idx *segmentindex.Indexes) bool {
    return !idx.SizesPrecomputed || len(idx.PrecomputedSecondaryIndexSizes) == int(idx.SecondaryIndexCount)
}

Try / catch

if _, err := sf.WriteIndexes(indexes); err != nil {
    if strings.Contains(err.Error(), "size mismatch") {
        return fmt.Errorf("index size inconsistency, recompute and retry: %w", err)
    }
    return fmt.Errorf("index write I/O failure: %w", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: Disk exhaustion during flush of a bucket with many keys; interrupted storage; inconsistent precomputed index sizes in a compactor path.

Related errors


AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04). Data as JSON: /api/errors/5850a7311593538a. Report an issue: GitHub.