From 66e82742b44bd41c517e6bf8fd98ec0469cf557a Mon Sep 17 00:00:00 2001 From: ZhenNan0 Date: Mon, 4 Mar 2024 07:49:37 +0000 Subject: [PATCH] [CP] Fix bug of enable_rebalance in upgrade script --- tools/upgrade/actions.py | 13 +++++++---- tools/upgrade/special_upgrade_action_pre.py | 8 +++++++ tools/upgrade/upgrade_post.py | 26 +++++++++++++++------ tools/upgrade/upgrade_post_checker.py | 5 ++-- tools/upgrade/upgrade_pre.py | 26 +++++++++++++++------ 5 files changed, 57 insertions(+), 21 deletions(-) diff --git a/tools/upgrade/actions.py b/tools/upgrade/actions.py index 5b61cd968..cc09aba52 100755 --- a/tools/upgrade/actions.py +++ b/tools/upgrade/actions.py @@ -147,10 +147,12 @@ def set_default_timeout_by_tenant(cur, timeout, timeout_per_tenant, min_timeout) return timeout -def set_tenant_parameter(cur, parameter, value, timeout = 0): +def set_tenant_parameter(cur, parameter, value, timeout = 0, only_sys_tenant = False): tenants_list = [] - if get_min_cluster_version(cur) < get_version("4.2.1.0"): + if only_sys_tenant: + tenants_list = ['sys'] + elif get_min_cluster_version(cur) < get_version("4.2.1.0"): tenants_list = ['all'] else: tenants_list = ['sys', 'all_user', 'all_meta'] @@ -166,7 +168,7 @@ def set_tenant_parameter(cur, parameter, value, timeout = 0): set_session_timeout(cur, 10) - wait_parameter_sync(cur, True, parameter, value, timeout) + wait_parameter_sync(cur, True, parameter, value, timeout, only_sys_tenant) def get_ori_enable_ddl(cur, timeout): ori_value_str = fetch_ori_enable_ddl(cur) @@ -250,10 +252,11 @@ def check_parameter(cur, is_tenant_config, key, value): bret = False return bret -def wait_parameter_sync(cur, is_tenant_config, key, value, timeout): +def wait_parameter_sync(cur, is_tenant_config, key, value, timeout, only_sys_tenant = False): table_name = "GV$OB_PARAMETERS" if not is_tenant_config else "__all_virtual_tenant_parameter_info" + extra_sql = " and tenant_id = 1" if is_tenant_config and only_sys_tenant else "" sql = """select count(*) as cnt from oceanbase.{0} - where name = '{1}' and value != '{2}'""".format(table_name, key, value) + where name = '{1}' and value != '{2}'{3}""".format(table_name, key, value, extra_sql) wait_timeout = 0 query_timeout = 0 diff --git a/tools/upgrade/special_upgrade_action_pre.py b/tools/upgrade/special_upgrade_action_pre.py index 3edb96daf..d8e68be6c 100755 --- a/tools/upgrade/special_upgrade_action_pre.py +++ b/tools/upgrade/special_upgrade_action_pre.py @@ -41,6 +41,14 @@ def do_special_upgrade(conn, cur, timeout, user, passwd): if actions.get_version(current_version) < actions.get_version('4.2.0.0')\ and actions.get_version(target_version) >= actions.get_version('4.2.0.0'): actions.set_tenant_parameter(cur, '_bloom_filter_enabled', 'False', timeout) + # Disable enable_rebalance of sys tenant to avoid automatic unit migration + # regardless of the same version upgrade or cross-version upgrade. + # enable_rebalance is changed from cluster level to tenant level since 4.2. + if actions.get_version(current_version) < actions.get_version('4.2.0.0'): + actions.set_parameter(cur, 'enable_rebalance', 'False', timeout) + else: + only_sys_tenant = True + actions.set_tenant_parameter(cur, 'enable_rebalance', 'False', timeout, only_sys_tenant) ####========******####======== actions begin ========####******========#### return diff --git a/tools/upgrade/upgrade_post.py b/tools/upgrade/upgrade_post.py index 127e2c6c6..c621999bc 100755 --- a/tools/upgrade/upgrade_post.py +++ b/tools/upgrade/upgrade_post.py @@ -155,10 +155,12 @@ # # return timeout # -#def set_tenant_parameter(cur, parameter, value, timeout = 0): +#def set_tenant_parameter(cur, parameter, value, timeout = 0, only_sys_tenant = False): # # tenants_list = [] -# if get_min_cluster_version(cur) < get_version("4.2.1.0"): +# if only_sys_tenant: +# tenants_list = ['sys'] +# elif get_min_cluster_version(cur) < get_version("4.2.1.0"): # tenants_list = ['all'] # else: # tenants_list = ['sys', 'all_user', 'all_meta'] @@ -174,7 +176,7 @@ # # set_session_timeout(cur, 10) # -# wait_parameter_sync(cur, True, parameter, value, timeout) +# wait_parameter_sync(cur, True, parameter, value, timeout, only_sys_tenant) # #def get_ori_enable_ddl(cur, timeout): # ori_value_str = fetch_ori_enable_ddl(cur) @@ -258,10 +260,11 @@ # bret = False # return bret # -#def wait_parameter_sync(cur, is_tenant_config, key, value, timeout): +#def wait_parameter_sync(cur, is_tenant_config, key, value, timeout, only_sys_tenant = False): # table_name = "GV$OB_PARAMETERS" if not is_tenant_config else "__all_virtual_tenant_parameter_info" +# extra_sql = " and tenant_id = 1" if is_tenant_config and only_sys_tenant else "" # sql = """select count(*) as cnt from oceanbase.{0} -# where name = '{1}' and value != '{2}'""".format(table_name, key, value) +# where name = '{1}' and value != '{2}'{3}""".format(table_name, key, value, extra_sql) # # wait_timeout = 0 # query_timeout = 0 @@ -1347,6 +1350,14 @@ # if actions.get_version(current_version) < actions.get_version('4.2.0.0')\ # and actions.get_version(target_version) >= actions.get_version('4.2.0.0'): # actions.set_tenant_parameter(cur, '_bloom_filter_enabled', 'False', timeout) +# # Disable enable_rebalance of sys tenant to avoid automatic unit migration +# # regardless of the same version upgrade or cross-version upgrade. +# # enable_rebalance is changed from cluster level to tenant level since 4.2. +# if actions.get_version(current_version) < actions.get_version('4.2.0.0'): +# actions.set_parameter(cur, 'enable_rebalance', 'False', timeout) +# else: +# only_sys_tenant = True +# actions.set_tenant_parameter(cur, 'enable_rebalance', 'False', timeout, only_sys_tenant) # #####========******####======== actions begin ========####******========#### # return @@ -2958,9 +2969,10 @@ #def enable_ddl(cur, timeout): # actions.set_parameter(cur, 'enable_ddl', 'True', timeout) # -## 5 打开rebalance +## 5 打开sys租户rebalance #def enable_rebalance(cur, timeout): -# actions.set_parameter(cur, 'enable_rebalance', 'True', timeout) +# only_sys_tenant = True +# actions.set_tenant_parameter(cur, 'enable_rebalance', 'True', timeout, only_sys_tenant) # ## 6 打开rereplication #def enable_rereplication(cur, timeout): diff --git a/tools/upgrade/upgrade_post_checker.py b/tools/upgrade/upgrade_post_checker.py index 2a6e56b87..21175cb60 100755 --- a/tools/upgrade/upgrade_post_checker.py +++ b/tools/upgrade/upgrade_post_checker.py @@ -106,9 +106,10 @@ def check_root_inspection(cur, query_cur, timeout): def enable_ddl(cur, timeout): actions.set_parameter(cur, 'enable_ddl', 'True', timeout) -# 5 打开rebalance +# 5 打开sys租户rebalance def enable_rebalance(cur, timeout): - actions.set_parameter(cur, 'enable_rebalance', 'True', timeout) + only_sys_tenant = True + actions.set_tenant_parameter(cur, 'enable_rebalance', 'True', timeout, only_sys_tenant) # 6 打开rereplication def enable_rereplication(cur, timeout): diff --git a/tools/upgrade/upgrade_pre.py b/tools/upgrade/upgrade_pre.py index bff01f71a..4edf9da23 100755 --- a/tools/upgrade/upgrade_pre.py +++ b/tools/upgrade/upgrade_pre.py @@ -155,10 +155,12 @@ # # return timeout # -#def set_tenant_parameter(cur, parameter, value, timeout = 0): +#def set_tenant_parameter(cur, parameter, value, timeout = 0, only_sys_tenant = False): # # tenants_list = [] -# if get_min_cluster_version(cur) < get_version("4.2.1.0"): +# if only_sys_tenant: +# tenants_list = ['sys'] +# elif get_min_cluster_version(cur) < get_version("4.2.1.0"): # tenants_list = ['all'] # else: # tenants_list = ['sys', 'all_user', 'all_meta'] @@ -174,7 +176,7 @@ # # set_session_timeout(cur, 10) # -# wait_parameter_sync(cur, True, parameter, value, timeout) +# wait_parameter_sync(cur, True, parameter, value, timeout, only_sys_tenant) # #def get_ori_enable_ddl(cur, timeout): # ori_value_str = fetch_ori_enable_ddl(cur) @@ -258,10 +260,11 @@ # bret = False # return bret # -#def wait_parameter_sync(cur, is_tenant_config, key, value, timeout): +#def wait_parameter_sync(cur, is_tenant_config, key, value, timeout, only_sys_tenant = False): # table_name = "GV$OB_PARAMETERS" if not is_tenant_config else "__all_virtual_tenant_parameter_info" +# extra_sql = " and tenant_id = 1" if is_tenant_config and only_sys_tenant else "" # sql = """select count(*) as cnt from oceanbase.{0} -# where name = '{1}' and value != '{2}'""".format(table_name, key, value) +# where name = '{1}' and value != '{2}'{3}""".format(table_name, key, value, extra_sql) # # wait_timeout = 0 # query_timeout = 0 @@ -1347,6 +1350,14 @@ # if actions.get_version(current_version) < actions.get_version('4.2.0.0')\ # and actions.get_version(target_version) >= actions.get_version('4.2.0.0'): # actions.set_tenant_parameter(cur, '_bloom_filter_enabled', 'False', timeout) +# # Disable enable_rebalance of sys tenant to avoid automatic unit migration +# # regardless of the same version upgrade or cross-version upgrade. +# # enable_rebalance is changed from cluster level to tenant level since 4.2. +# if actions.get_version(current_version) < actions.get_version('4.2.0.0'): +# actions.set_parameter(cur, 'enable_rebalance', 'False', timeout) +# else: +# only_sys_tenant = True +# actions.set_tenant_parameter(cur, 'enable_rebalance', 'False', timeout, only_sys_tenant) # #####========******####======== actions begin ========####******========#### # return @@ -2958,9 +2969,10 @@ #def enable_ddl(cur, timeout): # actions.set_parameter(cur, 'enable_ddl', 'True', timeout) # -## 5 打开rebalance +## 5 打开sys租户rebalance #def enable_rebalance(cur, timeout): -# actions.set_parameter(cur, 'enable_rebalance', 'True', timeout) +# only_sys_tenant = True +# actions.set_tenant_parameter(cur, 'enable_rebalance', 'True', timeout, only_sys_tenant) # ## 6 打开rereplication #def enable_rereplication(cur, timeout):