Commit 43b96953 authored by Xavier Thompson's avatar Xavier Thompson

stack/erp5: Add scripts to apply new primary-url

Add scripts in bin directory that can be called manually to apply a
new primary-url (after having edited it in the instance parameters)
by turning a primary into a replica or by making a replica follow a
new primary, all without deleting existing data - so this is useful
when the existing data does not diverge from the new primary.

Being able to start replicating from a new primary without deleting
existing data is convenient, but maybe it's better or sufficient or
both to only be able to tell a mariadb to just destroy its existing
data and re-bootstrap from scratch.

Being able to delete all existing data and start from scratch seems
necessary in any case, but it's not clear that a special feature is
needed for this: maybe it's completely enough to be able to destroy
and re-request the instance through standard slapos operations.

Questions remain for automated usage:

1. One option is to provide a url the user may simply interact with
   (clickable button ...) to call the appropriate script. This kind
   of interaction could also be used to trigger the deletion of all
   existing data for a fresh bootstrap.

2. Another option is that editing the primary-url in the parameters
   results in the appropriate script being called. This makes sense
   as a way to remain in sync with given parameters, although there
   are some drawbacks: the uncertain propagation time, and the fact
   there is no guarantee that the existing data can converge to the
   state of the new primary. This might be grounds to keep all this
   strictly manual.

In any case, this relies already on the propagation of the instance
parameters to input the new primary-url, so it may not be useful at
all for any use-case, manual or automated.
parent 590bc924
......@@ -26,7 +26,7 @@ md5sum = d10b8e35b02b5391cf46bf0c7dbb1196
[template-mariadb]
filename = instance-mariadb.cfg.in
md5sum = 34fb63681f1adcb38b7b1c36c0d54e47
md5sum = d8ad8b704020f24388c2c09ad4f4e9a8
[template-kumofs]
filename = instance-kumofs.cfg.in
......
......@@ -385,8 +385,7 @@ eggs =
file = ${mariadb-replication-sense:output}
output = ${directory:plugins}/mariadb_replication.py
[{{ section('mariadb-replica-become-primary') }}]
# See https://mariadb.com/kb/en/changing-a-replica-to-become-the-primary
[mariadb-replica-change-base]
recipe = slapos.cookbook:wrapper
wrapper-path = ${directory:bin}/${:_buildout_section_name_}
logfile = ${directory:log}/${:_buildout_section_name_}.log
......@@ -396,15 +395,49 @@ command-line =
{
date
$mysql -e "
STOP ALL SLAVES;
RESET SLAVE ALL;
SHOW MASTER STATUS;
SELECT @@global.gtid_binlog_pos;
${:sql-commands}
"
echo ""
} >> "${:logfile}"
echo "See ${:logfile}"
{% if replication -%}
[{{ section('mariadb-replica-change-primary') }}]
<= mariadb-replica-change-base
sql-commands =
STOP SLAVE;
CHANGE MASTER TO
MASTER_HOST='{{ primary.hostname }}',
MASTER_USER='{{ primary.username }}',
MASTER_PASSWORD='{{ primary.password }}',
MASTER_PORT={{ primary.port }},
MASTER_USE_GTID="slave_pos";
START SLAVE;
[{{ section('mariadb-primary-become-replica') }}]
<= mariadb-replica-change-base
sql-commands =
STOP ALL SLAVES;
RESET MASTER;
RESET SLAVE ALL;
CHANGE MASTER TO
MASTER_HOST='{{ primary.hostname }}',
MASTER_USER='{{ primary.username }}',
MASTER_PASSWORD='{{ primary.password }}',
MASTER_PORT={{ primary.port }},
MASTER_USE_GTID="slave_pos";
START SLAVE;
{%- endif %}
[{{ section('mariadb-replica-become-primary') }}]
# See https://mariadb.com/kb/en/changing-a-replica-to-become-the-primary
<= mariadb-replica-change-base
sql-commands =
STOP ALL SLAVES;
RESET SLAVE ALL;
SHOW MASTER STATUS;
SELECT @@global.gtid_binlog_pos;
[{{ section('mariadb-backup-static-server-promise') }}]
<= monitor-promise-base
promise = check_socket_listening
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment