Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ivan Tyagov
slapos
Commits
e4579253
Commit
e4579253
authored
Jul 08, 2021
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repman: destroy slave database if not slave instance is destroyed
parent
3ebe4aff
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
77 additions
and
12 deletions
+77
-12
software/repman/buildout.hash.cfg
software/repman/buildout.hash.cfg
+9
-5
software/repman/instance-mariadb.cfg.jinja2.in
software/repman/instance-mariadb.cfg.jinja2.in
+18
-0
software/repman/instance-repman.cfg.jinja2.in
software/repman/instance-repman.cfg.jinja2.in
+4
-6
software/repman/instance.cfg.in
software/repman/instance.cfg.in
+1
-0
software/repman/software.cfg
software/repman/software.cfg
+4
-0
software/repman/templates/init_root_wrapper.in
software/repman/templates/init_root_wrapper.in
+1
-1
software/repman/templates/mariadb_initial_setup.sql.in
software/repman/templates/mariadb_initial_setup.sql.in
+18
-0
software/repman/templates/slave-db-cleanup.in
software/repman/templates/slave-db-cleanup.in
+22
-0
No files found.
software/repman/buildout.hash.cfg
View file @
e4579253
...
@@ -14,11 +14,11 @@
...
@@ -14,11 +14,11 @@
# not need these here).
# not need these here).
[instance.cfg]
[instance.cfg]
filename = instance.cfg.in
filename = instance.cfg.in
md5sum =
1812befaf367f30a1fe469ccf95dae31
md5sum =
37eff9b6b85fcbd3930aa58a1e08d32e
[instance-repman.cfg]
[instance-repman.cfg]
_update_hash_filename_ = instance-repman.cfg.jinja2.in
_update_hash_filename_ = instance-repman.cfg.jinja2.in
md5sum =
b65e982e82dbef25cc71c12f91185e03
md5sum =
3faea4a761b4a48aa4c141cf8f267059
[config-toml.in]
[config-toml.in]
_update_hash_filename_ = templates/config.toml.in
_update_hash_filename_ = templates/config.toml.in
...
@@ -34,7 +34,7 @@ md5sum = 0eeb24c6aa0760f0d33c4cc2828ddf30
...
@@ -34,7 +34,7 @@ md5sum = 0eeb24c6aa0760f0d33c4cc2828ddf30
[template-mariadb.cfg]
[template-mariadb.cfg]
_update_hash_filename_ = instance-mariadb.cfg.jinja2.in
_update_hash_filename_ = instance-mariadb.cfg.jinja2.in
md5sum = 2
3d71176700487eb5e5240f6ad6cdce6
md5sum = 2
7bbc3c979faf9a1a35daa2382ebc4df
[template-my-cnf]
[template-my-cnf]
_update_hash_filename_ = templates/my.cnf.in
_update_hash_filename_ = templates/my.cnf.in
...
@@ -42,7 +42,7 @@ md5sum = f3661b788099bb31d71ba6e7d36836d9
...
@@ -42,7 +42,7 @@ md5sum = f3661b788099bb31d71ba6e7d36836d9
[template-mariadb-initial-setup]
[template-mariadb-initial-setup]
_update_hash_filename_ = templates/mariadb_initial_setup.sql.in
_update_hash_filename_ = templates/mariadb_initial_setup.sql.in
md5sum =
df44c2d6fb1971df582345daedad280c
md5sum =
c300e9c2fb67a5d41fadc572f4c02216
[template-publish-slave-information]
[template-publish-slave-information]
_update_hash_filename_ = publish-database-slave-parameters.cfg.in
_update_hash_filename_ = publish-database-slave-parameters.cfg.in
...
@@ -54,7 +54,7 @@ md5sum = d8a0a7d72b02f911dafda655941b805d
...
@@ -54,7 +54,7 @@ md5sum = d8a0a7d72b02f911dafda655941b805d
[init-root-wrapper-in]
[init-root-wrapper-in]
_update_hash_filename_ = templates/init_root_wrapper.in
_update_hash_filename_ = templates/init_root_wrapper.in
md5sum =
cc3745fdaa248e297d19076b664e3bb5
md5sum =
b3dffa3c8b9b2cc86b536d411cbde9d4
[repman-manager-sh.in]
[repman-manager-sh.in]
_update_hash_filename_ = templates/repman-manager.sh.in
_update_hash_filename_ = templates/repman-manager.sh.in
...
@@ -71,3 +71,7 @@ md5sum = 8f14054b3761b167cf8a86f4f084a574
...
@@ -71,3 +71,7 @@ md5sum = 8f14054b3761b167cf8a86f4f084a574
[proxy-need-start-stop.sh.in]
[proxy-need-start-stop.sh.in]
_update_hash_filename_ = templates/proxy-need-start-stop.sh.in
_update_hash_filename_ = templates/proxy-need-start-stop.sh.in
md5sum = 455aaf369bf5141758dc57f2c0e67b08
md5sum = 455aaf369bf5141758dc57f2c0e67b08
[slave-db-cleanup.in]
_update_hash_filename_ = templates/slave-db-cleanup.in
md5sum = d9838ccd037b382e20b9faf412305f82
software/repman/instance-mariadb.cfg.jinja2.in
View file @
e4579253
...
@@ -92,6 +92,7 @@ heartbeat-user = {{ slapparameter_dict['heartbeat-user'] }}
...
@@ -92,6 +92,7 @@ heartbeat-user = {{ slapparameter_dict['heartbeat-user'] }}
[init-script]
[init-script]
< = jinja2-template-executable
< = jinja2-template-executable
extensions = jinja2.ext.do
# XXX: is there a better location ?
# XXX: is there a better location ?
rendered = ${directory:etc}/mariadb_initial_setup.sql
rendered = ${directory:etc}/mariadb_initial_setup.sql
template = {{ parameter_dict['template-mariadb-initial-setup'] }}
template = {{ parameter_dict['template-mariadb-initial-setup'] }}
...
@@ -119,8 +120,18 @@ context =
...
@@ -119,8 +120,18 @@ context =
raw mysql_conf ${directory:etc}/mysql/my.cnf
raw mysql_conf ${directory:etc}/mysql/my.cnf
raw dash_bin {{ dash }}
raw dash_bin {{ dash }}
raw mysql_bin {{ parameter_dict['mariadb-location'] }}/bin/mysql
raw mysql_bin {{ parameter_dict['mariadb-location'] }}/bin/mysql
raw database-list {{ slapparameter_dict['database-name'] }}
template = {{ parameter_dict['template-init-root-wrapper'] }}
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]
[mysqld]
< = jinja2-template-executable
< = jinja2-template-executable
rendered = ${directory:bin}/mysqld
rendered = ${directory:bin}/mysqld
...
@@ -286,6 +297,13 @@ name = mariadb-need-start
...
@@ -286,6 +297,13 @@ name = mariadb-need-start
frequency = * * * * *
frequency = * * * * *
command = ${template-mysqld-need-start:rendered}
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]
[template-mysqld-need-start]
< = jinja2-template-executable
< = jinja2-template-executable
rendered = ${directory:bin}/mysqld_need_start
rendered = ${directory:bin}/mysqld_need_start
...
...
software/repman/instance-repman.cfg.jinja2.in
View file @
e4579253
...
@@ -11,6 +11,7 @@
...
@@ -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 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 frontend_parameter_dict = slapparameter_dict.get('slave-frontend', {}) -%}
{% set dabase_slave_list = [] -%}
{% set dabase_slave_list = [] -%}
{% set db_name_list = [] -%}
[directory]
[directory]
recipe = slapos.cookbook:mkdirectory
recipe = slapos.cookbook:mkdirectory
...
@@ -59,7 +60,6 @@ template = inline:#!{{ bash_bin }}
...
@@ -59,7 +60,6 @@ template = inline:#!{{ bash_bin }}
rendered = ${directory:bin}/update-proxysql-config
rendered = ${directory:bin}/update-proxysql-config
mode = 755
mode = 755
{% set db_name_list = [] -%}
[database-slave-information]
[database-slave-information]
{% for instance_dict in slave_instance_list -%}
{% for instance_dict in slave_instance_list -%}
{% set slave_dict = {
{% set slave_dict = {
...
@@ -72,6 +72,7 @@ mode = 755
...
@@ -72,6 +72,7 @@ mode = 755
{% do dabase_slave_list.append(slave_dict) -%}
{% do dabase_slave_list.append(slave_dict) -%}
{% do db_name_list.append(slave_dict['name']) -%}
{% do db_name_list.append(slave_dict['name']) -%}
{% endfor %}
{% endfor %}
{% set db_list = db_name_list | join(' ') -%}
{% do mariadb_dict.__setitem__('computer-memory-percent-threshold', 80) -%}
{% do mariadb_dict.__setitem__('computer-memory-percent-threshold', 80) -%}
{% set default_parameter_dict = {"cluster1": {"name": "cluster1", "db-prefered-master": "",
{% set default_parameter_dict = {"cluster1": {"name": "cluster1", "db-prefered-master": "",
...
@@ -112,6 +113,7 @@ config-repman-secure-url = ${nginx-parameter:backend-ssl-url}
...
@@ -112,6 +113,7 @@ config-repman-secure-url = ${nginx-parameter:backend-ssl-url}
config-cluster = {{ name }}
config-cluster = {{ name }}
config-name = {{ dbname }}
config-name = {{ dbname }}
config-database-list = {{ dumps(dabase_slave_list) }}
config-database-list = {{ dumps(dabase_slave_list) }}
config-database-name = {{ dumps(db_list) }}
return =
return =
database-host
database-host
receiver-port
receiver-port
...
@@ -484,17 +486,13 @@ name = nginx
...
@@ -484,17 +486,13 @@ name = nginx
log = ${nginx-parameter:access-log} ${nginx-parameter:error-log}
log = ${nginx-parameter:access-log} ${nginx-parameter:error-log}
post = kill -USR1 $(cat ${nginx-parameter:pid-file})
post = kill -USR1 $(cat ${nginx-parameter:pid-file})
{% set db_list = db_name_list | join(' ') -%}
[db-slave-requested]
name = {{ db_list }}
[publish-early]
[publish-early]
recipe = slapos.cookbook:publish-early
recipe = slapos.cookbook:publish-early
-init =
-init =
monitor-password monitor-htpasswd:passwd
monitor-password monitor-htpasswd:passwd
db-root-password gen-root-password:passwd
db-root-password gen-root-password:passwd
repman-password repman-password:passwd
repman-password repman-password:passwd
database-list db-slave-requested:name
database-list = {{ db_list }}
[publish-connection-parameter]
[publish-connection-parameter]
<= monitor-publish
<= monitor-publish
...
...
software/repman/instance.cfg.in
View file @
e4579253
...
@@ -85,6 +85,7 @@ template-mariadb-init-root = {{ template_init_root_sql }}
...
@@ -85,6 +85,7 @@ template-mariadb-init-root = {{ template_init_root_sql }}
template-init-root-wrapper = {{ template_init_root_wrapper }}
template-init-root-wrapper = {{ template_init_root_wrapper }}
template-mysqld-wrapper = {{ template_mysqld_wrapper }}
template-mysqld-wrapper = {{ template_mysqld_wrapper }}
template-mysqld-need-start = {{ mysqld_start_template }}
template-mysqld-need-start = {{ mysqld_start_template }}
template-cleanup-db = {{ template_slave_db_cleanup }}
link-binary = {{ dumps(mariadb_link_binary) }}
link-binary = {{ dumps(mariadb_link_binary) }}
check-computer-memory-binary = {{ bin_directory }}/check-computer-memory
check-computer-memory-binary = {{ bin_directory }}/check-computer-memory
bin-directory = {{ bin_directory }}
bin-directory = {{ bin_directory }}
...
...
software/repman/software.cfg
View file @
e4579253
...
@@ -84,6 +84,7 @@ context =
...
@@ -84,6 +84,7 @@ context =
key template_init_root_wrapper init-root-wrapper-in:target
key template_init_root_wrapper init-root-wrapper-in:target
key template_repman_cfg instance-repman.cfg:target
key template_repman_cfg instance-repman.cfg:target
key template_publish_slave template-publish-slave-information: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 unixodbc_location unixodbc:location
key sysbench_location sysbench:location
key sysbench_location sysbench:location
key proxysql_location proxysql:location
key proxysql_location proxysql:location
...
@@ -146,3 +147,6 @@ link-binary =
...
@@ -146,3 +147,6 @@ link-binary =
[proxy-need-start-stop.sh.in]
[proxy-need-start-stop.sh.in]
<= download-file
<= download-file
[slave-db-cleanup.in]
<= download-file
software/repman/templates/init_root_wrapper.in
View file @
e4579253
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
run_mysql
()
{
run_mysql
()
{
{{
mysql_bin
}}
--defaults-file
=
"{{ mysql_conf }}"
\
{{
mysql_bin
}}
--defaults-file
=
"{{ mysql_conf }}"
\
--protocol
=
socket
-uroot
-hlocalhost
$@
--protocol
=
socket
-uroot
-hlocalhost
"
$@
"
}
}
if
[
!
-f
"{{ init_password_done }}"
]
;
then
if
[
!
-f
"{{ init_password_done }}"
]
;
then
...
...
software/repman/templates/mariadb_initial_setup.sql.in
View file @
e4579253
...
@@ -8,6 +8,8 @@ SOURCE {{ parameter_dict['mroonga-mariadb-install-sql'] }};
...
@@ -8,6 +8,8 @@ SOURCE {{ parameter_dict['mroonga-mariadb-install-sql'] }};
DROP FUNCTION IF EXISTS sphinx_snippets;
DROP FUNCTION IF EXISTS sphinx_snippets;
#CREATE FUNCTION sphinx_snippets RETURNS STRING SONAME 'ha_sphinx.so';
#CREATE FUNCTION sphinx_snippets RETURNS STRING SONAME 'ha_sphinx.so';
CREATE DATABASE IF NOT EXISTS `repman_slave_definition`;
{% macro database(name, user, password) -%}
{% macro database(name, user, password) -%}
CREATE DATABASE IF NOT EXISTS `{{ name }}`;
CREATE DATABASE IF NOT EXISTS `{{ name }}`;
{% if user -%}
{% if user -%}
...
@@ -17,6 +19,22 @@ GRANT ALL PRIVILEGES ON `{{ name }}`.* TO `{{ user }}`@'::' IDENTIFIED BY '{{ pa
...
@@ -17,6 +19,22 @@ GRANT ALL PRIVILEGES ON `{{ name }}`.* TO `{{ user }}`@'::' IDENTIFIED BY '{{ pa
{%- endif %}
{%- endif %}
{% endmacro -%}
{% endmacro -%}
{% set entry_list = [] -%}
{% for entry in parameter_dict['database-list'] -%}
{% for entry in parameter_dict['database-list'] -%}
{{ database(entry['name'], entry.get('user'), entry.get('password')) }}
{{ database(entry['name'], entry.get('user'), entry.get('password')) }}
{% do entry_list.append(entry['name']) -%}
{% endfor -%}
{% 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
software/repman/templates/slave-db-cleanup.in
0 → 100644
View file @
e4579253
#!/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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment