TangSiyang2001 commented on code in PR #42413:
URL: https://github.com/apache/doris/pull/42413#discussion_r1836033539


##########
cloud/src/meta-service/meta_service_http.cpp:
##########
@@ -331,6 +338,128 @@ static HttpResponse process_alter_iam(MetaServiceImpl* 
service, brpc::Controller
     return http_json_reply(resp.status());
 }
 
+static HttpResponse process_adjust_rate_limit(MetaServiceImpl* service, 
brpc::Controller* cntl) {
+    const auto& uri = cntl->http_request().uri();
+    auto qps_limit_str = std::string {http_query(uri, "qps_limit")};
+    auto rpc_name = std::string {http_query(uri, "rpc_name")};
+    auto instance_id = std::string {http_query(uri, "instance_id")};
+
+    auto process_invalid_arguments = [&]() -> HttpResponse {
+        return http_json_reply(MetaServiceCode::INVALID_ARGUMENT,
+                               fmt::format("invalid argument: 
qps_limit(required)={}, "
+                                           "rpc_name(optional)={}, 
instance_id(optional)={}",
+                                           qps_limit_str, rpc_name, 
instance_id));
+    };
+
+    static auto parse_qps_limit =
+            [](const std::string& qps_limit_str) -> std::variant<int64_t, 
HttpResponse> {
+        DCHECK(!qps_limit_str.empty());
+        int64_t qps_limit = -1;
+        try {
+            qps_limit = std::stoll(qps_limit_str);
+        } catch (const std::exception& ex) {
+            return http_json_reply(
+                    MetaServiceCode::INVALID_ARGUMENT,
+                    fmt::format("param `qps_limit` is not a legal int64 
type:{}", ex.what()));
+        }
+        if (qps_limit < 0) {
+            return http_json_reply(MetaServiceCode::INVALID_ARGUMENT,
+                                   "`qps_limit` should not be less than 0");
+        }
+        return qps_limit;
+    };
+
+    auto process_set_qps_limit = [&](std::function<bool(int64_t)> cb) -> 
HttpResponse {
+        return std::visit(
+                [&](auto&& parse_result) {
+                    using T = std::decay_t<decltype(parse_result)>;
+                    if constexpr (std::is_same_v<T, HttpResponse>) {
+                        return parse_result;
+                    } else {
+                        if (cb(parse_result)) {
+                            return http_json_reply(MetaServiceCode::OK,
+                                                   "sucess to adjust rate 
limit");
+                        }
+                        return http_json_reply(
+                                MetaServiceCode::INVALID_ARGUMENT,
+                                fmt::format("failed to adjust rate limit for 
qps_limit={}, "
+                                            "rpc_name={}, instance_id={}, plz 
ensure correct "
+                                            "rpc/instance name",
+                                            qps_limit_str, rpc_name, 
instance_id));
+                    }
+                },
+                parse_qps_limit(qps_limit_str));
+    };
+
+    auto set_global_qps_limit = [process_set_qps_limit, service]() {
+        return process_set_qps_limit([service](int64_t qps_limit) {
+            return service->rate_limiter()->set_rate_limit(qps_limit);
+        });
+    };
+
+    auto set_rpc_qps_limit = [&]() {
+        return process_set_qps_limit([&](int64_t qps_limit) {
+            return service->rate_limiter()->set_rate_limit(qps_limit, 
rpc_name);
+        });
+    };
+
+    auto set_instance_qps_limit = [&]() {
+        return process_set_qps_limit([&](int64_t qps_limit) {
+            return service->rate_limiter()->set_instance_rate_limit(qps_limit, 
instance_id);
+        });
+    };
+
+    auto set_instance_rpc_qps_limit = [&]() {
+        return process_set_qps_limit([&](int64_t qps_limit) {
+            return service->rate_limiter()->set_rate_limit(qps_limit, 
rpc_name, instance_id);
+        });
+    };
+
+    // for 8 element in true table of params, register processor cb

Review Comment:
   Maybe I'll add some comments, just register different callback for different 
params pattern, and the "abuse" of lamda are just meant to adapt for this.



-- 
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: commits-unsubscr...@doris.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to