[CP] 升级脚本python3改造
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from my_error import MyError
|
||||
import logging
|
||||
import time
|
||||
from actions import Cursor
|
||||
@ -37,9 +38,9 @@ def upgrade_syslog_level(conn, cur):
|
||||
info_cnt = result[0][0]
|
||||
if info_cnt > 0:
|
||||
actions.set_parameter(cur, "syslog_level", "WDIAG")
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logging.warn("upgrade syslog level failed!")
|
||||
raise e
|
||||
raise
|
||||
####========******####========= actions end =========####******========####
|
||||
|
||||
def query(cur, sql):
|
||||
@ -75,7 +76,7 @@ def upgrade_across_version(cur):
|
||||
results = query(cur, sql)
|
||||
if len(results) < 1 or len(results[0]) < 1:
|
||||
logging.warn("row/column cnt not match")
|
||||
raise e
|
||||
raise MyError("row/column cnt not match")
|
||||
elif results[0][0] <= 0:
|
||||
# __all_virtual_core_table doesn't exist, this cluster is upgraded from 4.0.0.0
|
||||
across_version = True
|
||||
@ -84,14 +85,14 @@ def upgrade_across_version(cur):
|
||||
tenant_ids = get_tenant_ids(cur)
|
||||
if len(tenant_ids) <= 0:
|
||||
logging.warn("tenant_ids count is unexpected")
|
||||
raise e
|
||||
raise MyError("tenant_ids count is unexpected")
|
||||
tenant_count = len(tenant_ids)
|
||||
|
||||
sql = "select count(*) from __all_virtual_core_table where column_name in ('target_data_version', 'current_data_version') and column_value = {0}".format(int_current_data_version)
|
||||
results = query(cur, sql)
|
||||
if len(results) != 1 or len(results[0]) != 1:
|
||||
logging.warn('result cnt not match')
|
||||
raise e
|
||||
raise MyError('result cnt not match')
|
||||
elif 2 * tenant_count != results[0][0]:
|
||||
logging.info('target_data_version/current_data_version not match with {0}, tenant_cnt:{1}, result_cnt:{2}'.format(current_data_version, tenant_count, results[0][0]))
|
||||
across_version = True
|
||||
@ -105,7 +106,7 @@ def upgrade_across_version(cur):
|
||||
results = query(cur, sql)
|
||||
if len(results) < 1 or len(results[0]) < 1:
|
||||
logging.warn("row/column cnt not match")
|
||||
raise e
|
||||
raise MyError("row/column cnt not match")
|
||||
elif results[0][0] == 0:
|
||||
logging.info("compatible are all matched")
|
||||
else:
|
||||
@ -124,16 +125,16 @@ def get_max_used_job_id(cur):
|
||||
max_job_id = 0
|
||||
elif (len(results) != 1 or len(results[0]) != 1):
|
||||
logging.warn("row cnt not match")
|
||||
raise e
|
||||
raise MyError("row cnt not match")
|
||||
else:
|
||||
max_job_id = results[0][0]
|
||||
|
||||
logging.info("get max_used_job_id:{0}".format(max_job_id))
|
||||
|
||||
return max_job_id
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logging.warn("failed to get max_used_job_id")
|
||||
raise e
|
||||
raise
|
||||
|
||||
def check_can_run_upgrade_job(cur, job_name):
|
||||
try:
|
||||
@ -147,10 +148,10 @@ def check_can_run_upgrade_job(cur, job_name):
|
||||
logging.info("upgrade job not created yet, should run upgrade job")
|
||||
elif (len(results) != 1 or len(results[0]) != 1):
|
||||
logging.warn("row cnt not match")
|
||||
raise e
|
||||
raise MyError("row cnt not match")
|
||||
elif ("INPROGRESS" == results[0][0]):
|
||||
logging.warn("upgrade job still running, should wait")
|
||||
raise e
|
||||
raise MyError("upgrade job still running, should wait")
|
||||
elif ("SUCCESS" == results[0][0]):
|
||||
bret = True
|
||||
logging.info("maybe upgrade job remained, can run again")
|
||||
@ -159,12 +160,12 @@ def check_can_run_upgrade_job(cur, job_name):
|
||||
logging.info("execute upgrade job failed, should run again")
|
||||
else:
|
||||
logging.warn("invalid job status: {0}".format(results[0][0]))
|
||||
raise e
|
||||
raise MyError("invalid job status: {0}".format(results[0][0]))
|
||||
|
||||
return bret
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logging.warn("failed to check if upgrade job can run")
|
||||
raise e
|
||||
raise
|
||||
|
||||
def check_upgrade_job_result(cur, job_name, timeout, max_used_job_id):
|
||||
try:
|
||||
@ -181,7 +182,7 @@ def check_upgrade_job_result(cur, job_name, timeout, max_used_job_id):
|
||||
logging.info("upgrade job not created yet")
|
||||
elif (len(results) != 1 or len(results[0]) != 4):
|
||||
logging.warn("row cnt not match")
|
||||
raise e
|
||||
raise MyError("row cnt not match")
|
||||
elif ("INPROGRESS" == results[0][0]):
|
||||
logging.info("upgrade job is still running")
|
||||
# check if rs change
|
||||
@ -193,39 +194,39 @@ def check_upgrade_job_result(cur, job_name, timeout, max_used_job_id):
|
||||
results = query(cur, sql)
|
||||
if (len(results) != 1 or len(results[0]) != 1):
|
||||
logging.warn("row/column cnt not match")
|
||||
raise e
|
||||
raise MyError("row/column cnt not match")
|
||||
elif results[0][0] == 1:
|
||||
sql = """select count(*) from oceanbase.__all_rootservice_event_history where gmt_create > '{0}' and event = 'full_rootservice'""".format(gmt_create)
|
||||
results = query(cur, sql)
|
||||
if (len(results) != 1 or len(results[0]) != 1):
|
||||
logging.warn("row/column cnt not match")
|
||||
raise e
|
||||
raise MyError("row/column cnt not match")
|
||||
elif results[0][0] > 0:
|
||||
logging.warn("rs changed, should check if upgrade job is still running")
|
||||
raise e
|
||||
raise MyError("rs changed, should check if upgrade job is still running")
|
||||
else:
|
||||
logging.info("rs[{0}:{1}] still exist, keep waiting".format(ip, port))
|
||||
else:
|
||||
logging.warn("rs changed or not exist, should check if upgrade job is still running")
|
||||
raise e
|
||||
raise MyError("rs changed or not exist, should check if upgrade job is still running")
|
||||
elif ("SUCCESS" == results[0][0]):
|
||||
logging.info("execute upgrade job successfully")
|
||||
break;
|
||||
elif ("FAILED" == results[0][0]):
|
||||
logging.warn("execute upgrade job failed")
|
||||
raise e
|
||||
raise MyError("execute upgrade job failed")
|
||||
else:
|
||||
logging.warn("invalid job status: {0}".format(results[0][0]))
|
||||
raise e
|
||||
raise MyError("invalid job status: {0}".format(results[0][0]))
|
||||
|
||||
times = times - 1
|
||||
if times == -1:
|
||||
logging.warn("""check {0} job timeout""".format(job_name))
|
||||
raise e
|
||||
raise MyError("""check {0} job timeout""".format(job_name))
|
||||
time.sleep(10)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logging.warn("failed to check upgrade job result")
|
||||
raise e
|
||||
raise
|
||||
|
||||
def run_upgrade_job(conn, cur, job_name, timeout):
|
||||
try:
|
||||
@ -252,7 +253,7 @@ def run_upgrade_job(conn, cur, job_name, timeout):
|
||||
# reset enable_ddl
|
||||
if ori_enable_ddl == 0:
|
||||
actions.set_parameter(cur, 'enable_ddl', 'False', timeout)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logging.warn("run upgrade job failed, :{0}".format(job_name))
|
||||
raise e
|
||||
raise
|
||||
logging.info("run upgrade job success, job_name:{0}".format(job_name))
|
||||
|
||||
Reference in New Issue
Block a user