platoneko commented on code in PR #31415:
URL: https://github.com/apache/doris/pull/31415#discussion_r1517356605


##########
cloud/src/meta-service/meta_service_resource.cpp:
##########
@@ -218,52 +271,156 @@ void 
MetaServiceImpl::get_obj_store_info(google::protobuf::RpcController* contro
         return;
     }
     for (auto& obj_info : *instance.mutable_obj_info()) {
-        if (obj_info.has_encryption_info()) {
-            AkSkPair plain_ak_sk_pair;
-            int ret = decrypt_ak_sk_helper(obj_info.ak(), obj_info.sk(), 
obj_info.encryption_info(),
-                                           &plain_ak_sk_pair, code, msg);
-            if (ret != 0) return;
-            obj_info.set_ak(std::move(plain_ak_sk_pair.first));
-            obj_info.set_sk(std::move(plain_ak_sk_pair.second));
+        if (auto ret = decrypt_and_update_ak_sk(obj_info, code, msg); ret != 
0) {
+            return;
+        }
+    }
+    // Iterate all the resources to return to the rpc caller
+    for (const auto& resource_id : instance.resource_ids()) {
+        std::string storage_vault_k = storage_vault_key({instance_id, 
resource_id});
+        if (auto ret = fetch_all_storage_valut(std::move(storage_vault_k), 
instance_id, response,
+                                               txn_kv_.get(), code, msg);
+            ret != 0) {
+            return;
         }
     }
     response->mutable_obj_info()->CopyFrom(instance.obj_info());
 }
 
+// The next avaiable vault id would be max(max(obj info id), max(vault id)) + 
1.
+static std::string next_avaiable_vault_id(const InstanceInfoPB& instance) {
+    size_t vault_id = 0;
+    auto cmp = [](size_t prev, const auto& last) {
+        size_t last_id = 0;
+        if constexpr (std::is_same_v<std::decay_t<decltype(last)>, 
ObjectStoreInfoPB>) {
+            last_id = std::stoi(last.id());

Review Comment:
   防一手不是 int 的情况



##########
cloud/src/meta-service/meta_service_resource.cpp:
##########
@@ -218,52 +271,156 @@ void 
MetaServiceImpl::get_obj_store_info(google::protobuf::RpcController* contro
         return;
     }
     for (auto& obj_info : *instance.mutable_obj_info()) {
-        if (obj_info.has_encryption_info()) {
-            AkSkPair plain_ak_sk_pair;
-            int ret = decrypt_ak_sk_helper(obj_info.ak(), obj_info.sk(), 
obj_info.encryption_info(),
-                                           &plain_ak_sk_pair, code, msg);
-            if (ret != 0) return;
-            obj_info.set_ak(std::move(plain_ak_sk_pair.first));
-            obj_info.set_sk(std::move(plain_ak_sk_pair.second));
+        if (auto ret = decrypt_and_update_ak_sk(obj_info, code, msg); ret != 
0) {
+            return;
+        }
+    }
+    // Iterate all the resources to return to the rpc caller
+    for (const auto& resource_id : instance.resource_ids()) {
+        std::string storage_vault_k = storage_vault_key({instance_id, 
resource_id});
+        if (auto ret = fetch_all_storage_valut(std::move(storage_vault_k), 
instance_id, response,

Review Comment:
   Use range get



##########
cloud/src/meta-service/meta_service_resource.cpp:
##########
@@ -218,52 +271,156 @@ void 
MetaServiceImpl::get_obj_store_info(google::protobuf::RpcController* contro
         return;
     }
     for (auto& obj_info : *instance.mutable_obj_info()) {
-        if (obj_info.has_encryption_info()) {
-            AkSkPair plain_ak_sk_pair;
-            int ret = decrypt_ak_sk_helper(obj_info.ak(), obj_info.sk(), 
obj_info.encryption_info(),
-                                           &plain_ak_sk_pair, code, msg);
-            if (ret != 0) return;
-            obj_info.set_ak(std::move(plain_ak_sk_pair.first));
-            obj_info.set_sk(std::move(plain_ak_sk_pair.second));
+        if (auto ret = decrypt_and_update_ak_sk(obj_info, code, msg); ret != 
0) {
+            return;
+        }
+    }
+    // Iterate all the resources to return to the rpc caller
+    for (const auto& resource_id : instance.resource_ids()) {
+        std::string storage_vault_k = storage_vault_key({instance_id, 
resource_id});
+        if (auto ret = fetch_all_storage_valut(std::move(storage_vault_k), 
instance_id, response,
+                                               txn_kv_.get(), code, msg);
+            ret != 0) {
+            return;
         }
     }
     response->mutable_obj_info()->CopyFrom(instance.obj_info());
 }
 
+// The next avaiable vault id would be max(max(obj info id), max(vault id)) + 
1.
+static std::string next_avaiable_vault_id(const InstanceInfoPB& instance) {
+    size_t vault_id = 0;
+    auto cmp = [](size_t prev, const auto& last) {
+        size_t last_id = 0;
+        if constexpr (std::is_same_v<std::decay_t<decltype(last)>, 
ObjectStoreInfoPB>) {
+            last_id = std::stoi(last.id());
+        } else if constexpr (std::is_same_v<std::decay_t<decltype(last)>, 
std::string>) {
+            last_id = std::stoi(last);
+        }
+        return std::max(prev, last_id);
+    };
+    auto prev = std::accumulate(
+            instance.resource_ids().begin(), instance.resource_ids().end(),
+            std::accumulate(instance.obj_info().begin(), 
instance.obj_info().end(), vault_id, cmp),
+            cmp);
+    return std::to_string(prev + 1);
+}
+
+static int add_hdfs_storage_valut(InstanceInfoPB& instance, TxnKv* txn_kv,

Review Comment:
   
   ```suggestion
   static int add_hdfs_storage_valut(InstanceInfoPB& instance, Transaction* txn,
   ```



##########
cloud/src/meta-service/meta_service_resource.cpp:
##########
@@ -218,52 +271,156 @@ void 
MetaServiceImpl::get_obj_store_info(google::protobuf::RpcController* contro
         return;
     }
     for (auto& obj_info : *instance.mutable_obj_info()) {
-        if (obj_info.has_encryption_info()) {
-            AkSkPair plain_ak_sk_pair;
-            int ret = decrypt_ak_sk_helper(obj_info.ak(), obj_info.sk(), 
obj_info.encryption_info(),
-                                           &plain_ak_sk_pair, code, msg);
-            if (ret != 0) return;
-            obj_info.set_ak(std::move(plain_ak_sk_pair.first));
-            obj_info.set_sk(std::move(plain_ak_sk_pair.second));
+        if (auto ret = decrypt_and_update_ak_sk(obj_info, code, msg); ret != 
0) {
+            return;
+        }
+    }
+    // Iterate all the resources to return to the rpc caller
+    for (const auto& resource_id : instance.resource_ids()) {
+        std::string storage_vault_k = storage_vault_key({instance_id, 
resource_id});
+        if (auto ret = fetch_all_storage_valut(std::move(storage_vault_k), 
instance_id, response,
+                                               txn_kv_.get(), code, msg);
+            ret != 0) {
+            return;
         }
     }
     response->mutable_obj_info()->CopyFrom(instance.obj_info());
 }
 
+// The next avaiable vault id would be max(max(obj info id), max(vault id)) + 
1.
+static std::string next_avaiable_vault_id(const InstanceInfoPB& instance) {

Review Comment:
   typo `avaiable`



##########
gensrc/proto/cloud.proto:
##########
@@ -691,16 +717,24 @@ message GetObjStoreInfoRequest {
     optional string cloud_unique_id = 1; // For auth
 };
 
+message AlterHdfsVaultInfo {
+    optional string vault_name = 1;
+    optional HdfsVaultInfo hdfs = 2;
+}
+
 message AlterObjStoreInfoRequest {
     enum Operation {
         UNKNOWN         = 0;
         UPDATE_AK_SK    = 1;
         ADD_OBJ_INFO    = 2;
         LEGACY_UPDATE_AK_SK = 3;
+
+        ADD_HDFS_INFO = 100;
     }
     optional string cloud_unique_id = 1; // For auth
     optional ObjectStoreInfoPB obj = 2;
     optional Operation op = 3;
+    optional AlterHdfsVaultInfo hdfs = 4;

Review Comment:
   直接用 `StorageVaultPB` 吧



##########
cloud/src/meta-service/meta_service_resource.cpp:
##########
@@ -218,52 +271,156 @@ void 
MetaServiceImpl::get_obj_store_info(google::protobuf::RpcController* contro
         return;
     }
     for (auto& obj_info : *instance.mutable_obj_info()) {
-        if (obj_info.has_encryption_info()) {
-            AkSkPair plain_ak_sk_pair;
-            int ret = decrypt_ak_sk_helper(obj_info.ak(), obj_info.sk(), 
obj_info.encryption_info(),
-                                           &plain_ak_sk_pair, code, msg);
-            if (ret != 0) return;
-            obj_info.set_ak(std::move(plain_ak_sk_pair.first));
-            obj_info.set_sk(std::move(plain_ak_sk_pair.second));
+        if (auto ret = decrypt_and_update_ak_sk(obj_info, code, msg); ret != 
0) {
+            return;
+        }
+    }
+    // Iterate all the resources to return to the rpc caller
+    for (const auto& resource_id : instance.resource_ids()) {
+        std::string storage_vault_k = storage_vault_key({instance_id, 
resource_id});
+        if (auto ret = fetch_all_storage_valut(std::move(storage_vault_k), 
instance_id, response,
+                                               txn_kv_.get(), code, msg);
+            ret != 0) {
+            return;
         }
     }
     response->mutable_obj_info()->CopyFrom(instance.obj_info());
 }
 
+// The next avaiable vault id would be max(max(obj info id), max(vault id)) + 
1.
+static std::string next_avaiable_vault_id(const InstanceInfoPB& instance) {
+    size_t vault_id = 0;
+    auto cmp = [](size_t prev, const auto& last) {

Review Comment:
   
   ```suggestion
       auto max = [](size_t prev, const auto& last) {
   ```



-- 
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-unsubscr...@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to