<commit_before>---
# Copyright 2015, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

- name: Reload the systemd daemon
  systemd:
    daemon_reload: yes
    name: "{{ galera_mariadb_service_name }}"
    enabled: "yes"

- name: Check node status
  command: >
    mysql --silent --skip-column-names --connect-timeout=10 -e 'SHOW STATUS LIKE "wsrep_local_state";'
  failed_when: false
  changed_when: true
  register: node_status
  listen: Restart all mysql
  notify:
    - Bootstrap cluster
    - Restart mysql (All)

- name: Check if node is in the cluster
  command: >
    mysql --silent --skip-column-names --connect-timeout=10 -e 'SHOW STATUS LIKE "wsrep_incoming_addresses";'
  failed_when: false
  changed_when: false
  register: incoming_addresses
  listen: Bootstrap cluster

- name: Set incoming addresses fact (primary)
  set_fact:
    galera_incoming_addresses: "{{ (incoming_addresses.stdout.split()[-1] | default('')).split(',') }}"
  listen: Bootstrap cluster

- name: Set node status fact
  set_fact:
    galera_cluster_ready: "{{ (galera_wsrep_address_port in galera_incoming_addresses) or ((node_status.stdout.split()[-1] | default(false)) in ['2', '4']) }}"
  listen: Bootstrap cluster

- name: Stop mysql
  service:
    name: "{{ galera_mariadb_service_name }}"
    state: stopped
  changed_when: true
  listen: Bootstrap cluster
  when:
    - galera_install_server | bool
    - not galera_cluster_ready | bool

# TODO: Remove this include once MariaDB bug will be resolved
# https://jira.mariadb.org/browse/MDEV-25030
- name: Fix root user permissions during upgrade
  include_tasks: handlers/galera_upgrade_hook.yml
  listen: Bootstrap cluster
  when:
    - galera_install_server | bool
    - galera_upgrade | bool
    - inventory_hostname == galera_server_bootstrap_node

- name: Start new cluster
  command: /usr/local/bin/galera_new_cluster
  failed_when: not start_new_cluster.rc in [0, 3]
  changed_when: start_new_cluster.rc == 3
  register: start_new_cluster
  delegate_to: "{{ galera_server_bootstrap_node }}"
  run_once: true
  when:
    - galera_install_server | bool
    - not galera_cluster_ready | bool
  listen: Bootstrap cluster

- name: Restart mysql (All)
  service:
    name: "{{ galera_mariadb_service_name }}"
    state: "{{ (not hostvars[item]['galera_cluster_ready'] | bool) | ternary('started', 'restarted') }}"
  environment:
    MYSQLD_STARTUP_TIMEOUT: 180
  register: galera_restart
  until: galera_restart is success
  retries: 6
  delay: 5
  delegate_to: "{{ item }}"
  when:
    - galera_install_server | bool
    - hostvars[item]['galera_cluster_ready'] is defined
    - hostvars[item]['galera_deployed'] | default(false) | bool
  with_items:
    - "{{ ansible_play_hosts }}"
  run_once: true
  notify:
    - Delete encryption keyfile after starting Galera<commit_msg>Ensure mariadb service is enabled<commit_after>---
# Copyright 2015, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

- name: Reload the systemd daemon
  systemd:
    daemon_reload: yes
    name: "{{ galera_mariadb_service_name }}"
    enabled: "yes"

- name: Check node status
  command: >
    mysql --silent --skip-column-names --connect-timeout=10 -e 'SHOW STATUS LIKE "wsrep_local_state";'
  failed_when: false
  changed_when: true
  register: node_status
  listen: Restart all mysql
  notify:
    - Bootstrap cluster
    - Restart mysql (All)

- name: Check if node is in the cluster
  command: >
    mysql --silent --skip-column-names --connect-timeout=10 -e 'SHOW STATUS LIKE "wsrep_incoming_addresses";'
  failed_when: false
  changed_when: false
  register: incoming_addresses
  listen: Bootstrap cluster

- name: Set incoming addresses fact (primary)
  set_fact:
    galera_incoming_addresses: "{{ (incoming_addresses.stdout.split()[-1] | default('')).split(',') }}"
  listen: Bootstrap cluster

- name: Set node status fact
  set_fact:
    galera_cluster_ready: "{{ (galera_wsrep_address_port in galera_incoming_addresses) or ((node_status.stdout.split()[-1] | default(false)) in ['2', '4']) }}"
  listen: Bootstrap cluster

- name: Stop mysql
  service:
    name: "{{ galera_mariadb_service_name }}"
    state: stopped
    enabled: yes
  changed_when: true
  listen: Bootstrap cluster
  when:
    - galera_install_server | bool
    - not galera_cluster_ready | bool

# TODO: Remove this include once MariaDB bug will be resolved
# https://jira.mariadb.org/browse/MDEV-25030
- name: Fix root user permissions during upgrade
  include_tasks: handlers/galera_upgrade_hook.yml
  listen: Bootstrap cluster
  when:
    - galera_install_server | bool
    - galera_upgrade | bool
    - inventory_hostname == galera_server_bootstrap_node

- name: Start new cluster
  command: /usr/local/bin/galera_new_cluster
  failed_when: not start_new_cluster.rc in [0, 3]
  changed_when: start_new_cluster.rc == 3
  register: start_new_cluster
  delegate_to: "{{ galera_server_bootstrap_node }}"
  run_once: true
  when:
    - galera_install_server | bool
    - not galera_cluster_ready | bool
  listen: Bootstrap cluster

- name: Restart mysql (All)
  service:
    name: "{{ galera_mariadb_service_name }}"
    state: "{{ (not hostvars[item]['galera_cluster_ready'] | bool) | ternary('started', 'restarted') }}"
    enabled: yes
  environment:
    MYSQLD_STARTUP_TIMEOUT: 180
  register: galera_restart
  until: galera_restart is success
  retries: 6
  delay: 5
  delegate_to: "{{ item }}"
  when:
    - galera_install_server | bool
    - hostvars[item]['galera_cluster_ready'] is defined
    - hostvars[item]['galera_deployed'] | default(false) | bool
  with_items:
    - "{{ ansible_play_hosts }}"
  run_once: true
  notify:
    - Delete encryption keyfile after starting Galera
{'fraction_non_alphanumeric': 0.09994051160023795, 'fraction_numerical': 0.008625817965496729, 'mean_word_length': 3.9851742031134174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6465022', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2131, 'n_words': 631}