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.

Conflicts:
	playbooks/plugins/filters/osa-filters.py

Change-Id: Id15149e59cb03ab268bb3b7eeaf391334dfc0c01
Closes-Bug: #1479484
(cherry picked from commit 9ae6eeca8b)
This commit is contained in:
Darren Birkett 2015-08-05 09:42:57 +01:00 committed by Jesse Pretorius (odyssey4me)
parent f0875e07c7
commit d0bb38042e
4 changed files with 36 additions and 2 deletions

View File

@ -117,6 +117,7 @@
tags:
- "system-crontab-coordination"
vars:
galera_server_id: "{{ inventory_hostname | string_2_int }}"
galera_wsrep_node_name: "{{ container_name }}"
ansible_hostname: "{{ container_name }}"
ansible_ssh_host: "{{ container_address }}"

View File

@ -14,6 +14,9 @@
#
# (c) 2015, Kevin Carter <kevin.carter@rackspace.com>
import hashlib
"""Filter usage:
Simple filters that may be useful from within the stack
@ -27,7 +30,26 @@ def bit_length_power_of_2(value):
:type value: ``int``
:returns: ``int``
"""
return 2**(int(value)-1).bit_length()
return 2 ** (int(value) - 1).bit_length()
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):
@ -36,5 +58,6 @@ class FilterModule(object):
@staticmethod
def filters():
return {
'bit_length_power_of_2': bit_length_power_of_2
'bit_length_power_of_2': bit_length_power_of_2,
'string_2_int': string_2_int
}

View File

@ -18,6 +18,13 @@ is_metal: true
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_monitoring_user: monitoring

View File

@ -28,6 +28,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 }}