Commit e4579253 authored by Alain Takoudjou's avatar Alain Takoudjou

repman: destroy slave database if not slave instance is destroyed

parent 3ebe4aff
......@@ -14,11 +14,11 @@
# not need these here).
[instance.cfg]
filename = instance.cfg.in
md5sum = 1812befaf367f30a1fe469ccf95dae31
md5sum = 37eff9b6b85fcbd3930aa58a1e08d32e
[instance-repman.cfg]
_update_hash_filename_ = instance-repman.cfg.jinja2.in
md5sum = b65e982e82dbef25cc71c12f91185e03
md5sum = 3faea4a761b4a48aa4c141cf8f267059
[config-toml.in]
_update_hash_filename_ = templates/config.toml.in
......@@ -34,7 +34,7 @@ md5sum = 0eeb24c6aa0760f0d33c4cc2828ddf30
[template-mariadb.cfg]
_update_hash_filename_ = instance-mariadb.cfg.jinja2.in
md5sum = 23d71176700487eb5e5240f6ad6cdce6
md5sum = 27bbc3c979faf9a1a35daa2382ebc4df
[template-my-cnf]
_update_hash_filename_ = templates/my.cnf.in
......@@ -42,7 +42,7 @@ md5sum = f3661b788099bb31d71ba6e7d36836d9
[template-mariadb-initial-setup]
_update_hash_filename_ = templates/mariadb_initial_setup.sql.in
md5sum = df44c2d6fb1971df582345daedad280c
md5sum = c300e9c2fb67a5d41fadc572f4c02216
[template-publish-slave-information]
_update_hash_filename_ = publish-database-slave-parameters.cfg.in
......@@ -54,7 +54,7 @@ md5sum = d8a0a7d72b02f911dafda655941b805d
[init-root-wrapper-in]
_update_hash_filename_ = templates/init_root_wrapper.in
md5sum = cc3745fdaa248e297d19076b664e3bb5
md5sum = b3dffa3c8b9b2cc86b536d411cbde9d4
[repman-manager-sh.in]
_update_hash_filename_ = templates/repman-manager.sh.in
......@@ -71,3 +71,7 @@ md5sum = 8f14054b3761b167cf8a86f4f084a574
[proxy-need-start-stop.sh.in]
_update_hash_filename_ = templates/proxy-need-start-stop.sh.in
md5sum = 455aaf369bf5141758dc57f2c0e67b08
[slave-db-cleanup.in]
_update_hash_filename_ = templates/slave-db-cleanup.in
md5sum = d9838ccd037b382e20b9faf412305f82
......@@ -92,6 +92,7 @@ heartbeat-user = {{ slapparameter_dict['heartbeat-user'] }}
[init-script]
< = jinja2-template-executable
extensions = jinja2.ext.do
# XXX: is there a better location ?
rendered = ${directory:etc}/mariadb_initial_setup.sql
template = {{ parameter_dict['template-mariadb-initial-setup'] }}
......@@ -119,8 +120,18 @@ context =
raw mysql_conf ${directory:etc}/mysql/my.cnf
raw dash_bin {{ dash }}
raw mysql_bin {{ parameter_dict['mariadb-location'] }}/bin/mysql
raw database-list {{ slapparameter_dict['database-name'] }}
template = {{ parameter_dict['template-init-root-wrapper'] }}
[mysql-slave-db-cleanup]
< = jinja2-template-executable
rendered = ${directory:bin}/remove_slave_db
context =
raw mysql_conf ${directory:etc}/mysql/my.cnf
raw dash_bin {{ dash }}
raw mysql_bin {{ parameter_dict['mariadb-location'] }}/bin/mysql
template = {{ parameter_dict['template-cleanup-db'] }}
[mysqld]
< = jinja2-template-executable
rendered = ${directory:bin}/mysqld
......@@ -286,6 +297,13 @@ name = mariadb-need-start
frequency = * * * * *
command = ${template-mysqld-need-start:rendered}
[{{ section('db-remove-cron-entry') }}]
recipe = slapos.cookbook:cron.d
cron-entries = ${cron:cron-entries}
name = slave-db-remove
frequency = */20 * * * *
command = ${mysql-slave-db-cleanup:rendered}
[template-mysqld-need-start]
< = jinja2-template-executable
rendered = ${directory:bin}/mysqld_need_start
......
......@@ -11,6 +11,7 @@
{% set tag_list = ["gtidstrict", "bind", "pkg", "innodb", "noquerycache", "slow", "pfs", "linux", "readonly", "diskmonitor", "sqlerror", "compressbinlog", "bm4ci", "mroonga", "utctime", "readcommitted", "nohandshake"] -%}
{% set frontend_parameter_dict = slapparameter_dict.get('slave-frontend', {}) -%}
{% set dabase_slave_list = [] -%}
{% set db_name_list = [] -%}
[directory]
recipe = slapos.cookbook:mkdirectory
......@@ -59,7 +60,6 @@ template = inline:#!{{ bash_bin }}
rendered = ${directory:bin}/update-proxysql-config
mode = 755
{% set db_name_list = [] -%}
[database-slave-information]
{% for instance_dict in slave_instance_list -%}
{% set slave_dict = {
......@@ -72,6 +72,7 @@ mode = 755
{% do dabase_slave_list.append(slave_dict) -%}
{% do db_name_list.append(slave_dict['name']) -%}
{% endfor %}
{% set db_list = db_name_list | join(' ') -%}
{% do mariadb_dict.__setitem__('computer-memory-percent-threshold', 80) -%}
{% set default_parameter_dict = {"cluster1": {"name": "cluster1", "db-prefered-master": "",
......@@ -112,6 +113,7 @@ config-repman-secure-url = ${nginx-parameter:backend-ssl-url}
config-cluster = {{ name }}
config-name = {{ dbname }}
config-database-list = {{ dumps(dabase_slave_list) }}
config-database-name = {{ dumps(db_list) }}
return =
database-host
receiver-port
......@@ -484,17 +486,13 @@ name = nginx
log = ${nginx-parameter:access-log} ${nginx-parameter:error-log}
post = kill -USR1 $(cat ${nginx-parameter:pid-file})
{% set db_list = db_name_list | join(' ') -%}
[db-slave-requested]
name = {{ db_list }}
[publish-early]
recipe = slapos.cookbook:publish-early
-init =
monitor-password monitor-htpasswd:passwd
db-root-password gen-root-password:passwd
repman-password repman-password:passwd
database-list db-slave-requested:name
database-list = {{ db_list }}
[publish-connection-parameter]
<= monitor-publish
......
......@@ -85,6 +85,7 @@ template-mariadb-init-root = {{ template_init_root_sql }}
template-init-root-wrapper = {{ template_init_root_wrapper }}
template-mysqld-wrapper = {{ template_mysqld_wrapper }}
template-mysqld-need-start = {{ mysqld_start_template }}
template-cleanup-db = {{ template_slave_db_cleanup }}
link-binary = {{ dumps(mariadb_link_binary) }}
check-computer-memory-binary = {{ bin_directory }}/check-computer-memory
bin-directory = {{ bin_directory }}
......
......@@ -84,6 +84,7 @@ context =
key template_init_root_wrapper init-root-wrapper-in:target
key template_repman_cfg instance-repman.cfg:target
key template_publish_slave template-publish-slave-information:target
key template_slave_db_cleanup slave-db-cleanup.in:target
key unixodbc_location unixodbc:location
key sysbench_location sysbench:location
key proxysql_location proxysql:location
......@@ -146,3 +147,6 @@ link-binary =
[proxy-need-start-stop.sh.in]
<= download-file
[slave-db-cleanup.in]
<= download-file
......@@ -2,7 +2,7 @@
run_mysql () {
{{ mysql_bin }} --defaults-file="{{ mysql_conf }}" \
--protocol=socket -uroot -hlocalhost $@
--protocol=socket -uroot -hlocalhost "$@"
}
if [ ! -f "{{ init_password_done }}" ]; then
......
......@@ -8,6 +8,8 @@ SOURCE {{ parameter_dict['mroonga-mariadb-install-sql'] }};
DROP FUNCTION IF EXISTS sphinx_snippets;
#CREATE FUNCTION sphinx_snippets RETURNS STRING SONAME 'ha_sphinx.so';
CREATE DATABASE IF NOT EXISTS `repman_slave_definition`;
{% macro database(name, user, password) -%}
CREATE DATABASE IF NOT EXISTS `{{ name }}`;
{% if user -%}
......@@ -17,6 +19,22 @@ GRANT ALL PRIVILEGES ON `{{ name }}`.* TO `{{ user }}`@'::' IDENTIFIED BY '{{ pa
{%- endif %}
{% endmacro -%}
{% set entry_list = [] -%}
{% for entry in parameter_dict['database-list'] -%}
{{ database(entry['name'], entry.get('user'), entry.get('password')) }}
{% do entry_list.append(entry['name']) -%}
{% endfor -%}
use repman_slave_definition;
CREATE TABLE IF NOT EXISTS `slave` (
`name` varchar(20) NOT NULL,
`state` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
UPDATE `slave` set `state`=false;
{% for name in entry_list -%}
REPLACE INTO `slave` VALUES ('{{ name }}', true);
{% endfor -%}
\ No newline at end of file
#!/bin/bash
run_mysql () {
{{ mysql_bin }} --defaults-file="{{ mysql_conf }}" \
--protocol=socket -uroot -hlocalhost "$@"
}
DBNAME=$(run_mysql -Be "SELECT name FROM repman_slave_definition.slave WHERE state=false");
RET=$?
if [ ! "$RET" = "0" ]; then
echo "Mysql command failed: $DBNAME"
exit $RET
fi
for NAME in $DBNAME; do
if [ ! "$NAME" = "name" ]; then
echo "Deleting database $NAME..."
run_mysql -e "DROP DATABASE `$NAME`";
echo "Done."
fi
done
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