benbjohnson/litestream · error
fetch dst level info: %w
Error message
fetch dst level info: %w
What it means
Store.CompactDB failed while fetching metadata about the newest LTX file at the destination compaction level via db.MaxLTXFileInfo(ctx, dstLevel). This call lists LTX files at that level on the replica (using a cache when available), so failures are typically storage-listing errors, not compaction logic errors. The wrapped error is returned with %w.
Source
Thrown at store.go:781
}
return enabledCount > 0
}
// CompactDB performs a compaction or snapshot for a given database on a single destination level.
// This function will only proceed if a compaction has not occurred before the last compaction time.
func (s *Store) CompactDB(ctx context.Context, db *DB, lvl *CompactionLevel) (*ltx.FileInfo, error) {
// Skip if database is not yet initialized (page size unknown).
if db.PageSize() == 0 {
return nil, &DBNotReadyError{Reason: "page size not initialized"}
}
dstLevel := lvl.Level
// Ensure we are not re-compacting before the most recent compaction time.
prevCompactionAt := lvl.PrevCompactionAt(time.Now())
dstInfo, err := db.MaxLTXFileInfo(ctx, dstLevel)
if err != nil {
return nil, fmt.Errorf("fetch dst level info: %w", err)
} else if dstInfo.CreatedAt.After(prevCompactionAt) {
return nil, ErrCompactionTooEarly
}
// Shortcut if this is a snapshot since we are not pulling from a previous level.
if dstLevel == SnapshotLevel {
pos, err := db.Pos()
if err != nil {
return nil, fmt.Errorf("fetch db position: %w", err)
}
if dstInfo.MaxTXID != 0 && dstInfo.MaxTXID >= pos.TXID {
return nil, ErrNoCompaction
}
info, err := db.Snapshot(ctx)
if err != nil {
return info, err
}View on GitHub (pinned to 4ed7a308f6)
Solutions
- Verify replica storage credentials and bucket/container existence for the replica client in your config.
- Test connectivity to the storage backend; retry CompactDB after transient network errors.
- Check the wrapped error from Client.LTXFiles (e.g. NoSuchBucket, AccessDenied) and fix the underlying storage config.
- If the replica was migrated, ensure the new location contains the expected LTX level structure.
Example fix
// before
if err := monitorCompaction(); err != nil { log.Fatal(err) }
// after
if err := monitorCompaction(); err != nil {
if isStorageError(err) { // e.g. errors.Is(err, s3.ErrAccessDenied)
log.Printf("storage unavailable, will retry: %v", err)
}
log.Fatal(err)
} Defensive patterns
Strategy: retry
Validate before calling
// preflight: verify replica reachable before compaction
itr, err := replicaClient.LTXFiles(ctx, dstLevel, 0, false)
if err != nil {
return fmt.Errorf("replica unreachable: %w", err)
}
itr.Close() Try / catch
_, err := store.CompactDB(ctx, db, level)
if err != nil {
if errors.Is(err, context.DeadlineExceeded) || isStorageTransient(err) {
// monitor will retry next interval
return nil
}
return err
} Prevention
- Rotate storage credentials before expiry
- Add storage health checks before compaction windows
- Set generous timeouts for object-storage list operations
- Alert on repeated compaction failures from the monitor
When it happens
Trigger: CompactDB(ctx, db, dstLevel) where MaxLTXFileInfo cannot list LTX files at dstLevel on the replica: storage backend errors, network failure, or cache miss followed by a failed remote listing (Replica.MaxLTXFileInfo -> Client.LTXFiles).
Common situations: S3/GCS/Azure credentials expired or bucket removed, network outage during compaction, misconfigured replica client, or storage provider throttling list operations.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- fetch src level info: %w
- fetch db position: %w
- enforce snapshot retention: %w
- enforce L%d retention: %w
- validate level %d for %s: %w
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/34fd9b66affc4f3f.
Report an issue: GitHub.