Set server_id when using binlogs

Percona-cluster was failing to start when enable-binlogs was set to
True due to missing server_id in the configuration.

Set the server_id to a unique, non-zero, positive number from 1 to
2**32 - 1.

Closes-Bug: #1772947
Change-Id: Id7da6dd8f27e364e0d5244e4ec33ae4645e4ef96
This commit is contained in:
David Ames 2018-05-30 10:35:34 -07:00
parent e5974539a4
commit 78d1df2d50
4 changed files with 24 additions and 0 deletions

View File

@ -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'):

View File

@ -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

View File

@ -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 }}

View File

@ -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 %}