09b3c6ca07
Kolla-ansible is currently installing mariadb cluster on hosts defined in group['mariadb'] and render haproxy configuration for this hosts. This is not enough if user want to have several service databases in several mariadb clusters (shards). Spread service databases to multiple clusters (shards) is usefull especially for databases with high load (neutron,nova). How it works ? It works exactly same as now, but group reference 'mariadb' is now used as group where all mariadb clusters (shards) are located, and mariadb clusters are installed to dynamic groups created by group_by and host variable 'mariadb_shard_id'. It also adding special user 'shard_X' which will be used for creating users and databases, but only if haproxy is not used as load-balance solution. This patch will not affect user which has all databases on same db cluster on hosts in group 'mariadb', host variable 'mariadb_shard_id' is set to 0 if not defined. Mariadb's task in loadbalancer.yml (haproxy) is configuring mariadb default shard hosts as haproxy backends. If mariadb role is used to install several clusters (shards), only default one is loadbalanced via haproxy. Mariadb's backup is working only for default shard (cluster) when using haproxy as mariadb loadbalancer, if proxysql is used, all shards are backuped. After this patch will be merged, there will be way for proxysql patches which will implement L7 SQL balancing based on users and schemas. Example of inventory: [mariadb] server1 server2 server3 mariadb_shard_id=1 server4 mariadb_shard_id=1 server5 mariadb_shard_id=2 server6 mariadb_shard_id=3 Extra: wait_for_loadbalancer is removed instead of modified as its role is served by check already. The relevant refactor is applied as well. Change-Id: I933067f22ecabc03247ea42baf04f19100dffd08 Co-Authored-By: Radosław Piliszek <radoslaw.piliszek@gmail.com>
80 lines
3.1 KiB
YAML
80 lines
3.1 KiB
YAML
---
|
|
- name: Create MariaDB volume
|
|
become: true
|
|
kolla_docker:
|
|
action: "create_volume"
|
|
common_options: "{{ docker_common_options }}"
|
|
name: "mariadb"
|
|
register: mariadb_volume
|
|
|
|
- name: Divide hosts by their MariaDB volume availability
|
|
group_by:
|
|
key: "{{ mariadb_shard_group }}_had_volume_{{ mariadb_volume is not changed }}"
|
|
changed_when: false
|
|
|
|
- name: Establish whether the cluster has already existed
|
|
set_fact:
|
|
mariadb_cluster_exists: "{{ groups[mariadb_shard_group + '_had_volume_True'] is defined }}"
|
|
|
|
- block:
|
|
- name: Check MariaDB service port liveness
|
|
wait_for:
|
|
host: "{{ api_interface_address }}"
|
|
port: "{{ mariadb_port }}"
|
|
connect_timeout: 1
|
|
timeout: 10
|
|
search_regex: "MariaDB"
|
|
register: check_mariadb_port_liveness
|
|
ignore_errors: yes
|
|
|
|
- name: Divide hosts by their MariaDB service port liveness
|
|
group_by:
|
|
key: "{{ mariadb_shard_group }}_port_alive_{{ check_mariadb_port_liveness is success }}"
|
|
changed_when: false
|
|
|
|
- name: Fail on existing but stopped cluster
|
|
fail:
|
|
msg: MariaDB cluster exists but is stopped. Please start it using kolla-ansible mariadb_recovery
|
|
when:
|
|
# NOTE(yoctozepto): we allow single-node cluster to start
|
|
- groups[mariadb_shard_group] | length > 1
|
|
- mariadb_cluster_exists
|
|
- groups[mariadb_shard_group + '_port_alive_True'] is not defined
|
|
|
|
- block:
|
|
- name: Check MariaDB service WSREP sync status
|
|
become: true
|
|
command: >-
|
|
docker exec {{ mariadb_service.container_name }}
|
|
mysql -uroot -p{{ database_password }}
|
|
--silent --skip-column-names
|
|
-e 'SHOW STATUS LIKE "wsrep_local_state_comment"'
|
|
changed_when: false
|
|
register: check_mariadb_sync_status
|
|
no_log: true
|
|
|
|
# NOTE(yoctozepto): this is extracted separately to properly escape
|
|
# the TAB character which likes to go wrong due to interaction between
|
|
# Python/Ansible/Jinja2/YAML, the way below works
|
|
- name: Extract MariaDB service WSREP sync status
|
|
set_fact:
|
|
mariadb_sync_status: "{{ check_mariadb_sync_status.stdout.split('\t')[1] }}"
|
|
when:
|
|
- groups[mariadb_shard_group + '_port_alive_True'] is defined
|
|
- inventory_hostname in groups[mariadb_shard_group + '_port_alive_True']
|
|
|
|
- name: Divide hosts by their MariaDB service WSREP sync status
|
|
group_by:
|
|
key: "{{ mariadb_shard_group }}_sync_status_{{ mariadb_sync_status | default('NA') }}"
|
|
changed_when: false
|
|
|
|
- name: Fail when MariaDB services are not synced across the whole cluster
|
|
fail:
|
|
msg: MariaDB cluster is not synced. Please wait for WSREP sync before proceeding.
|
|
when:
|
|
- groups[mariadb_shard_group + '_port_alive_True'] is defined
|
|
- groups[mariadb_shard_group + '_sync_status_Synced'] is not defined or
|
|
groups[mariadb_shard_group + '_port_alive_True'] | sort != groups[mariadb_shard_group + '_sync_status_Synced'] | sort
|
|
|
|
when: not mariadb_recover | default(False)
|