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

Add source uri to headers for COPY request #1228

Merged
merged 7 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
23 changes: 20 additions & 3 deletions mountpoint-s3-client/src/s3_crt_client/copy_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use std::os::unix::prelude::OsStrExt;
use mountpoint_s3_crt::{http::request_response::Header, s3::client::MetaRequestResult};

use crate::object_client::{CopyObjectError, CopyObjectParams, CopyObjectResult, ObjectClientResult};
use crate::s3_crt_client::{S3CrtClient, S3Operation, S3RequestError};
use crate::s3_crt_client::{S3CrtClient, S3CrtClientInner, S3Operation, S3RequestError};
use tracing::trace;
passaro marked this conversation as resolved.
Show resolved Hide resolved

impl S3CrtClient {
/// Create and begin a new CopyObject request.
Expand Down Expand Up @@ -40,8 +41,24 @@ impl S3CrtClient {
destination_key
);

self.inner
.make_simple_http_request(message, S3Operation::CopyObject, span, parse_copy_object_error)?
let mut options = S3CrtClientInner::new_meta_request_options(message, S3Operation::CopyObject);
let uri = self
.inner
.endpoint_config
.resolve_for_bucket(source_bucket)
.map_err(S3RequestError::construction_failure)?
.uri()
.map_err(S3RequestError::construction_failure)?;
let source_uri = format!("{}/{source_key}", uri.as_os_str().to_string_lossy());
trace!(source_uri, "resolved source uri");
options.copy_source_uri(source_uri);
self.inner.make_simple_http_request_from_options(
options,
span,
|_| {},
parse_copy_object_error,
|_, _| (),
)?
};

let _body = request.await?;
Expand Down
15 changes: 15 additions & 0 deletions mountpoint-s3-crt/src/s3/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ struct MetaRequestOptionsInner<'a> {
/// Owned checksum config, if provided.
checksum_config: Option<ChecksumConfig>,

/// Owned source uri for copy request, if provided.
copy_source_uri: Option<String>,

/// Telemetry callback, if provided
on_telemetry: Option<TelemetryCallback>,

Expand Down Expand Up @@ -326,6 +329,7 @@ impl<'a> MetaRequestOptions<'a> {
on_upload_review: None,
on_finish: None,
_pinned: Default::default(),
copy_source_uri: None,
passaro marked this conversation as resolved.
Show resolved Hide resolved
});

// Pin the options in-place. This is because it's about to become self-referential.
Expand Down Expand Up @@ -462,6 +466,17 @@ impl<'a> MetaRequestOptions<'a> {
options.inner.send_using_async_writes = send_using_async_writes;
self
}

/// Set the URI of source bucket/key for COPY request only
pub fn copy_source_uri(&mut self, source_uri: String) -> &mut Self {
// SAFETY: we aren't moving out of the struct.
let options = unsafe { Pin::get_unchecked_mut(Pin::as_mut(&mut self.0)) };
options.copy_source_uri = Some(source_uri);
// SAFETY: We ensure that the cursor points to data that lives
// as long as the options struct
options.inner.copy_source_uri = unsafe { options.copy_source_uri.as_mut().unwrap().as_aws_byte_cursor() };
self
}
}

impl Default for MetaRequestOptions<'_> {
Expand Down
Loading