-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[feature](Vault) Support alter s3 storage vault using http interface #37537
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -509,6 +509,80 @@ static void set_default_vault_log_helper(const InstanceInfoPB& instance, | |
| LOG(INFO) << vault_msg; | ||
| } | ||
|
|
||
| static int alter_storage_vault(InstanceInfoPB& instance, std::unique_ptr<Transaction> txn, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an UT to test it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ut and regression cases would be involved in #37606. |
||
| const StorageVaultPB& vault, MetaServiceCode& code, | ||
| std::string& msg) { | ||
| if (!vault.has_obj_info()) { | ||
| code = MetaServiceCode::INVALID_ARGUMENT; | ||
| std::stringstream ss; | ||
| ss << "Only s3 vault can be altered"; | ||
ByteYue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| msg = ss.str(); | ||
| return -1; | ||
| } | ||
| const auto& obj_info = vault.obj_info(); | ||
| if (obj_info.has_bucket() || obj_info.has_endpoint() || obj_info.has_prefix() || | ||
| obj_info.has_provider()) { | ||
| code = MetaServiceCode::INVALID_ARGUMENT; | ||
| std::stringstream ss; | ||
| ss << "Only ak, sk can be altered"; | ||
| msg = ss.str(); | ||
| return -1; | ||
| } | ||
| const auto& name = vault.name(); | ||
| auto name_itr = std::find_if(instance.storage_vault_names().begin(), | ||
| instance.storage_vault_names().end(), | ||
| [&](const auto& vault_name) { return name == vault_name; }); | ||
| if (name_itr == instance.storage_vault_names().end()) { | ||
| code = MetaServiceCode::INVALID_ARGUMENT; | ||
| std::stringstream ss; | ||
| ss << "invalid storage vault name, name =" << name; | ||
| msg = ss.str(); | ||
| return -1; | ||
| } | ||
| auto pos = name_itr - instance.storage_vault_names().begin(); | ||
| auto id_itr = instance.resource_ids().begin() + pos; | ||
| auto vault_key = storage_vault_key({instance.instance_id(), *id_itr}); | ||
| std::string val; | ||
|
|
||
| auto err = txn->get(vault_key, &val); | ||
| LOG(INFO) << "get instance_key=" << hex(vault_key); | ||
|
|
||
| if (err != TxnErrorCode::TXN_OK) { | ||
| code = cast_as<ErrCategory::READ>(err); | ||
| std::stringstream ss; | ||
| ss << "failed to get storage vault, vault_id=" << *name_itr << ", vault_name=" | ||
| << "" << name << " err=" << err; | ||
| msg = ss.str(); | ||
| return -1; | ||
| } | ||
| StorageVaultPB alter; | ||
| alter.ParseFromString(val); | ||
| if (obj_info.has_ak()) { | ||
| alter.mutable_obj_info()->set_ak(obj_info.ak()); | ||
| } | ||
| if (obj_info.has_sk()) { | ||
| alter.mutable_obj_info()->set_ak(obj_info.sk()); | ||
| } | ||
|
|
||
| val = alter.SerializeAsString(); | ||
| if (val.empty()) { | ||
| msg = "failed to serialize"; | ||
| code = MetaServiceCode::PROTOBUF_SERIALIZE_ERR; | ||
| return -1; | ||
| } | ||
|
|
||
| txn->put(vault_key, val); | ||
| LOG(INFO) << "put vault_id=" << *id_itr << " instance_key=" << hex(vault_key); | ||
| err = txn->commit(); | ||
| if (err != TxnErrorCode::TXN_OK) { | ||
| code = cast_as<ErrCategory::COMMIT>(err); | ||
| msg = fmt::format("failed to commit kv txn, err={}", err); | ||
| LOG(WARNING) << msg; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| void MetaServiceImpl::alter_obj_store_info(google::protobuf::RpcController* controller, | ||
| const AlterObjStoreInfoRequest* request, | ||
| AlterObjStoreInfoResponse* response, | ||
|
|
@@ -575,22 +649,20 @@ void MetaServiceImpl::alter_obj_store_info(google::protobuf::RpcController* cont | |
| } | ||
| break; | ||
| } | ||
| case AlterObjStoreInfoRequest::ADD_BUILT_IN_VAULT: { | ||
ByteYue marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // It should at least has one hdfs info or obj info inside storage vault | ||
| if ((!request->has_vault())) { | ||
| code = MetaServiceCode::INVALID_ARGUMENT; | ||
| msg = "hdfs info is not found " + proto_to_json(*request); | ||
| return; | ||
| } | ||
| case AlterObjStoreInfoRequest::ALTER_S3_VAULT: | ||
| break; | ||
| } | ||
| case AlterObjStoreInfoRequest::UNKNOWN: { | ||
| code = MetaServiceCode::INVALID_ARGUMENT; | ||
| msg = "Unknown alter info " + proto_to_json(*request); | ||
| return; | ||
| } break; | ||
| case AlterObjStoreInfoRequest::UNSET_DEFAULT_VAULT: | ||
| break; | ||
| default: | ||
| code = MetaServiceCode::INVALID_ARGUMENT; | ||
| msg = "Unknown alter obj store info, request info " + proto_to_json(*request); | ||
| LOG_WARNING("Unknown alter obj store info, request info {}", request->DebugString()); | ||
| return; | ||
| } | ||
|
|
||
| // TODO(dx): check s3 info right | ||
|
|
@@ -784,22 +856,6 @@ void MetaServiceImpl::alter_obj_store_info(google::protobuf::RpcController* cont | |
| } | ||
| break; | ||
| } | ||
| case AlterObjStoreInfoRequest::ADD_BUILT_IN_VAULT: { | ||
| // If the resource ids is empty then it would be the first vault | ||
| if (!instance.resource_ids().empty()) { | ||
| std::stringstream ss; | ||
| code = MetaServiceCode::INVALID_ARGUMENT; | ||
| ss << "Default vault can not be modified"; | ||
| msg = ss.str(); | ||
| return; | ||
| } | ||
| if (auto ret = add_vault_into_instance( | ||
| instance, txn.get(), const_cast<StorageVaultPB&>(request->vault()), code, msg); | ||
| ret != 0) { | ||
| return; | ||
| } | ||
| return; | ||
| } | ||
| case AlterObjStoreInfoRequest::DROP_HDFS_INFO: { | ||
| if (auto ret = remove_hdfs_storage_vault(instance, txn.get(), request->vault(), code, msg); | ||
| ret != 0) { | ||
|
|
@@ -835,6 +891,10 @@ void MetaServiceImpl::alter_obj_store_info(google::protobuf::RpcController* cont | |
| instance.clear_default_storage_vault_name(); | ||
| break; | ||
| } | ||
| case AlterObjStoreInfoRequest::ALTER_S3_VAULT: { | ||
| alter_storage_vault(instance, std::move(txn), request->vault(), code, msg); | ||
| return; | ||
| } | ||
| case AlterObjStoreInfoRequest::DROP_S3_VAULT: | ||
| [[fallthrough]]; | ||
| default: { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.