set unique galera server-id

Each slave in a mysql replication cluster needs to have a unique
'server-id' set. This is an arbitrary integer, and often people select
1,2,3 etc. For easy deterministic uniqueness without needing to look at
what you've already used, a simple filter has been created to allow for
the hostname to be converted into an integer.

The server ID variable has been added to the my.cnf.j2 template
and the galera_server defaults/main.yml file. The generation of the
server-id variable happens within the `galera-install.yml` play making
it so there is no future impact in role requires.

Change-Id: Id15149e59cb03ab268bb3b7eeaf391334dfc0c01
Fixes-Bug: #1479484
changes/04/209404/5
Darren Birkett 7 years ago committed by Jesse Pretorius
parent d9a5bbc7cd
commit 9ae6eeca8b
  1. 1
      playbooks/galera-install.yml
  2. 23
      playbooks/plugins/filters/osa-filters.py
  3. 7
      playbooks/roles/galera_server/defaults/main.yml
  4. 3
      playbooks/roles/galera_server/templates/my.cnf.j2

@ -72,6 +72,7 @@
tags:
- "system-crontab-coordination"
vars:
galera_server_id: "{{ inventory_hostname | string_2_int }}"
galera_wsrep_node_name: "{{ container_name }}"
galera_lb_address: "{{ internal_lb_vip_address }}"
ansible_hostname: "{{ container_name }}"

@ -15,6 +15,7 @@
# (c) 2015, Kevin Carter <kevin.carter@rackspace.com>
import urlparse
import hashlib
"""Filter usage:
@ -88,6 +89,25 @@ def get_netorigin(url):
return '%s://%s' % (scheme, netloc)
def string_2_int(string):
"""Return the an integer from a string.
The string is hashed, converted to a base36 int, and the modulo of 10240
is returned.
:param string: string to retrieve an int from
:type string: ``str``
:returns: ``int``
"""
# Try to encode utf-8 else pass
try:
string = string.encode('utf-8')
except AttributeError:
pass
hashed_name = hashlib.sha256(string).hexdigest()
return int(hashed_name, 36) % 10240
class FilterModule(object):
"""Ansible jinja2 filters."""
@ -97,5 +117,6 @@ class FilterModule(object):
'bit_length_power_of_2': bit_length_power_of_2,
'netloc': get_netloc,
'netloc_no_port': get_netloc_no_port,
'netorigin': get_netorigin
'netorigin': get_netorigin,
'string_2_int': string_2_int
}

@ -20,6 +20,13 @@ galera_lb_address: 127.0.0.1
galera_cluster_name: openstack_galera_cluster
# The galera server-id should be set on all cluster nodes to ensure
# that replication is handled correctly and the error
# "Warning: You should set server-id to a non-0 value if master_host is
# set; we will force server id to 2, but this MySQL server will not act
# as a slave." is no longer present.
# galera_server_id: 0
galera_existing_cluster: true
galera_running_and_bootstrapped: false

@ -27,6 +27,9 @@ collation-server = utf8_unicode_ci
init-connect = 'SET NAMES utf8'
character-set-server = utf8
datadir = /var/lib/mysql
{% if galera_server_id is defined %}
server-id = {{ galera_server_id }}
{% endif %}
# LOGGING #
log-queries-not-using-indexes = {{ galera_unindexed_query_logging }}

Loading…
Cancel
Save