Skip to content

Commit

Permalink
fix: fix missing parts ordering in s3 simulator (#149)
Browse files Browse the repository at this point in the history
* fix: fix missing parts ordering in s3 simulator

* Update madsim-aws-sdk-s3/src/server/service.rs

Co-authored-by: Noel Kwan <[email protected]>

* fmt

---------

Co-authored-by: Noel Kwan <[email protected]>
  • Loading branch information
hzxa21 and kwannoel committed Jun 26, 2023
1 parent 6753d73 commit ef49c44
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion madsim-aws-sdk-s3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
description = "The s3 simulator on madsim."
Expand Down
41 changes: 8 additions & 33 deletions madsim-aws-sdk-s3/src/server/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ef49c44

Please sign in to comment.