🐛 Remove a race condition on file export

Caused when file is deleted in the middle of an exportation. The
current export process is not transactional, and on file deletion
several queries can start return not-found exception because of
concurrent file deletion.

With the changes on this PR we allow query deleted files internally
on the exportation process and make it resilent to possible
concurrent deletion.
This commit is contained in:
Andrey Antukh
2025-11-03 19:55:37 +01:00
parent cd6865f54b
commit 8307b699bf
2 changed files with 7 additions and 8 deletions

View File

@@ -550,7 +550,7 @@
[cfg data file-id]
(let [library-ids (get-libraries cfg [file-id])]
(reduce (fn [data library-id]
(if-let [library (get-file cfg library-id)]
(if-let [library (get-file cfg library-id :include-deleted? true)]
(ctf/absorb-assets data (:data library))
data))
data

View File

@@ -228,6 +228,7 @@
(db/tx-run! cfg (fn [cfg]
(cond-> (bfc/get-file cfg file-id
{:realize? true
:include-deleted? true
:lock-for-update? true})
detach?
(-> (ctf/detach-external-references file-id)
@@ -285,14 +286,12 @@
(let [file (cond-> (select-keys file bfc/file-attrs)
(:options data)
(assoc :options (:options data))
(assoc :options (:options data)))
:always
(dissoc :data))
file (cond-> file
:always
(encode-file))
file (-> file
(dissoc :data)
(dissoc :deleted-at)
(encode-file))
path (str "files/" file-id ".json")]
(write-entry! output path file))