From d20be8922d51f5ea12e50c9508512ac0d25d2272 Mon Sep 17 00:00:00 2001 From: Jean Christophe Roques Date: Mon, 10 Jun 2024 16:54:57 +0200 Subject: [PATCH] default mariadb plugins directory is configurable and set by default according to the os --- .github/scripts/collect-prepare-test-robot.sh | 4 ++-- broker/CMakeLists.txt | 5 ++++- .../com/centreon/broker/sql/database_config.hh | 8 ++++++++ .../centreon/broker/sql/mysql_connection.hh | 1 + broker/core/sql/src/database_config.cc | 18 ++++++++++++++---- broker/core/sql/src/mysql_connection.cc | 7 +++++++ 6 files changed, 36 insertions(+), 7 deletions(-) diff --git a/.github/scripts/collect-prepare-test-robot.sh b/.github/scripts/collect-prepare-test-robot.sh index 71a070bb091..25e9f02e5b0 100755 --- a/.github/scripts/collect-prepare-test-robot.sh +++ b/.github/scripts/collect-prepare-test-robot.sh @@ -30,8 +30,8 @@ if [ $database_type == 'mysql' ]; then sleep 5 echo "########################### Init centreon database ############################" - mysql -e "CREATE USER IF NOT EXISTS 'centreon'@'localhost' IDENTIFIED WITH mysql_native_password BY 'centreon'" - mysql -e "CREATE USER IF NOT EXISTS 'root_centreon'@'localhost' IDENTIFIED WITH mysql_native_password BY 'centreon'" + mysql -e "CREATE USER IF NOT EXISTS 'centreon'@'localhost' IDENTIFIED BY 'centreon'" + mysql -e "CREATE USER IF NOT EXISTS 'root_centreon'@'localhost' IDENTIFIED BY 'centreon'" else echo "########################### Start MariaDB ######################################" if [ "$distrib" = "ALMALINUX" ]; then diff --git a/broker/CMakeLists.txt b/broker/CMakeLists.txt index aa6ab735390..0f4cc9f6a32 100644 --- a/broker/CMakeLists.txt +++ b/broker/CMakeLists.txt @@ -66,12 +66,15 @@ endif() if(OS_DISTRIBUTOR STREQUAL "Debian" OR OS_DISTRIBUTOR STREQUAL "Ubuntu") message(STATUS "deb based os") add_definitions("-DMYSQL_SOCKET=\"/var/run/mysqld/mysqld.sock\"") + add_definitions("-DDEFAULT_MARIADB_EXTENSION_DIR=\"/usr/lib/x86_64-linux-gnu/libmariadb3/plugin\"") elseif(OS_DISTRIBUTOR STREQUAL "CentOS" OR OS_DISTRIBUTOR STREQUAL "RedHat") message(STATUS "rpm based os") add_definitions("-DMYSQL_SOCKET=\"/var/lib/mysql/mysql.sock\"") + add_definitions("-DDEFAULT_MARIADB_EXTENSION_DIR=\"/usr/lib64/mysql/plugin\"") else() message(STATUS "other os: ${OS_DISTRIBUTOR}") - add_definitions("-DMYSQL_SOCKET=/tmp/mysql.sock") + add_definitions("-DMYSQL_SOCKET=\"/tmp/mysql.sock\"") + add_definitions("-DDEFAULT_MARIADB_EXTENSION_DIR=\"/usr/lib/x86_64-linux-gnu/libmariadb3/plugin\"") endif() include_directories( diff --git a/broker/core/sql/inc/com/centreon/broker/sql/database_config.hh b/broker/core/sql/inc/com/centreon/broker/sql/database_config.hh index 0636df9d79d..d68df108294 100644 --- a/broker/core/sql/inc/com/centreon/broker/sql/database_config.hh +++ b/broker/core/sql/inc/com/centreon/broker/sql/database_config.hh @@ -75,6 +75,9 @@ class database_config { int get_connections_count() const; unsigned get_max_commit_delay() const; unsigned get_category() const; + const std::string& get_extension_directory() const { + return _extension_directory; + } void set_type(std::string const& type); void set_host(std::string const& host); @@ -87,6 +90,9 @@ class database_config { void set_queries_per_transaction(int qpt); void set_check_replication(bool check_replication); void set_category(unsigned category); + void set_extension_directory(std::string const& extension_directory) { + _extension_directory = extension_directory; + } database_config auto_commit_conf() const; @@ -105,6 +111,8 @@ class database_config { int _connections_count; unsigned _max_commit_delay; unsigned _category; + // where mariadb will find extension such as caching_sha2_password.so + std::string _extension_directory; }; std::ostream& operator<<(std::ostream& s, const database_config cfg); diff --git a/broker/core/sql/inc/com/centreon/broker/sql/mysql_connection.hh b/broker/core/sql/inc/com/centreon/broker/sql/mysql_connection.hh index d83aaa17697..efe6140ab21 100644 --- a/broker/core/sql/inc/com/centreon/broker/sql/mysql_connection.hh +++ b/broker/core/sql/inc/com/centreon/broker/sql/mysql_connection.hh @@ -85,6 +85,7 @@ class mysql_connection { const std::string _pwd; const std::string _name; const int _port; + const std::string _extension_directory; const unsigned _max_second_commit_delay; time_t _last_commit; std::atomic _state; diff --git a/broker/core/sql/src/database_config.cc b/broker/core/sql/src/database_config.cc index 855d56e0faa..6adf7ff3684 100644 --- a/broker/core/sql/src/database_config.cc +++ b/broker/core/sql/src/database_config.cc @@ -36,7 +36,8 @@ std::ostream& operator<<(std::ostream& s, const database_config cfg) { s << " queries per transaction:" << cfg.get_queries_per_transaction() << " check replication:" << cfg.get_check_replication() << " connection count:" << cfg.get_connections_count() - << " max commit delay:" << cfg.get_max_commit_delay() << 's'; + << " max commit delay:" << cfg.get_max_commit_delay() << 's' + << " extension_directory" << cfg.get_extension_directory(); return s; } @@ -49,7 +50,8 @@ database_config::database_config() : _queries_per_transaction(1), _check_replication(true), _connections_count(1), - _category(SHARED) {} + _category(SHARED), + _extension_directory(DEFAULT_MARIADB_EXTENSION_DIR) {} /** * Constructor. @@ -90,14 +92,16 @@ database_config::database_config(const std::string& type, _check_replication(check_replication), _connections_count(connections_count), _max_commit_delay(max_commit_delay), - _category(SHARED) {} + _category(SHARED), + _extension_directory(DEFAULT_MARIADB_EXTENSION_DIR) {} /** * Build a database configuration from a configuration set. * * @param[in] cfg Endpoint configuration. */ -database_config::database_config(config::endpoint const& cfg) { +database_config::database_config(config::endpoint const& cfg) + : _extension_directory(DEFAULT_MARIADB_EXTENSION_DIR) { std::map::const_iterator it, end; end = cfg.params.end(); @@ -212,6 +216,11 @@ database_config::database_config(config::endpoint const& cfg) { } } else _max_commit_delay = 5; + + it = cfg.params.find("extension_directory"); + if (it != end) { + _extension_directory = it->second; + } } /** @@ -557,6 +566,7 @@ void database_config::_internal_copy(database_config const& other) { _check_replication = other._check_replication; _connections_count = other._connections_count; _max_commit_delay = other._max_commit_delay; + _extension_directory = other._extension_directory; } /** diff --git a/broker/core/sql/src/mysql_connection.cc b/broker/core/sql/src/mysql_connection.cc index 61580982e5b..792bfef3105 100644 --- a/broker/core/sql/src/mysql_connection.cc +++ b/broker/core/sql/src/mysql_connection.cc @@ -190,6 +190,9 @@ bool mysql_connection::_try_to_reconnect() { uint32_t timeout = 10; mysql_options(_conn, MYSQL_OPT_CONNECT_TIMEOUT, &timeout); + mysql_optionsv(_conn, MYSQL_PLUGIN_DIR, + (const void*)_extension_directory.c_str()); + if (!mysql_real_connect(_conn, _host.c_str(), _user.c_str(), _pwd.c_str(), _name.c_str(), _port, (_socket == "" ? nullptr : _socket.c_str()), @@ -830,6 +833,9 @@ void mysql_connection::_run() { uint32_t timeout = 10; mysql_options(_conn, MYSQL_OPT_CONNECT_TIMEOUT, &timeout); + mysql_optionsv(_conn, MYSQL_PLUGIN_DIR, + (const void*)_extension_directory.c_str()); + while (config::applier::mode != config::applier::finished && !mysql_real_connect(_conn, _host.c_str(), _user.c_str(), _pwd.c_str(), _name.c_str(), _port, @@ -1076,6 +1082,7 @@ mysql_connection::mysql_connection( _pwd(db_cfg.get_password()), _name(db_cfg.get_name()), _port(db_cfg.get_port()), + _extension_directory(db_cfg.get_extension_directory()), _max_second_commit_delay(db_cfg.get_max_commit_delay()), _last_commit(db_cfg.get_queries_per_transaction() > 1 ? 0