GehaFearless commented on code in PR #1272:
URL: 
https://github.com/apache/incubator-pegasus/pull/1272#discussion_r1040569613


##########
src/meta/server_state.cpp:
##########
@@ -1259,6 +1259,111 @@ void server_state::drop_app(dsn::message_ex *msg)
     }
 }
 
+void server_state::do_app_rename(configuration_rename_app_rpc rpc)
+{
+    const auto &old_app_name = rpc.request().old_app_name;
+    const auto &new_app_name = rpc.request().new_app_name;
+
+    zauto_read_lock l;
+    auto target_app = get_app(old_app_name);
+
+    if (target_app == nullptr) {
+        auto &response = rpc.response();
+        std::ostringstream oss;
+        response.err = ERR_APP_NOT_EXIST;
+        oss << "ERROR: app(" << old_app_name << ") not exist. check it!" << 
std::endl;
+        response.hint_message += oss.str();
+        return;
+    }
+
+    LOG_INFO_F("ready to update remote app_name: app_id={}, old_app_name={}, 
new_app_name={}.",
+               target_app->app_id,
+               old_app_name,
+               new_app_name);
+
+    auto ainfo = *(reinterpret_cast<app_info *>(target_app.get()));
+    ainfo.app_name = new_app_name;
+    auto app_path = get_app_path(*target_app);
+
+    do_update_app_info(app_path, ainfo, [this, target_app, rpc](error_code ec) 
mutable {
+        const auto &new_app_name = rpc.request().new_app_name;
+        zauto_write_lock l(_lock);
+
+        CHECK_EQ(ec, ERR_OK);
+
+        const auto old_app_name = target_app->app_name;
+        target_app->app_name = new_app_name;
+
+        _exist_apps.emplace(new_app_name, target_app);
+        _exist_apps.erase(old_app_name);
+
+        LOG_INFO_F("both remote and local env of app_name have been updated "
+                   "successfully: app_id={}, old_app_name={}, new_app_name={}",
+                   target_app->app_id,
+                   old_app_name,
+                   new_app_name);
+
+        auto &response = rpc.response();
+        response.err = ERR_OK;
+
+    });
+}
+
+void server_state::rename_app(configuration_rename_app_rpc rpc)
+{
+    const std::string &old_app_name = rpc.request().old_app_name;
+    const std::string &new_app_name = rpc.request().new_app_name;
+    auto &response = rpc.response();
+
+    std::shared_ptr<app_state> target_app;
+    bool do_rename = false;
+    LOG_INFO_F(
+        "rename app request, old_app_name({}), new_app_name({})", 
old_app_name, new_app_name);
+
+    zauto_read_lock l(_lock);
+    target_app = get_app(old_app_name);
+
+    std::ostringstream oss;
+    if (target_app == nullptr) {
+        response.err = ERR_APP_NOT_EXIST;
+        oss << "ERROR: app(" << old_app_name << ") not exist. check it!" << 
std::endl;
+        response.hint_message += oss.str();
+        return;
+    }
+
+    switch (target_app->status) {
+    case app_status::AS_AVAILABLE: {
+        if (_exist_apps.find(new_app_name) != _exist_apps.end()) {
+            response.err = ERR_INVALID_PARAMETERS;
+            oss << "ERROR: app(" << new_app_name << ") already exist! check 
it!" << std::endl;
+            response.hint_message += oss.str();
+            return;
+        }
+        do_rename = true;

Review Comment:
   For a precise function,also keep style with others and be good for 
transformation and optimization.



-- 
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]

Reply via email to