Skip to content

Switch to one single runtime for S3 storage #909

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

Merged
merged 2 commits into from
Jul 25, 2020
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ path-slash = "0.1.3"
once_cell = { version = "1.4.0", features = ["parking_lot"] }
base64 = "0.12.1"
strum = { version = "0.18.0", features = ["derive"] }
parking_lot = "0.10.2"

# Data serialization and deserialization
serde = { version = "1.0", features = ["derive"] }
Expand Down
13 changes: 7 additions & 6 deletions src/storage/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use failure::Error;
use futures::stream::{FuturesUnordered, Stream};
use futures::Future;
use log::{error, warn};
use once_cell::sync::Lazy;
use parking_lot::Mutex;
use rusoto_core::region::Region;
use rusoto_credential::DefaultCredentialsProvider;
use rusoto_s3::{GetObjectRequest, PutObjectRequest, S3Client, S3};
Expand All @@ -16,6 +18,8 @@ mod test;
pub(crate) use test::TestS3;

pub(crate) static S3_BUCKET_NAME: &str = "rust-docs-rs";
static S3_RUNTIME: Lazy<Mutex<Runtime>> =
Lazy::new(|| Mutex::new(Runtime::new().expect("Failed to create S3 runtime")));

pub(crate) struct S3Backend {
client: S3Client,
Expand Down Expand Up @@ -63,16 +67,12 @@ impl S3Backend {
}

pub(super) fn start_storage_transaction(&self) -> Result<S3StorageTransaction, Error> {
Ok(S3StorageTransaction {
s3: self,
runtime: Runtime::new()?,
})
Ok(S3StorageTransaction { s3: self })
}
}

pub(super) struct S3StorageTransaction<'a> {
s3: &'a S3Backend,
runtime: Runtime,
}

impl<'a> StorageTransaction for S3StorageTransaction<'a> {
Expand Down Expand Up @@ -100,7 +100,7 @@ impl<'a> StorageTransaction for S3StorageTransaction<'a> {
}
attempts += 1;

match self.runtime.block_on(futures.map(drop).collect()) {
match S3_RUNTIME.lock().block_on(futures.map(drop).collect()) {
// this batch was successful, start another batch if there are still more files
Ok(_) => break,
Err(err) => {
Expand All @@ -112,6 +112,7 @@ impl<'a> StorageTransaction for S3StorageTransaction<'a> {
}
}
}

Ok(())
}

Expand Down