mysql_replication: add master_delay parameter (#63130)

pull/62584/head
Andrey Klychkov 5 years ago committed by René Moser
parent 30c2d21f17
commit e48202838c

@ -0,0 +1,2 @@
minor_changes:
- mysql_replication - add ``master_delay`` parameter (https://github.com/ansible/ansible/issues/51326).

@ -113,6 +113,13 @@ options:
choices: [current_pos, slave_pos, disabled]
type: str
version_added: "2.10"
master_delay:
description:
- Time lag behind the master's state (in seconds).
- Available from MySQL 5.6.
- For more information see U(https://dev.mysql.com/doc/refman/8.0/en/replication-delayed.html).
type: int
version_added: "2.10"
extends_documentation_fragment:
- mysql
@ -144,6 +151,12 @@ EXAMPLES = r'''
mysql_replication:
mode: changemaster
master_use_gtid: current_pos
- name: Change master to use replication delay 3600 seconds
mysql_replication:
mode: changemaster
master_host: 192.0.2.1
master_delay: 3600
'''
RETURN = r'''
@ -259,6 +272,7 @@ def main():
client_key=dict(type='path', aliases=['ssl_key']),
ca_cert=dict(type='path', aliases=['ssl_ca']),
master_use_gtid=dict(type='str', choices=['current_pos', 'slave_pos', 'disabled']),
master_delay=dict(type='int'),
)
)
mode = module.params["mode"]
@ -283,6 +297,7 @@ def main():
ssl_ca = module.params["ca_cert"]
connect_timeout = module.params['connect_timeout']
config_file = module.params['config_file']
master_delay = module.params['master_delay']
if module.params.get("master_use_gtid") == 'disabled':
master_use_gtid = 'no'
else:
@ -340,6 +355,8 @@ def main():
chm.append("MASTER_LOG_FILE='%s'" % master_log_file)
if master_log_pos is not None:
chm.append("MASTER_LOG_POS=%s" % master_log_pos)
if master_delay:
chm.append("MASTER_DELAY=%s" % master_delay)
if relay_log_file:
chm.append("RELAY_LOG_FILE='%s'" % relay_log_file)
if relay_log_pos is not None:

@ -2,6 +2,7 @@ master_port: 3306
standby_port: 3307
test_db: test_db
test_table: test_table
test_master_delay: 60
replication_user: replication_user
replication_pass: replication_pass
dump_path: /tmp/dump.sql

@ -1,6 +1,10 @@
# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Initial CI tests of mysql_replication module
# Initial CI tests of mysql_replication module:
- import_tasks: mysql_replication_initial.yml
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '7'
# Tests of master_delay parameter:
- import_tasks: mysql_replication_master_delay.yml
when: ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '7'

@ -0,0 +1,44 @@
# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Test master_delay mode:
- name: Run replication
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: changemaster
master_delay: '{{ test_master_delay }}'
register: result
- assert:
that:
- result is changed
- result.queries == ["CHANGE MASTER TO MASTER_DELAY=60"]
# Auxiliary step:
- name: Start slave
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: startslave
register: result
# Check master_delay:
- name: Get standby status
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: getslave
register: slave_status
- assert:
that:
- slave_status.SQL_Delay == {{ test_master_delay }}
- slave_status is not changed
# Stop standby for further tests:
- name: Stop slave
mysql_replication:
login_host: 127.0.0.1
login_port: "{{ standby_port }}"
mode: stopslave
Loading…
Cancel
Save