fix(archive): recover from P2002 race on cloud create in walk (BIT-33532) #323

Merged
spark merged 1 commits from fix/BIT-33532-cloudfile-p2002-race into main 2026-12-04 10:02:58 +00:00
1 Commits
Author SHA1 Message Date
paula-alves 5287afb508 fix(archive): recover from P2002 race on cloud create in walk (BIT-33532)
ci / typescript (push) Skipped
ci / rust (push) Skipped
ci / rust (pull_request) Successful in 5m10s
ci / typescript (pull_request) Successful in 11m12s
ArchiveService.walk used a check-then-create pattern for cloudFolder,
cloudFile and cloudVideo. When two concurrent passes (overlapping scans
or a folder reachable through two paths) both query existing rows before
either creates, the second create hits P2002 on @@unique([sourceId,
fileId]) and aborts the whole scan, marking the source ERROR.

Wrap each create in try/catch for P2002 and fall back to an update on the
sourceId_fileId compound key, so a race no longer fails the scan.

Adds vitest cases proving the cloudFile fallback updates the compound key
and requeues, and that non-P2002 errors still rethrow.

Paperclip-Issue: BIT-33532
2026-12-04 09:43:33 +00:00