You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "meteorgan (via GitHub)" <gi...@apache.org> on 2024/07/11 14:25:59 UTC

[PR] feat(user_metadata): support user defined metadata for oss [opendal]

meteorgan opened a new pull request, #4881:
URL: https://github.com/apache/opendal/pull/4881

   part of: https://github.com/apache/opendal/issues/4842


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(core): support user defined metadata for oss [opendal]

Posted by "meteorgan (via GitHub)" <gi...@apache.org>.
meteorgan commented on code in PR #4881:
URL: https://github.com/apache/opendal/pull/4881#discussion_r1675679880


##########
core/src/raw/http_util/header.rs:
##########
@@ -189,6 +190,45 @@ pub fn parse_into_metadata(path: &str, headers: &HeaderMap) -> Result<Metadata>
     Ok(m)
 }
 
+/// parse_metadata will parse http headers(including standards http headers
+/// and user defined metadata header) into Metadata.
+///
+/// # Arguments
+///
+/// * `user_metadata_prefix` is the prefix of user defined metadata key
+///
+/// # Notes
+///
+/// before return the user defined metadata, we'll strip the user_metadata_prefix from the key
+pub fn parse_metadata(

Review Comment:
   It may seem like premature optimization, but the user meta prefix is used in other services, such as S3 and GCS. However, it's ok to extract it later



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(user_metadata): support user defined metadata for oss [opendal]

Posted by "meteorgan (via GitHub)" <gi...@apache.org>.
meteorgan commented on code in PR #4881:
URL: https://github.com/apache/opendal/pull/4881#discussion_r1674202057


##########
core/src/services/oss/core.rs:
##########
@@ -225,14 +229,17 @@ impl OssCore {
         }
 
         if let Some(cache_control) = args.cache_control() {
-            req = req.header(CACHE_CONTROL, cache_control)
+            req = req.header(CACHE_CONTROL, cache_control);
         }
 
-        // set sse headers
-        req = self.insert_sse_headers(req);
+        if let Some(user_metadata) = args.user_metadata() {
+            for (key, value) in user_metadata {
+                // before insert user defined metadata header, add prefix to the header name
+                req = req.header(format!("{}{}", constants::USER_METADATA_PREFIX, key), value)

Review Comment:
   According to https://help.aliyun.com/zh/oss/developer-reference/putobject, the key of user defined metadata has some constrains, should we do some checks here ? otherwise the `aliyun` might return `SignatureDoesNotMatch` error, which can be confusing.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(core): support user defined metadata for oss [opendal]

Posted by "meteorgan (via GitHub)" <gi...@apache.org>.
meteorgan commented on code in PR #4881:
URL: https://github.com/apache/opendal/pull/4881#discussion_r1675679880


##########
core/src/raw/http_util/header.rs:
##########
@@ -189,6 +190,45 @@ pub fn parse_into_metadata(path: &str, headers: &HeaderMap) -> Result<Metadata>
     Ok(m)
 }
 
+/// parse_metadata will parse http headers(including standards http headers
+/// and user defined metadata header) into Metadata.
+///
+/// # Arguments
+///
+/// * `user_metadata_prefix` is the prefix of user defined metadata key
+///
+/// # Notes
+///
+/// before return the user defined metadata, we'll strip the user_metadata_prefix from the key
+pub fn parse_metadata(

Review Comment:
   It may seem like premature optimization, but the user meta prefix is used in other services, such as S3 and GCS. but it's ok to do it later



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(user_metadata): support user defined metadata for oss [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #4881:
URL: https://github.com/apache/opendal/pull/4881#discussion_r1674186222


##########
core/src/types/operator/operator_futures.rs:
##########


Review Comment:
   Yes, they are the same. We can call them `option`.



##########
core/src/types/operator/operator_futures.rs:
##########


Review Comment:
   Yes, they are the same. We can call them `option`. We can start a new PR for this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(core): support user defined metadata for oss [opendal]

Posted by "meteorgan (via GitHub)" <gi...@apache.org>.
meteorgan commented on code in PR #4881:
URL: https://github.com/apache/opendal/pull/4881#discussion_r1675676089


##########
core/src/types/operator/operator_futures.rs:
##########
@@ -384,6 +395,16 @@ impl<F: Future<Output = Result<Writer>>> FutureWriter<F> {
     pub fn executor(self, executor: Executor) -> Self {
         self.map(|(args, options)| (args.with_executor(executor), options))
     }
+
+    /// Set the user defined metadata of the op
+    ///
+    /// ## Notes
+    ///
+    /// we don't need to include the user defined metadata prefix in the key
+    /// every service will handle it internally
+    pub fn user_metadata(self, data: HashMap<String, String>) -> Self {

Review Comment:
   Do you mean `IntoIterator` ?
   like this:
   ```
       pub fn user_metadata(self, data: impl IntoIterator<Item = (String, String)>) -> Self {
           self.map(|(args, options, bs)| (args.with_user_metadata(HashMap::from_iter(data)), options, bs))
       }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(core): support user defined metadata for oss [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo merged PR #4881:
URL: https://github.com/apache/opendal/pull/4881


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(user_metadata): support user defined metadata for oss [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #4881:
URL: https://github.com/apache/opendal/pull/4881#discussion_r1674189264


##########
core/src/raw/http_util/header.rs:
##########
@@ -189,6 +190,45 @@ pub fn parse_into_metadata(path: &str, headers: &HeaderMap) -> Result<Metadata>
     Ok(m)
 }
 
+/// parse_metadata will parse http headers(including standards http headers
+/// and user defined metadata header) into Metadata.
+///
+/// # Arguments
+///
+/// * `user_metadata_prefix` is the prefix of user defined metadata key
+///
+/// # Notes
+///
+/// before return the user defined metadata, we'll strip the user_metadata_prefix from the key
+pub fn parse_metadata(

Review Comment:
   Hi, I'd prefer to keep that logic in the service for now. We can extract it later if we find it's common across different services.



##########
core/src/services/oss/core.rs:
##########
@@ -41,14 +41,15 @@ use serde::Serialize;
 use crate::raw::*;
 use crate::*;
 
-mod constants {
+pub mod constants {
     pub const X_OSS_SERVER_SIDE_ENCRYPTION: &str = "x-oss-server-side-encryption";
 
     pub const X_OSS_SERVER_SIDE_ENCRYPTION_KEY_ID: &str = "x-oss-server-side-encryption-key-id";
 
     pub const RESPONSE_CONTENT_DISPOSITION: &str = "response-content-disposition";
 
     pub const OSS_QUERY_VERSION_ID: &str = "versionId";
+    pub const USER_METADATA_PREFIX: &str = "x-oss-meta-";

Review Comment:
   How about keeping the same naming style like `X_OSS_META_PREFIX`



##########
core/src/types/operator/operator_futures.rs:
##########
@@ -384,6 +395,16 @@ impl<F: Future<Output = Result<Writer>>> FutureWriter<F> {
     pub fn executor(self, executor: Executor) -> Self {
         self.map(|(args, options)| (args.with_executor(executor), options))
     }
+
+    /// Set the user defined metadata of the op
+    ///
+    /// ## Notes
+    ///
+    /// we don't need to include the user defined metadata prefix in the key
+    /// every service will handle it internally
+    pub fn user_metadata(self, data: HashMap<String, String>) -> Self {

Review Comment:
   Let's accept an `FromIterator` to make it easier to use.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(core): support user defined metadata for oss [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #4881:
URL: https://github.com/apache/opendal/pull/4881#discussion_r1674204866


##########
core/src/services/oss/core.rs:
##########
@@ -225,14 +229,17 @@ impl OssCore {
         }
 
         if let Some(cache_control) = args.cache_control() {
-            req = req.header(CACHE_CONTROL, cache_control)
+            req = req.header(CACHE_CONTROL, cache_control);
         }
 
-        // set sse headers
-        req = self.insert_sse_headers(req);
+        if let Some(user_metadata) = args.user_metadata() {
+            for (key, value) in user_metadata {
+                // before insert user defined metadata header, add prefix to the header name
+                req = req.header(format!("{}{}", constants::USER_METADATA_PREFIX, key), value)

Review Comment:
   > the key of user defined metadata has some constrains, should we do some checks here ?
   
   That would be nice.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(core): support user defined metadata for oss [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #4881:
URL: https://github.com/apache/opendal/pull/4881#issuecomment-2227365979

   > Currently, none of the services that support blocking operations require user metadata. So, it seems there’s no need to support user metadata for the blocking operator, right? @Xuanwo
   
   I'm fine to split user metadata support of blocking operations into other PRs. Or just leave them not implemented.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(user_metadata): support user defined metadata for oss [opendal]

Posted by "meteorgan (via GitHub)" <gi...@apache.org>.
meteorgan commented on code in PR #4881:
URL: https://github.com/apache/opendal/pull/4881#discussion_r1674175719


##########
core/src/types/operator/operator_futures.rs:
##########


Review Comment:
   the function comments in `FutureWrite` and other related structs are not unified and confusing.
   for example: 
   
   1. Set the append mode of op
   2. Set the content type of option
   3. Set the executor for this operation
   
   Is the op, option, operation the same meaning ? shall we unify them ?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(core): support user defined metadata for oss [opendal]

Posted by "meteorgan (via GitHub)" <gi...@apache.org>.
meteorgan commented on PR #4881:
URL: https://github.com/apache/opendal/pull/4881#issuecomment-2227340537

   > part of: #4842
   > 
   > Done:
   > 
   > * [x]  Implement `user_metadata` for metadata
   > * [x]  Implement `user_metadata` for oss
   > 
   > Todo:
   > 
   > * [ ]  support blocking operator
   
   Currently, none of the services that support blocking operations require user metadata. So, it seems there’s no need to support user metadata for the blocking operator, right?  @Xuanwo 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] feat(core): support user defined metadata for oss [opendal]

Posted by "meteorgan (via GitHub)" <gi...@apache.org>.
meteorgan commented on code in PR #4881:
URL: https://github.com/apache/opendal/pull/4881#discussion_r1676100848


##########
core/tests/behavior/async_write.rs:
##########
@@ -70,6 +72,7 @@ pub async fn test_write_only(op: Operator) -> Result<()> {
     op.write(&path, content).await?;
 
     let meta = op.stat(&path).await.expect("stat must succeed");
+    println!("path: {}, meta: {:?}", path, meta);

Review Comment:
   emmm, I'll remove it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org