From ef49c4405864d3a1206fb2f681b02f906e7052cf Mon Sep 17 00:00:00 2001 From: "Zhanxiang (Patrick) Huang" Date: Mon, 26 Jun 2023 14:15:26 +0800 Subject: [PATCH] fix: fix missing parts ordering in s3 simulator (#149) * fix: fix missing parts ordering in s3 simulator * Update madsim-aws-sdk-s3/src/server/service.rs Co-authored-by: Noel Kwan <47273164+kwannoel@users.noreply.github.com> * fmt --------- Co-authored-by: Noel Kwan <47273164+kwannoel@users.noreply.github.com> --- CHANGELOG.md | 6 ++++ madsim-aws-sdk-s3/Cargo.toml | 2 +- madsim-aws-sdk-s3/src/server/service.rs | 41 +++++-------------------- 3 files changed, 15 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b11ede..414acfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.2.24] - 2023-06-26 + +### Fixed + +- s3: Fix missing parts ordering. + ## [0.2.23] - 2023-05-22 ### Added diff --git a/madsim-aws-sdk-s3/Cargo.toml b/madsim-aws-sdk-s3/Cargo.toml index e6e6a0e..a532828 100644 --- a/madsim-aws-sdk-s3/Cargo.toml +++ b/madsim-aws-sdk-s3/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "madsim-aws-sdk-s3" -version = "0.2.23+0.28" +version = "0.2.24+0.28" edition = "2021" authors = ["Kevin Axel "] description = "The s3 simulator on madsim." diff --git a/madsim-aws-sdk-s3/src/server/service.rs b/madsim-aws-sdk-s3/src/server/service.rs index f9f8518..5180ce4 100644 --- a/madsim-aws-sdk-s3/src/server/service.rs +++ b/madsim-aws-sdk-s3/src/server/service.rs @@ -4,7 +4,7 @@ use madsim::rand::{thread_rng, Rng}; use spin::Mutex; use tracing::debug; -use std::collections::{btree_map::Entry::*, BTreeMap, VecDeque}; +use std::collections::{btree_map::Entry::*, BTreeMap}; use crate::operation::abort_multipart_upload::*; use crate::operation::complete_multipart_upload::*; @@ -315,58 +315,33 @@ impl ServiceInner { let parts = object .parts - .get_mut(&upload_id) + .remove(&upload_id) .ok_or_else(|| CompleteMultipartUploadError::unhandled(no_such_upload(&upload_id)))?; if let Some(mut multipart) = multipart.parts { + let mut body = vec![]; + multipart.sort_by_key(|part| part.part_number); - let mut selection_idx = vec![]; for completed_part in multipart { - for (idx, part) in parts.iter().enumerate() { + for part in parts.iter() { if part.part_number == completed_part.part_number { if let Some(e_tag) = &completed_part.e_tag { if e_tag == &part.e_tag { - selection_idx.push(idx); + body.extend(&part.body); break; } } else { - selection_idx.push(idx); + body.extend(&part.body); break; } } } } - selection_idx.sort(); - let mut selection_idx = VecDeque::from(selection_idx); - let mut body = vec![]; - let parts = object.parts.remove(&upload_id).unwrap(); - - for (idx, part) in parts.into_iter().enumerate() { - if let Some(next_idx) = selection_idx.front() { - if *next_idx != idx { - continue; - } else { - body.extend(part.body); - selection_idx.pop_front(); - } - } else { - break; - } - } - object.body = body.into(); object.completed = true; - object.parts.remove(&upload_id); - - Ok(CompleteMultipartUploadOutput::builder().build()) - } else { - object - .parts - .remove(&upload_id) - .expect("empty complete multipart request, remove upload_id failed"); - Ok(CompleteMultipartUploadOutput::builder().build()) } + Ok(CompleteMultipartUploadOutput::builder().build()) } fn abort_multipart_upload(