Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix missing parts ordering in s3 simulator #149

Merged
merged 5 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading