Skip to content

Commit

Permalink
[enhance](Cloud) Unify s3 and hdfs vault's check existence logic (#34060
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ByteYue authored Apr 25, 2024
1 parent 8ffb170 commit df11c8c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions cloud/src/meta-service/meta_service_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,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
Expand Down Expand Up @@ -472,13 +465,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()});
Expand Down Expand Up @@ -757,7 +760,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;
Expand All @@ -773,7 +776,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;
Expand Down

0 comments on commit df11c8c

Please sign in to comment.