You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pegasus.apache.org by "empiredan (via GitHub)" <gi...@apache.org> on 2024/12/13 10:33:18 UTC

[PR] fix(meta): fix null pointer while deleting environment variables after table was dropped [incubator-pegasus]

empiredan opened a new pull request, #2170:
URL: https://github.com/apache/incubator-pegasus/pull/2170

   (no comment)


-- 
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: dev-unsubscribe@pegasus.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org


Re: [PR] fix(meta): fix null pointer while deleting environment variables after table was dropped [incubator-pegasus]

Posted by "empiredan (via GitHub)" <gi...@apache.org>.
empiredan merged PR #2170:
URL: https://github.com/apache/incubator-pegasus/pull/2170


-- 
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: dev-unsubscribe@pegasus.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org


Re: [PR] fix(meta): fix null pointer while deleting environment variables after table was dropped [incubator-pegasus]

Posted by "acelyc111 (via GitHub)" <gi...@apache.org>.
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: dev-unsubscribe@pegasus.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org


Re: [PR] fix(meta): fix null pointer while deleting environment variables after table was dropped [incubator-pegasus]

Posted by "empiredan (via GitHub)" <gi...@apache.org>.
empiredan commented on code in PR #2170:
URL: https://github.com/apache/incubator-pegasus/pull/2170#discussion_r1887852633


##########
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:
   OK, I'll use `fmt::format_to` instead.



-- 
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: dev-unsubscribe@pegasus.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pegasus.apache.org
For additional commands, e-mail: dev-help@pegasus.apache.org