diff options
author | Andrei Pavel <andrei@isc.org> | 2023-11-20 23:06:56 +0100 |
---|---|---|
committer | Andrei Pavel <andrei@isc.org> | 2024-02-22 08:57:35 +0100 |
commit | 83594bd11f240c4545a1aed0e4782e0bf13dc8fa (patch) | |
tree | 0e18978c2c43ed69f9afadf3baf77496b2e9465d /src | |
parent | [#3025] automatic init of mysql schema (diff) | |
download | kea-83594bd11f240c4545a1aed0e4782e0bf13dc8fa.tar.xz kea-83594bd11f240c4545a1aed0e4782e0bf13dc8fa.zip |
[#3025] convert db access params to kea-admin
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/database/db_log.cc | 1 | ||||
-rw-r--r-- | src/lib/database/db_log.h | 1 | ||||
-rw-r--r-- | src/lib/database/db_messages.cc | 2 | ||||
-rw-r--r-- | src/lib/database/db_messages.h | 1 | ||||
-rw-r--r-- | src/lib/database/db_messages.mes | 4 | ||||
-rw-r--r-- | src/lib/mysql/mysql_connection.cc | 24 | ||||
-rw-r--r-- | src/lib/mysql/mysql_connection.h | 3 |
7 files changed, 31 insertions, 5 deletions
diff --git a/src/lib/database/db_log.cc b/src/lib/database/db_log.cc index 395bd57691..612d71653b 100644 --- a/src/lib/database/db_log.cc +++ b/src/lib/database/db_log.cc @@ -33,6 +33,7 @@ const DbLogger::MessageMap db_message_map = { { PGSQL_ROLLBACK_SAVEPOINT, DATABASE_PGSQL_ROLLBACK_SAVEPOINT }, { PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED, DATABASE_PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED }, + { MYSQL_INITIALIZE_SCHEMA, DATABASE_MYSQL_INITIALIZE_SCHEMA }, { MYSQL_FATAL_ERROR, DATABASE_MYSQL_FATAL_ERROR }, { MYSQL_START_TRANSACTION, DATABASE_MYSQL_START_TRANSACTION }, { MYSQL_COMMIT, DATABASE_MYSQL_COMMIT }, diff --git a/src/lib/database/db_log.h b/src/lib/database/db_log.h index a873df78c6..4f042507c1 100644 --- a/src/lib/database/db_log.h +++ b/src/lib/database/db_log.h @@ -60,6 +60,7 @@ enum DbMessageID { PGSQL_ROLLBACK_SAVEPOINT, PGSQL_TCP_USER_TIMEOUT_UNSUPPORTED, + MYSQL_INITIALIZE_SCHEMA, MYSQL_FATAL_ERROR, MYSQL_START_TRANSACTION, MYSQL_COMMIT, diff --git a/src/lib/database/db_messages.cc b/src/lib/database/db_messages.cc index b680baaa19..bb55034cfa 100644 --- a/src/lib/database/db_messages.cc +++ b/src/lib/database/db_messages.cc @@ -10,6 +10,7 @@ namespace db { extern const isc::log::MessageID DATABASE_INVALID_ACCESS = "DATABASE_INVALID_ACCESS"; extern const isc::log::MessageID DATABASE_MYSQL_COMMIT = "DATABASE_MYSQL_COMMIT"; extern const isc::log::MessageID DATABASE_MYSQL_FATAL_ERROR = "DATABASE_MYSQL_FATAL_ERROR"; +extern const isc::log::MessageID DATABASE_MYSQL_INITIALIZE_SCHEMA = "DATABASE_MYSQL_INITIALIZE_SCHEMA"; extern const isc::log::MessageID DATABASE_MYSQL_ROLLBACK = "DATABASE_MYSQL_ROLLBACK"; extern const isc::log::MessageID DATABASE_MYSQL_START_TRANSACTION = "DATABASE_MYSQL_START_TRANSACTION"; extern const isc::log::MessageID DATABASE_PGSQL_COMMIT = "DATABASE_PGSQL_COMMIT"; @@ -33,6 +34,7 @@ const char* values[] = { "DATABASE_INVALID_ACCESS", "invalid database access string: %1", "DATABASE_MYSQL_COMMIT", "committing to MySQL database", "DATABASE_MYSQL_FATAL_ERROR", "Unrecoverable MySQL error occurred: %1 for <%2>, reason: %3 (error code: %4).", + "DATABASE_MYSQL_INITIALIZE_SCHEMA", "Initializing the MySQL schema with command: kea-admin %1.", "DATABASE_MYSQL_ROLLBACK", "rolling back MySQL database", "DATABASE_MYSQL_START_TRANSACTION", "starting new MySQL transaction", "DATABASE_PGSQL_COMMIT", "committing to PostgreSQL database", diff --git a/src/lib/database/db_messages.h b/src/lib/database/db_messages.h index ad367e298b..3ddc1efc69 100644 --- a/src/lib/database/db_messages.h +++ b/src/lib/database/db_messages.h @@ -11,6 +11,7 @@ namespace db { extern const isc::log::MessageID DATABASE_INVALID_ACCESS; extern const isc::log::MessageID DATABASE_MYSQL_COMMIT; extern const isc::log::MessageID DATABASE_MYSQL_FATAL_ERROR; +extern const isc::log::MessageID DATABASE_MYSQL_INITIALIZE_SCHEMA; extern const isc::log::MessageID DATABASE_MYSQL_ROLLBACK; extern const isc::log::MessageID DATABASE_MYSQL_START_TRANSACTION; extern const isc::log::MessageID DATABASE_PGSQL_COMMIT; diff --git a/src/lib/database/db_messages.mes b/src/lib/database/db_messages.mes index acec88cd94..958b48aac6 100644 --- a/src/lib/database/db_messages.mes +++ b/src/lib/database/db_messages.mes @@ -17,6 +17,10 @@ The code has issued a commit call. All outstanding transactions will be committed to the database. Note that depending on the MySQL settings, the committal may not include a write to disk. +% DATABASE_MYSQL_INITIALIZE_SCHEMA Initializing the MySQL schema with command: kea-admin %1. +This is logged before running the kea-admin command to automatically initialize the schema from Kea +after getting the schema version initially failed. The full kea-admin command is shown. + % DATABASE_MYSQL_FATAL_ERROR Unrecoverable MySQL error occurred: %1 for <%2>, reason: %3 (error code: %4). An error message indicating that communication with the MySQL database server has been lost. If automatic recovery has been enabled, then the server will diff --git a/src/lib/mysql/mysql_connection.cc b/src/lib/mysql/mysql_connection.cc index d3a13aec43..55d46f0513 100644 --- a/src/lib/mysql/mysql_connection.cc +++ b/src/lib/mysql/mysql_connection.cc @@ -407,6 +407,17 @@ MySqlConnection::ensureSchemaVersion(const ParameterMap& parameters, void MySqlConnection::initializeSchema(const ParameterMap& parameters) { + if (parameters.count("readonly") && parameters.at("readonly") == "true") { + // The readonly flag is historically used for host backends. Still, if + // enabled, it is a strong indication that we should not meDDLe with it. + return; + } + + // Convert parameters. + vector<string> kea_admin_parameters(toKeaAdminParameters(parameters)); + kea_admin_parameters.insert(kea_admin_parameters.begin(), "db-init"); + + // Run. IOServicePtr io_service(new IOService()); ProcessSpawn kea_admin(io_service, KEA_ADMIN, kea_admin_parameters); DB_LOG_INFO(MYSQL_INITIALIZE_SCHEMA).arg(kea_admin.getCommandLine()); @@ -424,7 +435,8 @@ MySqlConnection::initializeSchema(const ParameterMap& parameters) { } } -vector<string> MySqlConnection::toKeaAdminParameters(ParameterMap const& params) { +vector<string> +MySqlConnection::toKeaAdminParameters(ParameterMap const& params) { vector<string> result{"mysql"}; for (auto const& p : params) { string const& keyword(p.first); @@ -435,8 +447,7 @@ vector<string> MySqlConnection::toKeaAdminParameters(ParameterMap const& params) keyword == "password" || keyword == "host" || keyword == "port" || - keyword == "name"|| - keyword == "connect-timeout") { + keyword == "name") { result.push_back("--" + keyword); result.push_back(value); continue; @@ -446,10 +457,13 @@ vector<string> MySqlConnection::toKeaAdminParameters(ParameterMap const& params) // But they do have a mariadb client flag equivalent. // We pass them to kea-admin using the --extra flag. static unordered_map<string, string> conversions{ - {"cihper-list", "ssl-cipher"}, + {"connect-timeout", "connect_timeout"}, + {"cipher-list", "ssl-cipher"}, {"cert-file", "ssl-cert"}, {"key-file", "ssl-key"}, {"trust-anchor", "ssl-ca"}, + // {"read-timeout", "--net-read-timeout"}, // available in docs, but client says unknown variable? + // {"write-timeout", "--net-write-timeout"}, // available in docs, but client says unknown variable? }; bool extra_flag_added(false); if (conversions.count(keyword)) { @@ -517,7 +531,7 @@ MySqlConnection::~MySqlConnection() { // Free up the prepared statements, ignoring errors. (What would we do // about them? We're destroying this object and are not really concerned // with errors on a database connection that is about to go away.) - for (int i = 0; i < statements_.size(); ++i) { + for (size_t i = 0; i < statements_.size(); ++i) { if (statements_[i] != NULL) { (void) mysql_stmt_close(statements_[i]); statements_[i] = NULL; diff --git a/src/lib/mysql/mysql_connection.h b/src/lib/mysql/mysql_connection.h index f3188c5fe5..d7a3ce5dfc 100644 --- a/src/lib/mysql/mysql_connection.h +++ b/src/lib/mysql/mysql_connection.h @@ -256,6 +256,9 @@ public: /// @brief Destructor virtual ~MySqlConnection(); + static std::vector<std::string> + toKeaAdminParameters(ParameterMap const& params); + /// @brief Get the schema version. /// /// @param parameters A data structure relating keywords and values |