diff --git a/hooks/percona_hooks.py b/hooks/percona_hooks.py index 9b0788e..7d65b23 100755 --- a/hooks/percona_hooks.py +++ b/hooks/percona_hooks.py @@ -110,6 +110,7 @@ from percona_utils import ( update_root_password, cluster_wait, get_wsrep_provider_options, + get_server_id, ) from charmhelpers.core.unitdata import kv @@ -191,6 +192,7 @@ def render_config(hosts=None): 'binlogs_expire_days': config('binlogs-expire-days'), 'performance_schema': config('performance-schema'), 'is_leader': is_leader(), + 'server_id': get_server_id(), } if config('prefer-ipv6'): diff --git a/hooks/percona_utils.py b/hooks/percona_utils.py index 29f8244..b1cf278 100644 --- a/hooks/percona_utils.py +++ b/hooks/percona_utils.py @@ -1032,3 +1032,23 @@ def get_wsrep_provider_options(): .format(config('peer-timeout'))) return ';'.join(wsrep_provider_options) + + +def get_server_id(): + """ Return unique server id for bin log replication + + Server ID must be a unique, non-zero, positive number from 1 to 2**32 - 1 + https://dev.mysql.com/doc/refman/8.0/en/replication-options.html + + :returns: int server_id + """ + MAX_SERVER_ID = 2**32 - 1 + + # Get the juju unit number + server_id = int(local_unit().split('/')[-1]) + + # Server ID of 0 indicates disabled replication, use the max instead + if server_id == 0: + server_id = MAX_SERVER_ID + + return server_id diff --git a/templates/my.cnf b/templates/my.cnf index 252ee9e..9f4e243 100644 --- a/templates/my.cnf +++ b/templates/my.cnf @@ -29,6 +29,7 @@ wsrep_cluster_address=gcomm://{{ cluster_hosts }} binlog_format=ROW {% if enable_binlogs -%} +server_id = {{ server_id }} log_bin={{ binlogs_path }} expire_logs_days={{ binlogs_expire_days }} max_binlog_size={{ binlogs_max_size }} diff --git a/templates/mysqld.cnf b/templates/mysqld.cnf index d162671..d365616 100644 --- a/templates/mysqld.cnf +++ b/templates/mysqld.cnf @@ -73,6 +73,7 @@ log_error = /var/log/mysql/error.log # note: if you are setting up a replication slave, see README.Debian about # other settings you may need to change. {% if enable_binlogs -%} +server_id = {{ server_id }} log_bin={{ binlogs_path }} {% endif %}