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

return unsupported for read/stat/delete with version when versioning is not enabled #5145

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 22 additions & 1 deletion core/src/services/s3/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,13 @@ impl Access for S3Backend {
}

async fn stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
if args.version().is_some() && !self.core.enable_versioning {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this PR suggests that we consider introducing a layer to handle unsupported behaviors. Not all users and use cases are concerned about whether services support versioning; they might simply want to write code consistently and return it as is if not supported.


We have similar code here:

fn new_unsupported_error(&self, op: impl Into<&'static str>) -> Error {
let scheme = self.meta.scheme();
let op = op.into();
Error::new(
ErrorKind::Unsupported,
format!("service {scheme} doesn't support operation {op}"),
)
.with_operation(op)
}

I think we can create a new layer called CapabilityCheckLayer. By default, opendal will not perform any capability checks. Users can enable CapabilityCheckLayer to ensure the features they use are supported and behave as expected.

CapabilityCheckLayer may have different modes:

  • Default: just bypass all checks, like the opendal default behavior.
  • Correctness: only check capability that affected correctness, for example, write with if none match, read with version.
  • All: check all capabilities.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Let me think about how to implement them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shall we remove the check in list before implementing this CapabilityCheckLayer ?

return Err(Error::new(
ErrorKind::Unsupported,
"the bucket doesn't enable versioning, cannot stat with version",
));
}

let resp = self.core.s3_head_object(path, args).await?;

let status = resp.status();
Expand Down Expand Up @@ -994,6 +1001,13 @@ impl Access for S3Backend {
}

async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, Self::Reader)> {
if args.version().is_some() && !self.core.enable_versioning {
return Err(Error::new(
ErrorKind::Unsupported,
"the bucket doesn't enable versioning, cannot read with version",
));
}

let resp = self.core.s3_get_object(path, args.range(), &args).await?;

let status = resp.status();
Expand Down Expand Up @@ -1025,6 +1039,13 @@ impl Access for S3Backend {
return Ok(RpDelete::default());
}

if args.version().is_some() && !self.core.enable_versioning {
return Err(Error::new(
ErrorKind::Unsupported,
"the bucket doesn't enable versioning, cannot delete with version",
));
}

let resp = self.core.s3_delete_object(path, &args).await?;

let status = resp.status();
Expand All @@ -1043,7 +1064,7 @@ impl Access for S3Backend {
if args.version() && !self.core.enable_versioning {
return Err(Error::new(
ErrorKind::Unsupported,
"the bucket doesn't enable versioning",
"the bucket doesn't enable versioning, cannot list with version",
));
}

Expand Down
Loading