From e06c03a5795e35555200d5e7bd97b3302deafc9d Mon Sep 17 00:00:00 2001 From: Eukanj827 Date: Wed, 3 Aug 2022 10:48:44 +0800 Subject: [PATCH 1/6] Update __init__.py --- src/gausskernel/dbmind/tools/cmd/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gausskernel/dbmind/tools/cmd/__init__.py b/src/gausskernel/dbmind/tools/cmd/__init__.py index a10bdc671..c7a36182d 100644 --- a/src/gausskernel/dbmind/tools/cmd/__init__.py +++ b/src/gausskernel/dbmind/tools/cmd/__init__.py @@ -13,8 +13,14 @@ import sys from .cli import DBMindRun +#To import DBMindRun method from the parent file cli - +#function name: main +#description: Get the system command parameters, pass to the DBMindRun and call this function,if an InterruptedError is reported, the program will exit( sys.exit(1)). +#arguments: None +#return value: None +#date: 2022/8/3 +#contact: 1865997821 def main() -> None: try: DBMindRun(sys.argv[1:]) From 730e66cdf019f7c17454bf61e16070b308d43397 Mon Sep 17 00:00:00 2001 From: Eukanj827 Date: Wed, 3 Aug 2022 21:00:46 +0800 Subject: [PATCH 2/6] Update config_utils.py --- .../dbmind/tools/cmd/config_utils.py | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/gausskernel/dbmind/tools/cmd/config_utils.py b/src/gausskernel/dbmind/tools/cmd/config_utils.py index e1c518186..2c2b73d36 100644 --- a/src/gausskernel/dbmind/tools/cmd/config_utils.py +++ b/src/gausskernel/dbmind/tools/cmd/config_utils.py @@ -55,7 +55,12 @@ CONFIG_OPTIONS = { 'LOG-level': ['DEBUG', 'INFO', 'WARNING', 'ERROR'] } - +#function name: check_config_validity +#description: Checks the validity of the passed parameter +#arguments: section, option, value +#return value: bool and string +#date: 2022/8/ +#contact: 1865997821 def check_config_validity(section, option, value): config_item = '%s-%s' % (section, option) # exceptional cases: @@ -87,6 +92,16 @@ def check_config_validity(section, option, value): return True, None + +#function name: load_sys_configs +#description: Create and load the modification file +#arguments: The configuration to modify +#return value: a new configuration file +#note:To facilitate the user to modify the configuration items through the +#configuration file easily, we add inline comments to the file, but we need to remove the inline comments while parsing. +#Otherwise, it will cause the read configuration items to be wrong. +#date: 2022/8/ +#contact: 1865997821 def load_sys_configs(confile): # Note: To facilitate the user to modify the configuration items through the # configuration file easily, we add inline comments to the file, but we need @@ -96,6 +111,8 @@ def load_sys_configs(confile): with open(file=confile, mode='r') as fp: configs.read_file(fp) + +# Define a class that encapsulates the modification item class ConfigWrapper(object): def __getattribute__(self, name): try: @@ -122,7 +139,7 @@ def load_sys_configs(confile): return ConfigWrapper() - +# Defines a class that updates the encapsulated modification file class ConfigUpdater: def __init__(self, filepath): self.config = ConfigParser(inline_comment_prefixes=None) @@ -170,7 +187,7 @@ class ConfigUpdater: self.fp.flush() self.fp.close() - +# Defines a class that dynamically displays a modified item class DynamicConfig: @staticmethod def get(*args, **kwargs): From 1a3fad4d43b82470cf2aa3138c66aef48e319a9c Mon Sep 17 00:00:00 2001 From: Eukanj827 Date: Wed, 3 Aug 2022 21:11:28 +0800 Subject: [PATCH 3/6] Update edbmind.py --- src/gausskernel/dbmind/tools/cmd/edbmind.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/gausskernel/dbmind/tools/cmd/edbmind.py b/src/gausskernel/dbmind/tools/cmd/edbmind.py index 35b4f90a7..a7bc5329c 100644 --- a/src/gausskernel/dbmind/tools/cmd/edbmind.py +++ b/src/gausskernel/dbmind/tools/cmd/edbmind.py @@ -43,6 +43,7 @@ except ImportError: SKIP_LIST = ('COMMENT', 'LOG') +# The global variable acts as a switch that controls whether the program runs dbmind_master_should_exit = False @@ -57,8 +58,16 @@ def _process_clean(force=False): global_vars.worker.terminate(cancel_futures=force) TimedTaskManager.stop() +#function name: signal_handler +#description: The function processes the received signal parameters, reassigns variable x according to different signals +#or calls other functions to complete the content indicated by signals +#arguments: signum, frame +#return value: bool (dbmind_master_should_exit) +#date: 2022/8/3 +#contact: 1865997821 def signal_handler(signum, frame): + # The global variable dbmind_master_should_exit can be modified in this function to continue to play a control role global dbmind_master_should_exit if signum == signal.SIGINT or signum == signal.SIGHUP: @@ -148,10 +157,12 @@ class DBMindMain(Daemon): time.sleep(1) logging.info('DBMind will close.') + # Emptying the execution pool def clean(self): if os.path.exists(self.pid_file): os.unlink(self.pid_file) - + + # Reload the execution pool and solve the error def reload(self): pid = read_dbmind_pid_file(self.pid_file) if pid > 0: From edf79014bf79dd7d1975f77181ea9cbe20a3ff50 Mon Sep 17 00:00:00 2001 From: Eukanj827 Date: Thu, 4 Aug 2022 19:16:50 +0800 Subject: [PATCH 4/6] Update controller_aop.py --- .../dbmind/tools/common/http/controller_aop.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/gausskernel/dbmind/tools/common/http/controller_aop.py b/src/gausskernel/dbmind/tools/common/http/controller_aop.py index 95be44f5e..594277216 100644 --- a/src/gausskernel/dbmind/tools/common/http/controller_aop.py +++ b/src/gausskernel/dbmind/tools/common/http/controller_aop.py @@ -27,6 +27,17 @@ def do_after(rt_result): def do_exception(exception): """Nothing""" + +#function name: around +#description: Preserve the function properties and prevent an error from terminating the program +#arguments: One or more functions +#return value: none +#note: Decorators are implemented in such a way that the function being decorated is actually another function (the function name and other properties change). +#To avoid this, Python's FuncTools package provides a decorator called wraps to remove such side effects. +#When writing a decorator, it is a good idea to wrap FuncTools before implementing it. +#It preserves the name and properties of the original function +#date: 2022/8/4 +#contact: 1865997821 def around(func, *args, **kw): @wraps(func) def wrapper(): From cf86dd46f5c398f3939fcb9c3bd4e5a276f06d1a Mon Sep 17 00:00:00 2001 From: Eukanj827 Date: Thu, 4 Aug 2022 19:58:05 +0800 Subject: [PATCH 5/6] Update alarm.py --- src/gausskernel/dbmind/tools/common/types/alarm.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gausskernel/dbmind/tools/common/types/alarm.py b/src/gausskernel/dbmind/tools/common/types/alarm.py index 3c4a8a73d..7ebba80d9 100644 --- a/src/gausskernel/dbmind/tools/common/types/alarm.py +++ b/src/gausskernel/dbmind/tools/common/types/alarm.py @@ -15,7 +15,11 @@ from typing import Optional, Iterable, Union from .root_cause import RootCause from .enumerations import ALARM_TYPES, ALARM_LEVEL - +#Define an Alarm class that takes the error parameters entered by the user and displays the error content and cause +#method:Display the error content and suggestions, and retrieve suggestions provided by the system. If there are no suggestions, return “ no suggestions” +#note:The property decorator turns a method into a property call.(root_causes、suggestions) +#date:2022/8/4 +#contact:18365997821 class Alarm: def __init__(self, host: Union[str], From c7e4a7454454aefe2f09eee9145b00f8d268347b Mon Sep 17 00:00:00 2001 From: Eukanj827 Date: Thu, 4 Aug 2022 20:55:05 +0800 Subject: [PATCH 6/6] Update misc.py --- src/gausskernel/dbmind/tools/common/types/misc.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gausskernel/dbmind/tools/common/types/misc.py b/src/gausskernel/dbmind/tools/common/types/misc.py index fa7767d27..05060be83 100644 --- a/src/gausskernel/dbmind/tools/common/types/misc.py +++ b/src/gausskernel/dbmind/tools/common/types/misc.py @@ -12,7 +12,11 @@ # See the Mulan PSL v2 for more details. from .root_cause import RootCause - +#Define anSlowQuery class thatSlow query accepts user input commands and performs operations on the database +#method:Display the error content and suggestions, and retrieve suggestions provided by the system. If there are no suggestions, return “ no suggestions” +#note:The property decorator turns a method into a property call.(root_causes、suggestions) +#date:2022/8/4 +#contact:18365997821 class SlowQuery: def __init__(self, db_host, db_port, db_name, schema_name, query, start_timestamp, duration_time, hit_rate=None, fetch_rate=None, cpu_time=None, data_io_time=None, template_id=None, sort_count=None,