acelyc111 commented on code in PR #2170:
URL:
https://github.com/apache/incubator-pegasus/pull/2170#discussion_r1886942781
##########
src/meta/server_state.cpp:
##########
@@ -3109,70 +3112,119 @@ void server_state::set_app_envs(const app_env_rpc
&env_rpc)
void server_state::del_app_envs(const app_env_rpc &env_rpc)
{
- const configuration_update_app_env_request &request = env_rpc.request();
- if (!request.__isset.keys || request.keys.size() <= 0) {
+ const auto &request = env_rpc.request();
+ if (!request.__isset.keys || request.keys.empty()) {
env_rpc.response().err = ERR_INVALID_PARAMETERS;
LOG_WARNING("del app envs failed with invalid request");
return;
}
- const std::vector<std::string> &keys = request.keys;
- const std::string &app_name = request.app_name;
- std::ostringstream os;
- for (int i = 0; i < keys.size(); i++) {
- if (i != 0)
- os << ",";
- os << keys[i];
- }
+ const auto &keys = request.keys;
+ const auto &app_name = request.app_name;
+
LOG_INFO("del app envs for app({}) from remote({}): keys = {}",
app_name,
env_rpc.remote_address(),
- os.str());
+ boost::join(keys, ","));
app_info ainfo;
std::string app_path;
{
+ FAIL_POINT_INJECT_NOT_RETURN_F("del_app_envs_failed", [app_name,
this](std::string_view s) {
+ zauto_write_lock l(_lock);
+
+ if (s == "not_found") {
+ CHECK_EQ(_exist_apps.erase(app_name), 1);
+ return;
+ }
+
+ if (s == "dropping") {
+ gutil::FindOrDie(_exist_apps, app_name)->status =
app_status::AS_DROPPING;
+ return;
+ }
+ });
+
zauto_read_lock l(_lock);
- std::shared_ptr<app_state> app = get_app(app_name);
- if (app == nullptr) {
- LOG_WARNING("del app envs failed with invalid app_name({})",
app_name);
- env_rpc.response().err = ERR_INVALID_PARAMETERS;
- env_rpc.response().hint_message = "invalid app name";
+
+ const auto &app = get_app(app_name);
+ if (!app) {
+ LOG_WARNING("del app envs failed since app_name({}) cannot be
found", app_name);
+ env_rpc.response().err = ERR_APP_NOT_EXIST;
+ env_rpc.response().hint_message = "app cannot be found";
return;
- } else {
- ainfo = *(reinterpret_cast<app_info *>(app.get()));
- app_path = get_app_path(*app);
}
+
+ if (app->status == app_status::AS_DROPPING) {
+ LOG_WARNING("del app envs failed since app(name={}, id={}) is
being dropped",
+ app_name,
+ app->app_id);
+ env_rpc.response().err = ERR_BUSY_DROPPING;
+ env_rpc.response().hint_message = "app is being dropped";
+ return;
+ }
+
+ ainfo = *app;
+ app_path = get_app_path(*app);
}
- std::ostringstream oss;
- oss << "deleted keys:";
- int deleted = 0;
+ std::string deleted_keys_info("deleted keys:");
+ size_t deleted_count = 0;
for (const auto &key : keys) {
- if (ainfo.envs.erase(key) > 0) {
- oss << std::endl << " " << key;
- deleted++;
+ if (ainfo.envs.erase(key) == 0) {
+ continue;
}
+
+ deleted_keys_info += fmt::format("\n {}", key);
Review Comment:
Will `fmt::format_to` be faster than `std::string` `+` operator?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]