diff --git a/src/config.yaml b/src/config.yaml index 625eefd..9198d70 100644 --- a/src/config.yaml +++ b/src/config.yaml @@ -46,9 +46,13 @@ options: auth_cache_refresh_interval else Router won't start. max_connections: type: int - default: 512 + default: 1024 description: | - Maximum number of connections to allow in direction to each MySQL + If mysql router version < 8.0.27, this option will be set as max_connections + in the config. Else will be max_total_connections. + The max_connections is maximum number of connections to allow in direction to each MySQL routing sessions, with one for the RW unit and another one for the RO - units of the MySQL innodb cluster. Defaults to 512. A valid range is - between 1 and 65535. + units of the MySQL innodb cluster. A valid range is between 1 and 65535. + The max_total_connections is the maximum number of client connections handled by Router, to help + prevent running out of the file descriptors. A valid + range is between 1 and 9223372036854775807. diff --git a/src/lib/charm/openstack/mysql_router.py b/src/lib/charm/openstack/mysql_router.py index 653e3d6..61afb0b 100644 --- a/src/lib/charm/openstack/mysql_router.py +++ b/src/lib/charm/openstack/mysql_router.py @@ -755,7 +755,6 @@ class MySQLRouterCharm(charms_openstack.charm.OpenStackCharm): }, DEFAULT_SECTION: { "pid_file": self.mysqlrouter_pid_file, - "max_connections": str(self.options.max_connections), "unknown_config_option": "warning", # LP: #1971565 }, LOGGING_SECTION: { @@ -770,6 +769,15 @@ class MySQLRouterCharm(charms_openstack.charm.OpenStackCharm): ch_core.hookenv.log("TLS mode PREFERRED", "DEBUG") _parameters["DEFAULT"]["client_ssl_mode"] = "PREFERRED" + if ch_core.host.cmp_pkgrevno('mysql-router', '8.0.27') >= 0: + _parameters[DEFAULT_SECTION]["max_total_connections"] = str( + self.options.max_connections + ) + else: + _parameters[DEFAULT_SECTION]["max_connections"] = str( + self.options.max_connections + ) + with ch_core.host.restart_on_change( self.restart_map, restart_functions=self.restart_functions): ch_core.hookenv.log("Updating configuration parameters", "DEBUG") diff --git a/unit_tests/test_lib_charm_openstack_mysql_router.py b/unit_tests/test_lib_charm_openstack_mysql_router.py index 00a1f6c..a31b351 100644 --- a/unit_tests/test_lib_charm_openstack_mysql_router.py +++ b/unit_tests/test_lib_charm_openstack_mysql_router.py @@ -776,7 +776,7 @@ class TestMySQLRouterCharm(test_utils.PatchHelper): mysql_router.METADATA_CACHE_SECTION: _metadata_config, mysql_router.DEFAULT_SECTION: { 'client_ssl_mode': "PASSTHROUGH", - 'max_connections': _config_data['max_connections'], + 'max_total_connections': _config_data['max_connections'], 'pid_file': '/run/mysql/mysqlrouter-foobar.pid', 'unknown_config_option': 'warning', }, @@ -784,6 +784,9 @@ class TestMySQLRouterCharm(test_utils.PatchHelper): 'level': 'INFO', }, } + # Successful > 8.0.27 + # Should use max_total_connections in config + self.cmp_pkgrevno.return_value = 1 # Not bootstrapped yet self.exists.return_value = False @@ -804,6 +807,15 @@ class TestMySQLRouterCharm(test_utils.PatchHelper): mrc.config_changed() _mock_update_config_parameters.assert_called_once_with(_params) + # Successful < 8.0.27 + # Should use max_connections in config + self.cmp_pkgrevno.return_value = -1 + _params["DEFAULT"].pop("max_total_connections") + _params["DEFAULT"]["max_connections"] = _config_data['max_connections'] + _mock_update_config_parameters.reset_mock() + mrc.config_changed() + _mock_update_config_parameters.assert_called_once_with(_params) + def test_custom_restart_function(self): self.patch_object(mysql_router.ch_core.host, "service_stop") self.patch_object(mysql_router.ch_core.host, "service_start")