{"record":{"id":"ededea56cd9ea635","repo":"canopy-network/canopy","slug":"finalize-backup-w","errorCode":null,"errorMessage":"finalize backup: %w","messagePattern":"finalize backup: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"store/store.go","lineNumber":800,"sourceCode":"\t\t// perform the backup using pebble's checkpointing mechanism which creates a\n\t\t// consistent snapshot of the database at the specified directory\n\t\tif err = s.db.Checkpoint(tempBackupDir); err != nil {\n\t\t\terr = fmt.Errorf(\"checkpoint creation: %w\", err)\n\t\t\treturn\n\t\t}\n\t\t// write the current height to a separate file\n\t\theightFile := filepath.Join(tempBackupDir, \"height.txt\")\n\t\tif err = os.WriteFile(heightFile, fmt.Appendf(nil, \"%d\", version), 0644); err != nil {\n\t\t\terr = fmt.Errorf(\"write height file: %w\", err)\n\t\t\treturn\n\t\t}\n\t\tif err = os.Rename(backupDir, prevBackupDir); err != nil && !os.IsNotExist(err) {\n\t\t\terr = fmt.Errorf(\"rotate backup: %w\", err)\n\t\t\treturn\n\t\t}\n\t\t// promote: atomically move the temp backup into the active slot\n\t\tif err = os.Rename(tempBackupDir, backupDir); err != nil {\n\t\t\terr = fmt.Errorf(\"finalize backup: %w\", err)\n\t\t\treturn\n\t\t}\n\t\tbackupDuration := time.Since(start)\n\t\t// log results\n\t\ts.log.Infof(\"backup completed at height [%d] in %s\", version, backupDuration)\n\t\t// update metrics\n\t\ts.metrics.UpdateStoreJobMetrics(0, 0, backupDuration)\n\t}()\n}\n\n// Compact runs Pebble range compaction over the prefix range\nfunc (s *Store) Compact(version uint64, prefix []byte) lib.ErrorI {\n\t// compactions are not allowed to run concurrently to not intertwine with the keys\n\tif !s.compaction.CompareAndSwap(false, true) {\n\t\ts.log.Debugf(\"key compaction skipped [%d] [%s]: already in progress\", version, prefix)\n\t\treturn nil\n\t}\n\tdefer s.compaction.Store(false)","sourceCodeStart":782,"sourceCodeEnd":818,"githubUrl":"https://github.com/canopy-network/canopy/blob/ee8197d91dd410f6592cb650a94c925ee6dc8bad/store/store.go#L782-L818","documentation":"Wrapped failure (fmt.Errorf with %w) for the final phase of the backup rotation: renaming the freshly completed tempBackupDir into place as the active backupDir. The checkpoint, height file, and prior-backup rotation all succeeded, but the final swap failed, leaving the backup incomplete.","triggerScenarios":"Thrown at store/store.go:800 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the wrapped OS error for rename failures (permissions, target path busy/locked, cross-device).","Clean up leftover tempBackupDir before the next backup cycle to avoid conflicts.","Retry the backup; the prior backupDir should still be intact since the swap is the last step."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ee8197d91dd410f6592cb650a94c925ee6dc8bad","analyzedAt":"2026-09-06T09:30:15.973Z","contentChangedAt":"2026-09-06T09:30:15.973Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}