This is an automated email from the ASF dual-hosted git repository.

dataroaring pushed a commit to branch branch-4.0-preview
in repository https://gitbox.apache.org/repos/asf/doris.git

commit a6659c8c41c419379d7f8e8ab803834e145c3fff
Author: AlexYue <yj976240...@gmail.com>
AuthorDate: Thu Apr 25 11:24:21 2024 +0800

    [enhance](Cloud) Unify s3 and hdfs vault's check existence logic (#34060)
---
 cloud/src/meta-service/meta_service_resource.cpp | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/cloud/src/meta-service/meta_service_resource.cpp 
b/cloud/src/meta-service/meta_service_resource.cpp
index 8d7a420ab59..a1edaae527b 100644
--- a/cloud/src/meta-service/meta_service_resource.cpp
+++ b/cloud/src/meta-service/meta_service_resource.cpp
@@ -382,13 +382,6 @@ static int add_hdfs_storage_vault(InstanceInfoPB& 
instance, Transaction* txn,
         msg = fmt::format("vault_name={} passed invalid argument", 
hdfs_param.name());
         return -1;
     }
-    if (std::find_if(instance.storage_vault_names().begin(), 
instance.storage_vault_names().end(),
-                     [&hdfs_param](const auto& name) { return name == 
hdfs_param.name(); }) !=
-        instance.storage_vault_names().end()) {
-        code = MetaServiceCode::ALREADY_EXISTED;
-        msg = fmt::format("vault_name={} already created", hdfs_param.name());
-        return -1;
-    }
 
     using namespace detail;
     // Check and normalize hdfs conf
@@ -480,13 +473,23 @@ static void create_object_info_with_encrypt(const 
InstanceInfoPB& instance, Obje
 static int add_vault_into_instance(InstanceInfoPB& instance, Transaction* txn,
                                    StorageVaultPB& vault_param, 
MetaServiceCode& code,
                                    std::string& msg) {
+    if (std::find_if(instance.storage_vault_names().begin(), 
instance.storage_vault_names().end(),
+                     [&vault_param](const auto& name) { return name == 
vault_param.name(); }) !=
+        instance.storage_vault_names().end()) {
+        code = MetaServiceCode::ALREADY_EXISTED;
+        msg = fmt::format("vault_name={} already created", vault_param.name());
+        return -1;
+    }
+
     if (vault_param.has_hdfs_info()) {
         return add_hdfs_storage_vault(instance, txn, vault_param, code, msg);
     }
+
     create_object_info_with_encrypt(instance, vault_param.mutable_obj_info(), 
true, code, msg);
     if (code != MetaServiceCode::OK) {
         return -1;
     }
+
     vault_param.mutable_obj_info()->CopyFrom(vault_param.obj_info());
     vault_param.set_id(vault_param.obj_info().id());
     auto vault_key = storage_vault_key({instance.instance_id(), 
vault_param.obj_info().id()});
@@ -763,7 +766,7 @@ void 
MetaServiceImpl::alter_obj_store_info(google::protobuf::RpcController* cont
         }
     } break;
     case AlterObjStoreInfoRequest::ADD_HDFS_INFO: {
-        if (auto ret = add_hdfs_storage_vault(
+        if (auto ret = add_vault_into_instance(
                     instance, txn.get(), 
const_cast<StorageVaultPB&>(request->vault()), code, msg);
             ret != 0) {
             return;
@@ -779,7 +782,7 @@ void 
MetaServiceImpl::alter_obj_store_info(google::protobuf::RpcController* cont
             msg = ss.str();
             return;
         }
-        if (auto ret = add_hdfs_storage_vault(
+        if (auto ret = add_vault_into_instance(
                     instance, txn.get(), 
const_cast<StorageVaultPB&>(request->vault()), code, msg);
             ret != 0) {
             return;


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

Reply via email to