{"record":{"id":"34fd9b66affc4f3f","repo":"benbjohnson/litestream","slug":"fetch-dst-level-info-w","errorCode":null,"errorMessage":"fetch dst level info: %w","messagePattern":"fetch dst level info: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"store.go","lineNumber":781,"sourceCode":"\t}\n\treturn enabledCount > 0\n}\n\n// CompactDB performs a compaction or snapshot for a given database on a single destination level.\n// This function will only proceed if a compaction has not occurred before the last compaction time.\nfunc (s *Store) CompactDB(ctx context.Context, db *DB, lvl *CompactionLevel) (*ltx.FileInfo, error) {\n\t// Skip if database is not yet initialized (page size unknown).\n\tif db.PageSize() == 0 {\n\t\treturn nil, &DBNotReadyError{Reason: \"page size not initialized\"}\n\t}\n\n\tdstLevel := lvl.Level\n\n\t// Ensure we are not re-compacting before the most recent compaction time.\n\tprevCompactionAt := lvl.PrevCompactionAt(time.Now())\n\tdstInfo, err := db.MaxLTXFileInfo(ctx, dstLevel)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"fetch dst level info: %w\", err)\n\t} else if dstInfo.CreatedAt.After(prevCompactionAt) {\n\t\treturn nil, ErrCompactionTooEarly\n\t}\n\n\t// Shortcut if this is a snapshot since we are not pulling from a previous level.\n\tif dstLevel == SnapshotLevel {\n\t\tpos, err := db.Pos()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"fetch db position: %w\", err)\n\t\t}\n\t\tif dstInfo.MaxTXID != 0 && dstInfo.MaxTXID >= pos.TXID {\n\t\t\treturn nil, ErrNoCompaction\n\t\t}\n\n\t\tinfo, err := db.Snapshot(ctx)\n\t\tif err != nil {\n\t\t\treturn info, err\n\t\t}","sourceCodeStart":763,"sourceCodeEnd":799,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/store.go#L763-L799","documentation":"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.","triggerScenarios":"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).","commonSituations":"S3/GCS/Azure credentials expired or bucket removed, network outage during compaction, misconfigured replica client, or storage provider throttling list operations.","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."],"exampleFix":"// before\nif err := monitorCompaction(); err != nil { log.Fatal(err) }\n// after\nif err := monitorCompaction(); err != nil {\n    if isStorageError(err) { // e.g. errors.Is(err, s3.ErrAccessDenied)\n        log.Printf(\"storage unavailable, will retry: %v\", err)\n    }\n    log.Fatal(err)\n}","handlingStrategy":"retry","validationCode":"// preflight: verify replica reachable before compaction\nitr, err := replicaClient.LTXFiles(ctx, dstLevel, 0, false)\nif err != nil {\n    return fmt.Errorf(\"replica unreachable: %w\", err)\n}\nitr.Close()","typeGuard":null,"tryCatchPattern":"_, err := store.CompactDB(ctx, db, level)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) || isStorageTransient(err) {\n        // monitor will retry next interval\n        return nil\n    }\n    return err\n}","preventionTips":["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"],"tags":["go","litestream","compaction","storage"],"backgroundTag":"http-request-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}