diff --git a/playbooks/galera-install.yml b/playbooks/galera-install.yml index 38a3c49689..e95000890a 100644 --- a/playbooks/galera-install.yml +++ b/playbooks/galera-install.yml @@ -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 }}" diff --git a/playbooks/plugins/filters/osa-filters.py b/playbooks/plugins/filters/osa-filters.py index e532d14580..7347a51f46 100644 --- a/playbooks/plugins/filters/osa-filters.py +++ b/playbooks/plugins/filters/osa-filters.py @@ -14,6 +14,9 @@ # # (c) 2015, Kevin Carter +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 } diff --git a/playbooks/roles/galera_server/defaults/main.yml b/playbooks/roles/galera_server/defaults/main.yml index 28f4eee978..202f4241f4 100644 --- a/playbooks/roles/galera_server/defaults/main.yml +++ b/playbooks/roles/galera_server/defaults/main.yml @@ -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 diff --git a/playbooks/roles/galera_server/templates/my.cnf.j2 b/playbooks/roles/galera_server/templates/my.cnf.j2 index 6269af7916..1165f3e072 100644 --- a/playbooks/roles/galera_server/templates/my.cnf.j2 +++ b/playbooks/roles/galera_server/templates/my.cnf.j2 @@ -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 }}