diff --git a/storage/ctc/ctc_mysql_proxy.cc b/storage/ctc/ctc_mysql_proxy.cc index 92a568a66178dcc3c92625dc309ba44f9c8d1d8e..a7546fc28569bdbdd1e8199d4814b36386404dd6 100644 --- a/storage/ctc/ctc_mysql_proxy.cc +++ b/storage/ctc/ctc_mysql_proxy.cc @@ -52,6 +52,8 @@ using namespace std; +__attribute__((visibility("default"))) mutex m_ctc_cluster_role_mutex; +__attribute__((visibility("default"))) int32_t ctc_cluster_role = (int32_t)dis_cluster_role::DEFAULT; struct ctc_mysql_conn_info { MYSQL* conn; set> table_lock_info; // 连接上已存在的表锁 (db, table) @@ -455,6 +457,34 @@ __attribute__((visibility("default"))) int ctc_ddl_execute_set_opt(uint32_t thd_ return ret; } +__attribute__((visibility("default"))) void ctc_set_mysql_read_only() { + ctc_log_system("[Disaster Recovecy] starting or initializing"); + super_read_only = true; + read_only = true; + opt_readonly = true; + ctc_log_system("[Disaster Recovery] set super_read_only = true."); +} + +__attribute__((visibility("default"))) void ctc_reset_mysql_read_only() { + ctc_log_system("[Disaster Recovecy] starting or initializing"); + super_read_only = false; + read_only = false; + opt_readonly = false; + ctc_log_system("[Disaster Recovery] set super_read_only = false."); +} + +__attribute__((visibility("default"))) int ctc_set_cluster_role_by_cantian(bool is_slave) { + lock_guard lock(m_ctc_mysql_proxy_mutex); + if (is_slave) { + ctc_cluster_role = (int32_t)dis_cluster_role::STANDBY; + ctc_set_mysql_read_only(); + } else { + ctc_cluster_role = (int32_t)dis_cluster_role::PRIMARY; + ctc_reset_mysql_read_only(); + } + return 0; +} + static int ctc_ddl_get_lock(MYSQL *curr_conn, const uint64_t &conn_map_key, const char *lock_name, int *err_code) { uchar digest[MD5_HASH_SIZE]; compute_md5_hash(pointer_cast(digest), lock_name, strlen(lock_name)); diff --git a/storage/ctc/ctc_srv.h b/storage/ctc/ctc_srv.h index 9918bd9821a2a304205ead94befc0f4880a463a4..82fcd400655c35dcb543886ffcd783129acd0c48 100644 --- a/storage/ctc/ctc_srv.h +++ b/storage/ctc/ctc_srv.h @@ -719,6 +719,8 @@ int ctc_broadcast_mysql_dd_invalidate(ctc_handler_t *tch, ctc_invalidate_broadca /* Disaster Recovery Related Interface*/ int ctc_set_cluster_role_by_cantian(bool is_slave); +void ctc_set_mysql_read_only(); +void ctc_reset_mysql_read_only(); int ctc_record_sql_for_cantian(ctc_handler_t *tch, ctc_ddl_broadcast_request *broadcast_req, bool allow_fail); diff --git a/storage/ctc/ha_ctc.cc b/storage/ctc/ha_ctc.cc index 722771d9ad94a7b397819b2247236bc256607491..1d030f372affbc3d7aaa4d56e6d3ad9b70815696 100644 --- a/storage/ctc/ha_ctc.cc +++ b/storage/ctc/ha_ctc.cc @@ -180,8 +180,8 @@ int32_t ctc_metadata_normalization = (int32_t)metadata_switchs::DEFAULT; static MYSQL_SYSVAR_INT(metadata_normalization, ctc_metadata_normalization, PLUGIN_VAR_READONLY, "Option for Mysql-Cantian metadata normalization.", nullptr, nullptr, -1, -1, 3, 0); -static mutex m_ctc_cluster_role_mutex; -int32_t ctc_cluster_role = (int32_t)dis_cluster_role::DEFAULT; +extern int32_t ctc_cluster_role; +extern mutex m_ctc_cluster_role_mutex; static MYSQL_SYSVAR_INT(cluster_role, ctc_cluster_role, PLUGIN_VAR_READONLY, "flag for Disaster Recovery Cluster Role.", nullptr, nullptr, -1, -1, 2, 0); @@ -4398,34 +4398,6 @@ static bool ctc_show_status(handlerton *, THD *thd, stat_print_fn *stat_print, e return false; } -void ctc_set_mysql_read_only() { - ctc_log_system("[Disaster Recovecy] starting or initializing"); - super_read_only = true; - read_only = true; - opt_readonly = true; - ctc_log_system("[Disaster Recovery] set super_read_only = true."); -} - -void ctc_reset_mysql_read_only() { - ctc_log_system("[Disaster Recovecy] starting or initializing"); - super_read_only = false; - read_only = false; - opt_readonly = false; - ctc_log_system("[Disaster Recovery] set super_read_only = false."); -} - -__attribute__((visibility("default"))) int ctc_set_cluster_role_by_cantian(bool is_slave) { - lock_guard lock(m_ctc_cluster_role_mutex); - if (is_slave) { - ctc_cluster_role = (int32_t)dis_cluster_role::STANDBY; - ctc_set_mysql_read_only(); - } else { - ctc_cluster_role = (int32_t)dis_cluster_role::PRIMARY; - ctc_reset_mysql_read_only(); - } - return 0; -} - bool is_single_run_mode() { #ifndef WITH_CANTIAN diff --git a/storage/ctc/ha_ctc.h b/storage/ctc/ha_ctc.h index 141126fed0c6cf9f019c5c55f5c12d2317e87c15..7c1de74932863fd4b22fbfb38eab531a7f3f389d 100644 --- a/storage/ctc/ha_ctc.h +++ b/storage/ctc/ha_ctc.h @@ -1106,8 +1106,6 @@ bool is_starting(); bool ctc_is_temporary(const dd::Table *table_def); int32_t ctc_get_cluster_role(); -void ctc_set_mysql_read_only(); -void ctc_reset_mysql_read_only(); int alloc_str_mysql_mem(ctc_cbo_stats_t *cbo_stats, uint32_t part_num, TABLE *table); void free_columns_cbo_stats(ctc_cbo_stats_column_t *ctc_cbo_stats_columns, bool *is_str_first_addr, TABLE *table);