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

Filter exact list prefix matches for azure gen2 accounts #3714

Merged
merged 2 commits into from
Feb 14, 2023
Merged
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
58 changes: 31 additions & 27 deletions object_store/src/azure/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl AzureClient {
.context(InvalidListResponseSnafu)?;
let token = response.next_marker.take();

Ok((response.try_into()?, token))
Ok((to_list_result(response, prefix)?, token))
}

/// Perform a list operation automatically handling pagination
Expand Down Expand Up @@ -419,33 +419,37 @@ struct ListResultInternal {
pub blobs: Blobs,
}

impl TryFrom<ListResultInternal> for ListResult {
type Error = crate::Error;

fn try_from(value: ListResultInternal) -> Result<Self> {
let common_prefixes = value
.blobs
.blob_prefix
.into_iter()
.map(|x| Ok(Path::parse(x.name)?))
.collect::<Result<_>>()?;

let objects = value
.blobs
.blobs
.into_iter()
.map(ObjectMeta::try_from)
// Note: workaround for gen2 accounts with hierarchical namespaces. These accounts also
// return path segments as "directories". When we cant directories, its always via
// the BlobPrefix mechanics.
.filter_map_ok(|obj| if obj.size > 0 { Some(obj) } else { None })
.collect::<Result<_>>()?;

Ok(Self {
common_prefixes,
objects,
fn to_list_result(value: ListResultInternal, prefix: Option<&str>) -> Result<ListResult> {
let prefix = prefix.map(Path::from).unwrap_or_else(Path::default);
let common_prefixes = value
.blobs
.blob_prefix
.into_iter()
.map(|x| Ok(Path::parse(x.name)?))
.collect::<Result<_>>()?;

let objects = value
.blobs
.blobs
.into_iter()
.map(ObjectMeta::try_from)
// Note: workaround for gen2 accounts with hierarchical namespaces. These accounts also
// return path segments as "directories" and include blobs in list requests with prefix,
// if the prefix mateches the blob. When we want directories, its always via
// the BlobPrefix mechanics, and during lists we state that prefixes are evaluated on path segement basis.
.filter_map_ok(|obj| {
if obj.size > 0 && obj.location.as_ref().len() > prefix.as_ref().len() {
Some(obj)
} else {
None
}
})
}
.collect::<Result<_>>()?;

Ok(ListResult {
common_prefixes,
objects,
})
}

/// Collection of blobs and potentially shared prefixes returned from list requests.
Expand Down