Mola-maker commented on code in PR #9059:
URL: https://github.com/apache/opendal/pull/9059#discussion_r4696739714


##########
integrations/object_store/src/store.rs:
##########
@@ -1261,37 +1310,83 @@ impl MultipartUpload for OpendalMultipartUpload {
     fn put_part(&mut self, data: PutPayload) -> UploadPart {
         let writer = self.writer.clone();
         let location = self.location.clone();
-
-        // Generate next notify which will be notified only after the current
-        // part is written successfully.
-        let (tx, rx) = oneshot::channel();
-        // Fetch the notify for current part to wait for it to be written.
-        let last_rx = std::mem::replace(&mut self.next_notify, rx);
-        let mut guard = PutPartGuard::register(self.state.clone(), tx);
+        let state = self.state.clone();
+        let (mut guard, outcome) = match 
PutPartGuard::register(self.state.clone(), data) {
+            Ok(registered) => registered,
+            // The upload already failed: there is no part to drive, so the
+            // returned future reports the rejection at once.
+            Err(err) => return async move { Err::<(), _>(err) 
}.into_send().boxed(),
+        };
 
         async move {
-            // Wait for the previous part to be written. A predecessor that
-            // failed or was dropped disconnects the channel.
-            if last_rx.await.is_err() {
-                return Err(format_multipart_error(
-                    &location,
-                    "previous multipart part failed or was cancelled",
-                ));
+            // Return this part's recorded outcome before the poison check:
+            // a part whose own write failed must report its original error,
+            // not the generic poison error.
+            if let Some(outcome) = outcome.lock().unwrap().take() {
+                if outcome.is_ok() {
+                    guard.succeed();
+                }
+                return outcome;
             }
+
             guard.ensure_active(&location)?;

Review Comment:
   Fixed in 2f55d41, following your suggestion. Each part gets a monotonic ID, 
and completed outcomes live in `MultipartUploadState.outcomes` next to 
`failed`. `MultipartUploadState::take_outcome(id)` runs under the state lock 
and checks `outcomes.remove(&id)` before `failed`. A part future uses it before 
`writer.lock().await`, again after taking the writer lock, and once more after 
the drain. A failed write records its error and calls `poison()` under the same 
lock acquisition, and `poison()` now only sets `failed` and clears `queued`. So 
`failed` is never observed before a written part's outcome is visible.
   
   `test_multipart_poison_keeps_recorded_outcomes` covers part 2 writing part 
1, failing its own write and poisoning the upload before part 1 is polled: part 
1 still returns `Ok(())` and part 2 keeps the injected error. The race itself 
has no `.await` in its window, so the test does not reproduce it. The structure 
closes it. Integration crate on Windows: 67 lib tests pass (the remaining 
failure, `test_directories_return_not_found_on_head_and_get`, also fails on 
main on Windows), plus 7 backends and 5 behavior tests. All 10 multipart tests 
pass.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to