Exemplo n.º 1
0
    def check_connection_params(self):
        # Check whether the binary files of the database can be located through environment variables.
        try:
            self.exec_command_on_host("which gsql")
            self.exec_command_on_host("which gaussdb")
            self.exec_command_on_host("which gs_guc")
            self.exec_command_on_host("which gs_ctl")
        except ExecutionError as e:
            logging.exception("An exception occurred while checking connection parameters: %s", e)
            raise OptionError("The parameters about SSH login user are incorrect. Please check.\n"
                              "Hint: The binary file path of the database cannot be obtained after the login."
                              "Please ensure that the paths of tools such as gsql and gs_ctl are added to environment "
                              "variables ($PATH).") from None

        # Check whether the third-party libraries can be properly loaded.
        try:
            self.exec_command_on_host("gaussdb --version")
            self.exec_command_on_host("gsql --version")
        except ExecutionError as e:
            logging.exception("An exception occurred while checking connection parameters: %s", e)
            raise DBStatusError("The database environment is incorrectly configured. "
                                "login to the database host as the user and check whether "
                                "the database environment can be used properly. "
                                "For example, check environment variables $LD_LIBRARY_PATH.") from None

        # Check whether the database is started.
        # And check whether the user name and password are correct.
        try:
            if not self.is_alive():
                raise DBStatusError("Failed to login to the database. "
                                    "Check whether the database is started. ")

            # Get database instance pid and data_path.
            _, self.data_path = self.exec_statement(
                "SELECT datapath FROM pg_node_env;"
            )
        except ExecutionError as e:
            logging.exception("An exception occurred while checking connection parameters: %s", e)
            raise DBStatusError("Failed to login to the database. "
                                "Check whether the user name or password is correct, "
                                "and whether the database information passed to the X-Tuner is correct.") from None

        # Check whether the current user has sufficient permission to perform tuning.
        try:
            self.exec_statement("select * from pg_user;")
        except ExecutionError as e:
            logging.exception("An exception occurred while checking connection parameters: %s", e)
            raise DBStatusError("The current database user may not have the permission to tune best_knobs. "
                                "Please assign the administrator permission temporarily so that you can "
                                "obtain more information from the database.") from None
Exemplo n.º 2
0
 def check_positive_integer(*opts):
     for opt in opts:
         if config[opt] <= 0:
             raise OptionError(positive_integer_msg % opt)
Exemplo n.º 3
0
def get_config(filepath):
    if not os.path.exists(filepath):
        print("FATAL: Not found the configuration file %s." % filepath,
              file=sys.stderr)
        return

    if not os.access(filepath, os.R_OK):
        print("FATAL: Not have permission to read the configuration file %s." %
              filepath,
              file=sys.stderr)
        return

    cp = configparser.ConfigParser(inline_comment_prefixes=('#', ';', "'"))
    cp.read(filepath)

    config = dict()
    for section in cp.sections():
        for option, value in cp.items(section):
            config.setdefault(option, value)

    # Check configs.
    null_error_msg = 'The configuration option %s is null. Please set a specific value.'
    invalid_opt_msg = 'The configuration option %s is invalid. Please set one of %s.'
    positive_integer_msg = 'The configuration option %s must be a positive integer greater than 0.'

    # Section Master:
    for name in ('logfile', 'recorder_file', 'tune_strategy'):
        if cp['Master'].get(name, '').strip() == '':
            raise OptionError(null_error_msg % name)

    tune_strategy_opts = ['rl', 'gop', 'auto']
    tune_strategy = cp['Master'].get('tune_strategy')
    if tune_strategy not in tune_strategy_opts:
        raise OptionError(invalid_opt_msg %
                          ('tune_strategy', tune_strategy_opts))

    config['verbose'] = cp['Master'].getboolean('verbose', fallback=True)
    config['drop_cache'] = cp['Master'].getboolean('drop_cache',
                                                   fallback=False)
    config['used_mem_penalty_term'] = cp['Master'].getfloat(
        'used_mem_penalty_term')

    # Section Benchmark:
    benchmarks = []
    benchmark_dir = os.path.join(os.path.dirname(__file__), 'benchmark')
    for root_dir, sub_dir, files in os.walk(benchmark_dir):
        if os.path.basename(root_dir) == 'benchmark':
            benchmarks = files
            break

    benchmark_script = cp['Benchmark'].get('benchmark_script', '')
    if benchmark_script.rstrip('.py') + '.py' not in benchmarks:
        raise OptionError(invalid_opt_msg % ('benchmark_script', benchmarks))
    config['benchmark_path'] = cp['Benchmark'].get('benchmark_path', '')
    config['benchmark_cmd'] = cp['Benchmark'].get('benchmark_cmd', '')

    # Section Knobs
    scenario_opts = ['auto', 'ap', 'tp', 'htap']
    if cp['Knobs'].get('scenario', '') not in scenario_opts:
        raise OptionError(invalid_opt_msg % ('scenario', scenario_opts))

    # Section RL and GOP
    def check_positive_integer(*opts):
        for opt in opts:
            if config[opt] <= 0:
                raise OptionError(positive_integer_msg % opt)

    if tune_strategy in ('auto', 'rl'):
        for name in cp['Reinforcement Learning']:
            if name.strip() == '':
                raise OptionError(null_error_msg % name)
        if cp['Reinforcement Learning'].get('rl_algorithm', '') != 'ddpg':
            raise OptionError(invalid_opt_msg % ('rl_algorithm', 'ddpg'))

        config['rl_steps'] = cp['Reinforcement Learning'].getint('rl_steps')
        config['max_episode_steps'] = cp['Reinforcement Learning'].getint(
            'max_episode_steps')
        config['test_episode'] = cp['Reinforcement Learning'].getint(
            'test_episode')
        check_positive_integer('rl_steps', 'max_episode_steps', 'test_episode')

    if tune_strategy in ('auto', 'gop'):
        for name in cp['Gloabal Optimization Algorithm']:
            if name.strip() == '':
                raise OptionError(null_error_msg % name)

        gop_algorithm_opts = ['bayes', 'pso']
        if cp['Gloabal Optimization Algorithm'].get(
                'gop_algorithm', '') not in gop_algorithm_opts:
            raise OptionError(invalid_opt_msg %
                              ('gop_algorithm', gop_algorithm_opts))

        config['max_iterations'] = cp['Gloabal Optimization Algorithm'].getint(
            'max_iterations')
        config['particle_nums'] = cp['Gloabal Optimization Algorithm'].getint(
            'particle_nums')
        check_positive_integer('max_iterations', 'particle_nums')

    return config