You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tustvold (via GitHub)" <gi...@apache.org> on 2023/03/01 13:04:53 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #3781: Make LocalFileSystem::put atomic (#3780)

tustvold opened a new pull request, #3781:
URL: https://github.com/apache/arrow-rs/pull/3781

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #3780
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] alamb commented on a diff in pull request #3781: Make LocalFileSystem::put atomic (#3780)

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #3781:
URL: https://github.com/apache/arrow-rs/pull/3781#discussion_r1123243987


##########
object_store/src/lib.rs:
##########
@@ -840,6 +840,12 @@ mod tests {
             crate::Error::NotFound { .. }
         ));
 
+        let files = flatten_list_stream(storage, None).await.unwrap();

Review Comment:
   I didn't see a test for atomic `puts` (this appears to be testing atomic `put_multipart`). 
   
   Maybe I am misreading the code, but I think there should be a separate test to ensure we don't accidentally break `put` in the future (and that the other implementations are also atomic)



##########
object_store/src/local.rs:
##########
@@ -282,28 +290,10 @@ impl ObjectStore for LocalFileSystem {
     ) -> Result<(MultipartId, Box<dyn AsyncWrite + Unpin + Send>)> {
         let dest = self.config.path_to_filesystem(location)?;
 
-        // Generate an id in case of concurrent writes
-        let mut multipart_id = 1;
-
-        // Will write to a temporary path
-        let staging_path = loop {
-            let staging_path = get_upload_stage_path(&dest, &multipart_id.to_string());
-
-            match std::fs::metadata(&staging_path) {

Review Comment:
   TIL: https://en.wikipedia.org/wiki/Time-of-check_to_time-of-use



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3781: Make LocalFileSystem::put atomic (#3780)

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #3781:
URL: https://github.com/apache/arrow-rs/pull/3781#discussion_r1121699011


##########
object_store/src/local.rs:
##########
@@ -553,9 +543,40 @@ impl ObjectStore for LocalFileSystem {
     }
 }
 
-fn get_upload_stage_path(dest: &std::path::Path, multipart_id: &MultipartId) -> PathBuf {
+/// Generates a unique file path `{base}#{suffix}`, returning the opened `File` and `suffix`
+///
+/// Creates any directories if necessary
+fn new_staged_upload(base: &PathBuf) -> Result<(File, String)> {

Review Comment:
   This combines the logic of `open_writeable_file` and `get_upload_stage_path`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] alamb commented on a diff in pull request #3781: Make LocalFileSystem::put atomic (#3780)

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #3781:
URL: https://github.com/apache/arrow-rs/pull/3781#discussion_r1123420846


##########
object_store/src/lib.rs:
##########
@@ -840,6 +840,12 @@ mod tests {
             crate::Error::NotFound { .. }
         ));
 
+        let files = flatten_list_stream(storage, None).await.unwrap();

Review Comment:
   Ah, well then I agree testing this is likely going to be hard and intrusive 👍 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] crepererum commented on pull request #3781: Make LocalFileSystem::put atomic (#3780)

Posted by "crepererum (via GitHub)" <gi...@apache.org>.
crepererum commented on PR #3781:
URL: https://github.com/apache/arrow-rs/pull/3781#issuecomment-1450536382

   I'm also wondering if we could be slightly smarter on Linux: instead of creating an ordinary file that will never get pruned if the write fails half-way, we could create an unlinked file (`open(2)` w/ `O_TMPFILE`) and link it once the write is done.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3781: Make LocalFileSystem::put atomic (#3780)

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #3781:
URL: https://github.com/apache/arrow-rs/pull/3781#discussion_r1121699814


##########
object_store/src/local.rs:
##########
@@ -282,28 +290,10 @@ impl ObjectStore for LocalFileSystem {
     ) -> Result<(MultipartId, Box<dyn AsyncWrite + Unpin + Send>)> {
         let dest = self.config.path_to_filesystem(location)?;
 
-        // Generate an id in case of concurrent writes
-        let mut multipart_id = 1;
-
-        // Will write to a temporary path
-        let staging_path = loop {
-            let staging_path = get_upload_stage_path(&dest, &multipart_id.to_string());
-
-            match std::fs::metadata(&staging_path) {

Review Comment:
   This has a TOCTOU thread race, which is fixed by using create_new instead



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] alamb commented on a diff in pull request #3781: Make LocalFileSystem::put atomic (#3780)

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #3781:
URL: https://github.com/apache/arrow-rs/pull/3781#discussion_r1123335527


##########
object_store/src/lib.rs:
##########
@@ -840,6 +840,12 @@ mod tests {
             crate::Error::NotFound { .. }
         ));
 
+        let files = flatten_list_stream(storage, None).await.unwrap();

Review Comment:
   Maybe a stream where you can send one `bytes`, verify the file doesn't appear, and then close the stream?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] ursabot commented on pull request #3781: Make LocalFileSystem::put atomic (#3780)

Posted by "ursabot (via GitHub)" <gi...@apache.org>.
ursabot commented on PR #3781:
URL: https://github.com/apache/arrow-rs/pull/3781#issuecomment-1452212385

   Benchmark runs are scheduled for baseline = 231ae9b31769b62da368b9f1eb355a840540cb06 and contender = 4f6729673b9c97e3daa8983ef52c51033b72a741. 4f6729673b9c97e3daa8983ef52c51033b72a741 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/a3bd2e5667644805aeb3b02dcc7b6faa...58462edbfc0a4250b79022efceccd8c9/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/5c75a4126a604df18f1a954fe5f18917...5450b925fc6241aead8fa14c22453f74/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/889edfb66f894432af6da6bd49397e1d...aa613f6034c9499fab456e4602100332/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/9056d2bb8cf74b84abb9ef207b41eba3...864942903cb043bd87153ab7870754fc/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold merged pull request #3781: Make LocalFileSystem::put atomic (#3780)

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold merged PR #3781:
URL: https://github.com/apache/arrow-rs/pull/3781


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3781: Make LocalFileSystem::put atomic (#3780)

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #3781:
URL: https://github.com/apache/arrow-rs/pull/3781#discussion_r1121698563


##########
object_store/src/local.rs:
##########
@@ -266,11 +271,14 @@ impl ObjectStore for LocalFileSystem {
         let path = self.config.path_to_filesystem(location)?;
 
         maybe_spawn_blocking(move || {
-            let mut file = open_writable_file(&path)?;
+            let (mut file, suffix) = new_staged_upload(&path)?;

Review Comment:
   This is the fix for #3780, we write to a temporary staging path that is ignored by listing operations and is not a legal Path



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on pull request #3781: Make LocalFileSystem::put atomic (#3780)

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on PR #3781:
URL: https://github.com/apache/arrow-rs/pull/3781#issuecomment-1450556001

   > Could you add a test validating that the temporary files aren't listed and that listing while temporary files are present doesn't error?
   
   There already is such a test - https://github.com/apache/arrow-rs/blob/master/object_store/src/lib.rs#L836
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3781: Make LocalFileSystem::put atomic (#3780)

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #3781:
URL: https://github.com/apache/arrow-rs/pull/3781#discussion_r1123400363


##########
object_store/src/lib.rs:
##########
@@ -840,6 +840,12 @@ mod tests {
             crate::Error::NotFound { .. }
         ));
 
+        let files = flatten_list_stream(storage, None).await.unwrap();

Review Comment:
   `put` doesn't take a stream, it only takes a `Bytes`...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3781: Make LocalFileSystem::put atomic (#3780)

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #3781:
URL: https://github.com/apache/arrow-rs/pull/3781#discussion_r1123328650


##########
object_store/src/lib.rs:
##########
@@ -840,6 +840,12 @@ mod tests {
             crate::Error::NotFound { .. }
         ));
 
+        let files = flatten_list_stream(storage, None).await.unwrap();

Review Comment:
   I wasn't really sure how to reliably test this as it depends on the latency of the write... I'll have a think



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org