Skip to content

Commit

Permalink
Added crc64nvme for s3
Browse files Browse the repository at this point in the history
  • Loading branch information
geetanshjuneja committed Jan 27, 2025
1 parent c6fe050 commit 7c528f2
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 0 deletions.
56 changes: 56 additions & 0 deletions core/Cargo.lock

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

2 changes: 2 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ services-s3 = [
"reqsign?/services-aws",
"reqsign?/reqwest_request",
"dep:crc32c",
"dep:crc64fast-nvme",
]
services-seafile = []
services-sftp = ["dep:openssh", "dep:openssh-sftp-client", "dep:bb8"]
Expand Down Expand Up @@ -352,6 +353,7 @@ compio = { version = "0.12.0", optional = true, features = [
] }
# for services-s3
crc32c = { version = "0.6.6", optional = true }
crc64fast-nvme = {version = "1.1.1", optional = true}
# for services-nebula-graph
rust-nebula = { version = "^0.0.2", optional = true, features = ["graph"] }
snowflaked = { version = "1", optional = true, features = ["sync"] }
Expand Down
1 change: 1 addition & 0 deletions core/src/services/s3/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ impl Builder for S3Builder {

let checksum_algorithm = match self.config.checksum_algorithm.as_deref() {
Some("crc32c") => Some(ChecksumAlgorithm::Crc32c),
Some("crc64nvme") => Some(ChecksumAlgorithm::Crc64nvme),
None => None,
v => {
return Err(Error::new(
Expand Down
1 change: 1 addition & 0 deletions core/src/services/s3/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ pub struct S3Config {
///
/// Available options:
/// - "crc32c"
/// - "crc64nvme"
pub checksum_algorithm: Option<String>,
/// Disable write with if match so that opendal will not send write request with if match headers.
///
Expand Down
11 changes: 11 additions & 0 deletions core/src/services/s3/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,12 @@ impl S3Core {
body.clone()
.for_each(|b| crc = crc32c::crc32c_append(crc, &b));
Some(BASE64_STANDARD.encode(crc.to_be_bytes()))
},
Some(ChecksumAlgorithm::Crc64nvme) => {
let mut c = crc64fast_nvme::Digest::new();
body.clone()
.for_each(|b| c.write(&b));
Some(BASE64_STANDARD.encode(c.sum64().to_be_bytes()))
}
}
}
Expand Down Expand Up @@ -938,6 +944,8 @@ pub struct CompleteMultipartUploadRequestPart {
pub etag: String,
#[serde(rename = "ChecksumCRC32C", skip_serializing_if = "Option::is_none")]
pub checksum_crc32c: Option<String>,
#[serde(rename = "ChecksumCRC64NVME", skip_serializing_if = "Option::is_none")]
pub checksum_crc64nvme: Option<String>,
}

/// Request of DeleteObjects.
Expand Down Expand Up @@ -1046,11 +1054,13 @@ pub struct ListObjectVersionsOutputDeleteMarker {

pub enum ChecksumAlgorithm {
Crc32c,
Crc64nvme,
}
impl ChecksumAlgorithm {
pub fn to_header_name(&self) -> HeaderName {
match self {
Self::Crc32c => HeaderName::from_static("x-amz-checksum-crc32c"),
Self::Crc64nvme => HeaderName::from_static("x-amz-checksum-crc64nvme"),
}
}
}
Expand All @@ -1061,6 +1071,7 @@ impl Display for ChecksumAlgorithm {
"{}",
match self {
Self::Crc32c => "CRC32C",
Self::Crc64nvme => "CRC64NVME",
}
)
}
Expand Down
7 changes: 7 additions & 0 deletions core/src/services/s3/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ impl oio::MultipartWrite for S3Writer {
part_number: p.part_number,
etag: p.etag.clone(),
checksum_crc32c: p.checksum.clone(),
..Default::default()
},
ChecksumAlgorithm::Crc64nvme => CompleteMultipartUploadRequestPart {
part_number: p.part_number,
etag: p.etag.clone(),
checksum_crc64nvme: p.checksum.clone(),
..Default::default()
},
},
})
Expand Down

0 comments on commit 7c528f2

Please sign in to comment.