From 97b68aab05722af2e8beeb5d53ef817b509634f9 Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Sun, 24 Sep 2023 13:36:29 -0500 Subject: [PATCH 1/4] fix: Sync staged files immediately after create --- object_store/src/local.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/object_store/src/local.rs b/object_store/src/local.rs index 20eb3c63ccbd..62f06b9c92a7 100644 --- a/object_store/src/local.rs +++ b/object_store/src/local.rs @@ -673,7 +673,11 @@ fn new_staged_upload(base: &std::path::Path) -> Result<(File, String)> { let path = staged_upload_path(base, &suffix); let mut options = OpenOptions::new(); match options.read(true).write(true).create_new(true).open(&path) { - Ok(f) => return Ok((f, suffix)), + Ok(f) => { + f.sync_all() + .map_err(|e| Error::UnableToOpenFile { source: e, path })?; + return Ok((f, suffix)); + } Err(source) => match source.kind() { ErrorKind::AlreadyExists => multipart_id += 1, ErrorKind::NotFound => create_parent_dirs(&path, source)?, From 38d081237bb06acd64e61c2ee485f3ac9b08a630 Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Sun, 24 Sep 2023 13:59:33 -0500 Subject: [PATCH 2/4] more sync --- object_store/src/local.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/object_store/src/local.rs b/object_store/src/local.rs index 62f06b9c92a7..e9e74f844d5a 100644 --- a/object_store/src/local.rs +++ b/object_store/src/local.rs @@ -278,6 +278,7 @@ impl ObjectStore for LocalFileSystem { file.write_all(&bytes) .context(UnableToCopyDataToFileSnafu) .and_then(|_| { + file.sync_all().unwrap(); std::fs::rename(&staging_path, &path).context(UnableToRenameFileSnafu) }) .map_err(|e| { From e3b240cec93f08b08526bd8d4f7d934c90cbf2cb Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Sun, 24 Sep 2023 14:26:34 -0500 Subject: [PATCH 3/4] try --- object_store/src/local.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/object_store/src/local.rs b/object_store/src/local.rs index e9e74f844d5a..b11c3b076b95 100644 --- a/object_store/src/local.rs +++ b/object_store/src/local.rs @@ -277,14 +277,14 @@ impl ObjectStore for LocalFileSystem { let staging_path = staged_upload_path(&path, &suffix); file.write_all(&bytes) .context(UnableToCopyDataToFileSnafu) - .and_then(|_| { - file.sync_all().unwrap(); - std::fs::rename(&staging_path, &path).context(UnableToRenameFileSnafu) - }) - .map_err(|e| { - let _ = std::fs::remove_file(&staging_path); // Attempt to cleanup - e.into() - }) + .unwrap(); + + file.sync_all().unwrap(); + std::fs::rename(&staging_path, &path) + .context(UnableToRenameFileSnafu) + .expect(&format!("path: {staging_path:?}")); + + Ok(()) }) .await } From f18a5b7f6b1f6f47abd6100640b90c0550d087ed Mon Sep 17 00:00:00 2001 From: Sean Smith Date: Sun, 24 Sep 2023 14:48:41 -0500 Subject: [PATCH 4/4] idk --- object_store/src/local.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/object_store/src/local.rs b/object_store/src/local.rs index b11c3b076b95..410d2676f55b 100644 --- a/object_store/src/local.rs +++ b/object_store/src/local.rs @@ -279,7 +279,8 @@ impl ObjectStore for LocalFileSystem { .context(UnableToCopyDataToFileSnafu) .unwrap(); - file.sync_all().unwrap(); + std::mem::drop(file); + std::fs::rename(&staging_path, &path) .context(UnableToRenameFileSnafu) .expect(&format!("path: {staging_path:?}"));