From 0f79efee2529eb74e01def0fe7a3a2b246806980 Mon Sep 17 00:00:00 2001 From: Bei Chu <914745487@qq.com> Date: Fri, 8 Sep 2023 14:28:11 +0800 Subject: [PATCH] fix: Don't call `Storage::delete_objects` with empty objects array (#2010) --- dozer-log/src/replication/persist.rs | 4 +++- dozer-log/src/storage/local.rs | 4 ++++ dozer-log/src/storage/mod.rs | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dozer-log/src/replication/persist.rs b/dozer-log/src/replication/persist.rs index 582bbc7a03..75b5b00d71 100644 --- a/dozer-log/src/replication/persist.rs +++ b/dozer-log/src/replication/persist.rs @@ -68,7 +68,9 @@ pub async fn load_persisted_log_entries( } // Remove extra entries. These are persisted in the middle of a checkpointing, but the checkpointing didn't finish. - storage.delete_objects(to_remove).await?; + if !to_remove.is_empty() { + storage.delete_objects(to_remove).await?; + } // Check invariants. if let Some(first) = result.first() { diff --git a/dozer-log/src/storage/local.rs b/dozer-log/src/storage/local.rs index 251361ee62..58f5a8391e 100644 --- a/dozer-log/src/storage/local.rs +++ b/dozer-log/src/storage/local.rs @@ -167,6 +167,10 @@ impl Storage for LocalStorage { } async fn delete_objects(&self, keys: Vec) -> Result<(), Error> { + if keys.is_empty() { + return Err(Error::EmptyDeleteObjectsRequest); + } + for key in keys { let path = self.get_path(&key).await?; tokio::fs::remove_file(&path) diff --git a/dozer-log/src/storage/mod.rs b/dozer-log/src/storage/mod.rs index dbe3ee3107..529a077615 100644 --- a/dozer-log/src/storage/mod.rs +++ b/dozer-log/src/storage/mod.rs @@ -111,6 +111,8 @@ pub enum Error { NonUtf8Path(PathBuf), #[error("upload not found: key {key}, upload id {upload_id}")] UploadNotFound { key: String, upload_id: String }, + #[error("empty delete objects request")] + EmptyDeleteObjectsRequest, } use dyn_clone::DynClone;