From ec268543eb2bf5c6344e476c26d551d32424d5ab Mon Sep 17 00:00:00 2001 From: zhang_xubo <2578876417@qq.com> Date: Sat, 2 Nov 2024 18:05:14 +0800 Subject: [PATCH] =?UTF-8?q?3.0=E5=8E=8B=E7=BC=A9=E8=A1=A8=E9=99=90?= =?UTF-8?q?=E5=88=B6=E5=8D=87=E7=BA=A7=E5=88=B0=E6=96=B0=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/gs_upgradectl | 3 ++ script/impl/upgrade/UpgradeImpl.py | 57 ++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/script/gs_upgradectl b/script/gs_upgradectl index 88b6265..93dfe1a 100644 --- a/script/gs_upgradectl +++ b/script/gs_upgradectl @@ -119,6 +119,9 @@ class Upgrade(ParallelBaseOM): self.upgradePhaseInfoPath = "" self.upgrade_action = "" self.upgrade_package = "" + + # check if upgrade from 3.0.* version with compress table. + self.check_compresstbl_compat = True def usage(self): """ diff --git a/script/impl/upgrade/UpgradeImpl.py b/script/impl/upgrade/UpgradeImpl.py index 2aebe8d..e41123e 100644 --- a/script/impl/upgrade/UpgradeImpl.py +++ b/script/impl/upgrade/UpgradeImpl.py @@ -408,6 +408,58 @@ class UpgradeImpl: if self.context.is_grey_upgrade: self.getOneDNInst(checkNormal=True) self.checkUpgradeMode() + self.check_compress_tbl_compatibility() + + + def check_compress_tbl_compatibility(self): + """ + Check if upgrade from 3.0.* version with compressed table. + :return: + + Version 3.0 compression table is not compatible with other versions, it will + be unavailability after upgraded. + We will force the upgrade to exit until the compressed table is compatible + with version 3.0. + """ + + UNCOMPAT_VERSION_PRE = "3.0." + if not self.context.check_compresstbl_compat or \ + not self.context.oldClusterVersion.startswith(UNCOMPAT_VERSION_PRE): + return + + dbnames_sql = "select datname from pg_database " \ + "where datname not in ('template0', 'template1');" + relopts_sql = "select relname,reloptions from pg_class where reloptions::text ~ 'compress';" + + (status, output) = self.execSqlCommandInPrimaryDN(dbnames_sql) + if status != 0 or output == "": + raise Exception("Failed query database names: Status: {0}. Output: {1}".format(status, + output)) + db_list = output.split("\n") + for dbname in db_list: + self.context.logger.debug("[check_compress_tbl]check database %s" % dbname) + (status, output) = self.execSqlCommandInPrimaryDN(relopts_sql, database=dbname) + if output != "": + reloptinfo_list = output.split("\n") + for relinfo in reloptinfo_list: + compressed = self.check_tbl_compressed(relinfo) + if compressed: + self.context.logger.error("ERROR: Database [%s] has compressed table, reloptions [%s]" % + (dbname, relinfo)) + self.context.logger.warn("WARNNING: Cannot upgrade from %s to %s with compressed tables, " \ + "Which are incompatible." % + (self.context.oldClusterVersion, self.context.newClusterVersion)) + sys.exit(1) + + def check_tbl_compressed(self, reloptinfo): + tblinfoarr = reloptinfo.split("|") + if len(tblinfoarr) != 2: + return + relopt = tblinfoarr[1] + if re.search(r"compresstype=[1-2]{1}", relopt): + return True + return False + def checkReadOnly(self): """ @@ -7519,7 +7571,8 @@ END;""" else: return False - def execSqlCommandInPrimaryDN(self, sql, retryTime=3, execHost=None, mode="primary"): + def execSqlCommandInPrimaryDN(self, sql, retryTime=3, execHost=None, mode="primary", + database=DefaultValue.DEFAULT_DB_NAME): """ execute sql on primary dn :return: @@ -7536,7 +7589,7 @@ END;""" (status, output) = ClusterCommand.remoteSQLCommand(sql, self.context.user, execHost.hostname, execHost.port, False, - DefaultValue.DEFAULT_DB_NAME, + database, IsInplaceUpgrade=True, maintenance_mode=mode) self.context.logger.debug("Exec sql result " -- Gitee