You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: 🚑 Handle multiple file records for same file_key (#593)
* fix: 🚑 `get_by_file_key` now returns a vector and there's a `get_latest_by_file_key`
* fix: 🚑 Propagate fix to backend functions
* fix: 🚑 ensure file operations in indexer are done by id instead of file key
* fix: 🔥 remove unused import
* fix: 🐛 update `delete_file` of backend tests with file id argument
---------
Co-authored-by: Tobi Demeco <[email protected]>
/// Delete file only if it has no BSP associations and is not in the bucket forest.
329
306
/// The flag [`is_in_bucket`](File::is_in_bucket) is set to false or true based on the [`MutationsApplied`] event emitted by the proofs dealer pallet for catch all.
307
+
/// Returns true if all files associated with the file key were deleted, false if any still has associations.
330
308
pubasyncfndelete_if_orphaned<'a>(
331
309
conn:&mutDbConnection<'a>,
332
310
file_key:implAsRef<[u8]>,
333
-
) -> Result<bool, diesel::result::Error>{
311
+
) -> Result<(), diesel::result::Error>{
334
312
let file_key = file_key.as_ref();
335
313
336
314
// Check if file is still in bucket forest or has BSP associations
337
-
letfile_record:Option<Self> = file::table
315
+
letfile_records:Vec<Self> = file::table
338
316
.filter(file::file_key.eq(file_key))
339
-
.first(conn)
340
-
.await
341
-
.optional()?;
342
-
343
-
letSome(file_record) = file_record else{
344
-
// File doesn't exist, nothing to delete
345
-
returnOk(false);
346
-
};
317
+
.load(conn)
318
+
.await?;
347
319
348
-
let has_bsp = Self::has_bsp_associations(conn, file_key).await?;
349
-
let is_in_bucket = file_record.is_in_bucket;
350
-
351
-
if !is_in_bucket && !has_bsp {
352
-
// File is not in bucket forest and has no BSP associations, safe to delete
Copy file name to clipboardExpand all lines: client/indexer-db/src/models/msp_file.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ impl MspFile {
53
53
// Log if we found multiple files with the same key
54
54
if file_ids.len() > 1{
55
55
log::warn!(
56
-
"Found {} files with the same file_key: {:?}. This is an inconsistent state. Will proceed to delete all associated file IDs with this key.",
56
+
"Found {} files with the same file_key: {:?}. This is expected only if there was more than one storage request for the same file key. Will proceed to delete all associated file IDs with this key.",
0 commit comments