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

feat(core): Add is_current to metadata #5493

Merged
merged 4 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions core/src/services/oss/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,11 @@ impl Access for OssBackend {
let headers = resp.headers();
let mut meta = self.core.parse_metadata(path, resp.headers())?;

// If version id exists, set the version; otherwise, mark as the current version.
if let Some(v) = parse_header_to_str(headers, "x-oss-version-id")? {
meta.set_version(v);
} else {
meta.set_is_current(true);
Wenbin1002 marked this conversation as resolved.
Show resolved Hide resolved
}

Ok(RpStat::new(meta))
Expand Down
1 change: 1 addition & 0 deletions core/src/services/oss/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ impl oio::PageList for OssLister {
}

let mut meta = Metadata::new(EntryMode::from_path(&path));
meta.set_is_current(true);
meta.set_etag(&object.etag);
meta.set_content_md5(object.etag.trim_matches('"'));
meta.set_content_length(object.size);
Expand Down
3 changes: 3 additions & 0 deletions core/src/services/s3/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1016,8 +1016,11 @@ impl Access for S3Backend {
meta.with_user_metadata(user_meta);
}

// If version id exists, set the version; otherwise, mark as the current version.
Wenbin1002 marked this conversation as resolved.
Show resolved Hide resolved
if let Some(v) = parse_header_to_str(headers, "x-amz-version-id")? {
meta.set_version(v);
} else {
meta.set_is_current(true);
}

Ok(RpStat::new(meta))
Expand Down
3 changes: 2 additions & 1 deletion core/src/services/s3/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl oio::PageList for S3Lister {
}

let mut meta = Metadata::new(EntryMode::from_path(&path));

meta.set_is_current(true);
if let Some(etag) = &object.etag {
meta.set_etag(etag);
meta.set_content_md5(etag.trim_matches('"'));
Expand Down Expand Up @@ -239,6 +239,7 @@ impl oio::PageList for S3ObjectVersionsLister {

let mut meta = Metadata::new(EntryMode::from_path(&path));
meta.set_version(&version_object.version_id);
meta.set_is_current(version_object.is_latest);
meta.set_content_length(version_object.size);
meta.set_last_modified(parse_datetime_from_rfc3339(
version_object.last_modified.as_str(),
Expand Down
23 changes: 23 additions & 0 deletions core/src/types/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct Metadata {
etag: Option<String>,
last_modified: Option<DateTime<Utc>>,
version: Option<String>,
is_current: Option<bool>,

user_metadata: Option<HashMap<String, String>>,
}
Expand All @@ -64,6 +65,7 @@ impl Metadata {
content_disposition: None,
version: None,
user_metadata: None,
is_current: None,
}
}

Expand Down Expand Up @@ -404,6 +406,27 @@ impl Metadata {
self
}

/// Is_current of this entry.
///
/// Is_current is a boolean that can be used to identify
/// if the version of this entry is the latest version.
Wenbin1002 marked this conversation as resolved.
Show resolved Hide resolved
pub fn is_current(&self) -> Option<bool> {
self.is_current
}

/// Set is_current of this entry.
///
/// For HeadObject without version_id, we will set it to Some(true).
///
/// For HeadObject with version_id, we will set it to None.
///
/// For ListObjects, we will set all keys to Some(true)
///
/// For ListObjectVersions, we will decide the value based on IsLatest.
Wenbin1002 marked this conversation as resolved.
Show resolved Hide resolved
pub fn set_is_current(&mut self, is_current: bool) {
self.is_current = Some(is_current);
}

Wenbin1002 marked this conversation as resolved.
Show resolved Hide resolved
/// User defined metadata of this entry
///
/// The prefix of the user defined metadata key(for example: in oss, it's x-oss-meta-)
Expand Down
Loading