From 9c10b5847de1ae410689ff1430f0b6682889f629 Mon Sep 17 00:00:00 2001 From: justdba <49357318+justdba@users.noreply.github.com> Date: Thu, 10 Mar 2022 15:50:31 +0800 Subject: [PATCH 1/3] feat: enable weakly consistent read for users who connected this obproxy #21 In the read-write separation scenario, a switch for the session-level enable weakly consistent read or for only the session-level enable weakly consistent to the specified user --- src/obproxy/obutils/ob_proxy_config.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/obproxy/obutils/ob_proxy_config.h b/src/obproxy/obutils/ob_proxy_config.h index 60d46b82..082568fe 100644 --- a/src/obproxy/obutils/ob_proxy_config.h +++ b/src/obproxy/obutils/ob_proxy_config.h @@ -306,6 +306,9 @@ class ObProxyConfig : public common::ObCommonConfig // proxy cmd DEF_INT(proxy_local_cmd, "0", "[0,]", "proxy local cmd type: 0->none(default), 1->exit, 2->restart, 3->commit, 4->rollback", CFG_NO_NEED_REBOOT, CFG_SECTION_OBPROXY, CFG_VISIBLE_LEVEL_MEMORY); + DEF_BOOL(enable_weak_read, "false", "weak read by default for all clients connected this proxy", CFG_NO_NEED_REBOOT, CFG_SECTION_OBPROXY, CFG_VISIBLE_LEVEL_USER); + DEF_STR_LIST(weak_read_user_list, "", "weak read only for list of users, format user1;user2", CFG_NO_NEED_REBOOT, CFG_SECTION_OBPROXY, CFG_VISIBLE_LEVEL_USER); + //ldc DEF_STR(proxy_idc_name, "", "idc name for proxy ldc route. If is empty or invalid, treat as do not use ldc. User session vars 'proxy_session_ldc' can cover it", CFG_NO_NEED_REBOOT, CFG_SECTION_OBPROXY, CFG_VISIBLE_LEVEL_SYS); From 0340f2e515833d856989e6f730ee00106e75770e Mon Sep 17 00:00:00 2001 From: justdba <49357318+justdba@users.noreply.github.com> Date: Thu, 10 Mar 2022 16:01:05 +0800 Subject: [PATCH 2/3] feat: enable weakly consistent read for users who connected the obproxy #21 In the read-write separation scenario, a switch for the session-level enable weakly consistent read or for only the session-level enable weakly consistent to the specified user --- .../ob_proxy_session_info_handler.cpp | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/obproxy/proxy/mysqllib/ob_proxy_session_info_handler.cpp b/src/obproxy/proxy/mysqllib/ob_proxy_session_info_handler.cpp index 53f1e7d7..1ce6e7b2 100644 --- a/src/obproxy/proxy/mysqllib/ob_proxy_session_info_handler.cpp +++ b/src/obproxy/proxy/mysqllib/ob_proxy_session_info_handler.cpp @@ -1176,7 +1176,25 @@ int ObProxySessionInfoHandler::save_changed_session_info(ObClientSessionInfo &cl // 6. handle vip for fllower replica in public cloud or handle config enable read only mode if (OB_SUCC(ret) && is_auth_request) { - if (client_info.is_request_follower_user()) { + bool is_weak_read_user = false ; + int64_t total_size = get_global_proxy_config().weak_read_user_list.size(); + if (OB_UNLIKELY(total_size > 0)){ + ObMysqlAuthRequest &auth_req = client_info.get_login_req(); + ObHSRResult &hsr = auth_req.get_hsr_result(); + char user_buf[MAX_VALUE_LENGTH]; + for (int64_t i = 0; i < total_size; ++i) { + user_buf[0] = '\0'; + if (OB_FAIL(get_global_proxy_config().weak_read_user_list.get(i, user_buf, static_cast(sizeof(user_buf))))) { + LOG_WARN("get weak read user list variables failed", K(ret)); + } + else if (hsr.response_.get_username().prefix_match(user_buf)){ + is_weak_read_user = true; + break; + } + } + } + + if (client_info.is_request_follower_user() || get_global_proxy_config().enable_weak_read || is_weak_read_user) { ObString ob_read_consistency("ob_read_consistency"); // 2 means WEAK for ob_read_consistency ObString weak("2"); From 5cdeb3a303218926580cfba07e4fbe46bd85c18e Mon Sep 17 00:00:00 2001 From: justdba <49357318+justdba@users.noreply.github.com> Date: Wed, 25 May 2022 16:32:03 +0800 Subject: [PATCH 3/3] fix code style --- .../proxy/mysqllib/ob_proxy_session_info_handler.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/obproxy/proxy/mysqllib/ob_proxy_session_info_handler.cpp b/src/obproxy/proxy/mysqllib/ob_proxy_session_info_handler.cpp index 1ce6e7b2..97737a9a 100644 --- a/src/obproxy/proxy/mysqllib/ob_proxy_session_info_handler.cpp +++ b/src/obproxy/proxy/mysqllib/ob_proxy_session_info_handler.cpp @@ -1178,16 +1178,15 @@ int ObProxySessionInfoHandler::save_changed_session_info(ObClientSessionInfo &cl if (OB_SUCC(ret) && is_auth_request) { bool is_weak_read_user = false ; int64_t total_size = get_global_proxy_config().weak_read_user_list.size(); - if (OB_UNLIKELY(total_size > 0)){ + if (OB_UNLIKELY(total_size > 0)) { ObMysqlAuthRequest &auth_req = client_info.get_login_req(); ObHSRResult &hsr = auth_req.get_hsr_result(); char user_buf[MAX_VALUE_LENGTH]; - for (int64_t i = 0; i < total_size; ++i) { + for (int64_t i = 0; OB_SUCC(ret) && i < total_size; ++i) { user_buf[0] = '\0'; if (OB_FAIL(get_global_proxy_config().weak_read_user_list.get(i, user_buf, static_cast(sizeof(user_buf))))) { LOG_WARN("get weak read user list variables failed", K(ret)); - } - else if (hsr.response_.get_username().prefix_match(user_buf)){ + } else if (hsr.response_.get_username().prefix_match(user_buf)){ is_weak_read_user = true; break; }