weaviate/weaviate · error
prepend segments: pause compaction: %w
Error message
prepend segments: pause compaction: %w
What it means
pauseCompaction failed while preparing the segment group for prepending, so the operation aborts to avoid racing a compaction cycle that could replace the wrong segment when indices shift. The underlying error (typically context cancellation) is wrapped with 'prepend segments: pause compaction:'.
Source
Thrown at adapters/repos/db/lsmkv/segment_group_prepend.go:97
return fmt.Errorf("%w (bucket=%s)", ErrPrependWouldDesyncInMemoryRep, filepath.Base(sg.dir))
}
// Step 2: Discover source segments (.db files).
srcDBFiles, err := discoverDBFiles(srcDir)
if err != nil {
return fmt.Errorf("prepend segments: discover source segments: %w", err)
}
if len(srcDBFiles) == 0 {
return nil // no-op
}
// Pause compaction for the duration of the operation. Compaction's
// switchInMemory uses stored segment indices — a prepend that shifts
// indices while compaction is in flight would cause it to replace the
// wrong segment. Pausing ensures no compaction cycle starts (and waits
// for any in-progress cycle to finish) before we proceed.
if err := sg.pauseCompaction(ctx); err != nil {
return fmt.Errorf("prepend segments: pause compaction: %w", err)
}
defer func() {
// Best-effort resume — if this fails, the segment group's compaction
// stays paused, which is degraded but not data-losing.
_ = sg.resumeCompaction(ctx)
}()
// Step 3: Compute timestamp shift and copy files with crash-safe staging.
tgtDBFiles, err := discoverDBFiles(sg.dir)
if err != nil {
return fmt.Errorf("prepend segments: discover target segments: %w", err)
}
shift, err := computeTimestampShift(srcDBFiles, tgtDBFiles)
if err != nil {
return fmt.Errorf("prepend segments: compute timestamp shift: %w", err)
}
copiedDBPaths, err := copySegmentFiles(srcDir, sg.dir, srcDBFiles, shift)
if err != nil {View on GitHub (pinned to 75aa4b6d11)
Solutions
- Pass a context without a short deadline (context.Background() or a generous timeout) when calling PrependSegmentsFromBucket
- Retry the operation after the in-flight compaction completes
- Investigate why pauseCompaction failed (check logs for the wrapped cause) and ensure no shutdown is racing the restore
Example fix
// before err := sg.PrependSegmentsFromBucket(ctx, srcDir) // request ctx, cancels quickly // after err = sg.PrependSegmentsFromBucket(context.Background(), srcDir)
Defensive patterns
Strategy: retry
Validate before calling
// avoid passing short-lived request contexts cctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) defer cancel() err := sg.PrependSegmentsFromBucket(cctx, srcDir)
Try / catch
err := sg.PrependSegmentsFromBucket(ctx, srcDir)
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
return retryWithBackoff(ctx, func() error {
return sg.PrependSegmentsFromBucket(context.Background(), srcDir)
})
} Prevention
- Use context.Background() (or a long timeout) for maintenance operations like prepend
- Avoid running prepend during server shutdown when pauseCompaction may be interrupted
- Monitor compaction backlog so pauseCompaction doesn't wait excessively
When it happens
Trigger: The ctx passed to PrependSegmentsFromBucket is cancelled or times out while pauseCompaction waits for an in-progress compaction cycle to finish; the segment group's pause mechanism itself errors.
Common situations: Restore invoked with a request-scoped context that gets cancelled; long-running compaction on a large shard exceeding the caller's timeout; server shutdown mid-restore.
Related errors
- flush buffered: %w
- write compactorMap segment checksum: %w
- merge keys: %w
- close new segment file %q: %w
- replace compacted segments on disk: %w
AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04).
Data as JSON: /api/errors/a7afcd2b0d26d2f6.
Report an issue: GitHub.