From 2cee936a779bece2cae6883095fab22e9eb80df7 Mon Sep 17 00:00:00 2001 From: liuheng Date: Sat, 19 Apr 2025 11:46:38 +0800 Subject: [PATCH] =?UTF-8?q?fix=20gs=5Fsdr=E6=A3=80=E6=B5=8Bstart=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E9=87=8D=E5=85=A5=E6=97=B6=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?-f=E5=8F=82=E6=95=B0=E5=BC=BA=E5=88=B6=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=8F=AF=E9=87=8D=E5=85=A5=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../params_handler.py | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/script/impl/streaming_disaster_recovery/params_handler.py b/script/impl/streaming_disaster_recovery/params_handler.py index cfc84cfd..7497715b 100644 --- a/script/impl/streaming_disaster_recovery/params_handler.py +++ b/script/impl/streaming_disaster_recovery/params_handler.py @@ -30,6 +30,8 @@ from impl.streaming_disaster_recovery.streaming_constants import StreamingConsta from gspylib.common.DbClusterInfo import dbClusterInfo from gspylib.common.ErrorCode import ErrorCode from base_utils.security.security_checker import SecurityChecker, ValidationError +from base_utils.os.env_util import EnvUtil +from base_utils.os.user_util import UserUtil from domain_utils.cluster_file.version_info import VersionInfo @@ -160,6 +162,7 @@ General options: -W Disaster recovery user password. -X Path of the XML configuration file. -l Path of log file. + -f Force remove the last time start process file. --json Path of params file for streaming options. --time-out=SECS Maximum waiting time when Main standby connect to the primary dn, default value is 1200s. @@ -207,6 +210,8 @@ class ParamsHandler(object): help='time out.') parser.add_option("-l", dest='logFile', type='string', help='Path of log file.') + parser.add_option("-f", dest='force', action='store_true', + help='-f|Force remove the last time start process file.') return parser def __print_usage(self): @@ -269,6 +274,45 @@ class ParamsHandler(object): raise ValidationError(ErrorCode.GAUSS_500["GAUSS_50004"] % "--time-out") self.params.waitingTimeout = int(self.params.timeout) + def __force_remove_step_file(self): + """ + Remove the last process file + """ + if not self.params.force: + return + self.logger.debug("remove the last process file on all connected nodes.") + user = UserUtil.getUserInfo().get("name") + pg_host = EnvUtil.getEnvironmentParameterValue("PGHOST", user) + streaming_file_dir = os.path.join(pg_host, StreamingConstants.STREAMING_FILES_DIR) + self.__do_remove_step_file(streaming_file_dir) + self.logger.debug("Successfully remove the last process file on all connected nodes.") + + def __do_remove_step_file(self, streaming_file_dir): + """ + remove step file + """ + if not os.path.isdir(streaming_file_dir): + self.logger.debug(f"Invalid directory: {streaming_file_dir}") + return + + task_file_map = { + StreamingConstants.ACTION_START: ("start_primary", "start_standby") + } + + file_keys = task_file_map.get(self.params.task) + if not file_keys: + self.logger.logExit(f"Unknown task: {self.params.task}") + return + + for key in file_keys: + file_path = os.path.realpath(os.path.join(streaming_file_dir, StreamingConstants.STREAMING_STEP_FILES.get(key))) + try: + if os.path.exists(file_path): + os.remove(file_path) + self.logger.debug(f"Removed file: {file_path}") + except Exception as e: + self.logger.logExit(f"Failed to remove file {file_path}: {str(e)}") + def __parse_args(self): """ Parse arguments @@ -277,6 +321,7 @@ class ParamsHandler(object): self.params, _ = parser.parse_args() self.__print_usage() self.__print_version_info() + self.__force_remove_step_file() if not hasattr(self.params, 'task') or not self.params.task: raise ValidationError(ErrorCode.GAUSS_500["GAUSS_50001"] % 't' + ".") if self.params.task not in StreamingConstants.STREAMING_JSON_PARAMS.keys(): -- Gitee