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
b30539a9
Commit
b30539a9
authored
Jul 09, 2021
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
repman: update and remove slave database only on master mariadb
parent
688cc6bd
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
91 additions
and
61 deletions
+91
-61
software/repman/buildout.hash.cfg
software/repman/buildout.hash.cfg
+6
-6
software/repman/instance-mariadb.cfg.jinja2.in
software/repman/instance-mariadb.cfg.jinja2.in
+23
-13
software/repman/instance-repman.cfg.jinja2.in
software/repman/instance-repman.cfg.jinja2.in
+1
-1
software/repman/instance.cfg.in
software/repman/instance.cfg.in
+1
-1
software/repman/software.cfg
software/repman/software.cfg
+2
-2
software/repman/templates/mariadb_initial_setup.sql.in
software/repman/templates/mariadb_initial_setup.sql.in
+0
-16
software/repman/templates/slave-db-cleanup.in
software/repman/templates/slave-db-cleanup.in
+0
-22
software/repman/templates/slave-db-manage.in
software/repman/templates/slave-db-manage.in
+58
-0
No files found.
software/repman/buildout.hash.cfg
View file @
b30539a9
...
...
@@ -14,11 +14,11 @@
# not need these here).
[instance.cfg]
filename = instance.cfg.in
md5sum =
37eff9b6b85fcbd3930aa58a1e08d32e
md5sum =
9aeb37bd4590aa7fa746ef70d78cc0d0
[instance-repman.cfg]
_update_hash_filename_ = instance-repman.cfg.jinja2.in
md5sum =
140a5c8a8bf8a841f65f2aa767db2c38
md5sum =
287e446905a6905606f5e12ae38e533f
[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 =
27bbc3c979faf9a1a35daa2382ebc4d
f
md5sum =
e9c62f54824d7c6b549a864f9f67d0a
f
[template-my-cnf]
_update_hash_filename_ = templates/my.cnf.in
...
...
@@ -72,6 +72,6 @@ md5sum = 8f14054b3761b167cf8a86f4f084a574
_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
[slave-db-
manage
.in]
_update_hash_filename_ = templates/slave-db-
manage
.in
md5sum =
6af818d4513561eea7def0f4f8d42164
software/repman/instance-mariadb.cfg.jinja2.in
View file @
b30539a9
...
...
@@ -37,6 +37,22 @@ mode = 644
< = jinja2-template-base
mode = 755
[jinja2-template-script-base]
< = jinja2-template-executable
context =
key tmp_dir directory:tmp
key partition_dir buildout:directory
raw username {{ slapparameter_dict['repman-user'] }}
raw password {{ slapparameter_dict['repman-passwd'] }}
raw cluster_name {{ slapparameter_dict['cluster'] }}
raw secure_url {{ slapparameter_dict['repman-secure-url'] }}
raw mysql_conf ${directory:etc}/mysql/my.cnf
raw dash_bin {{ dash }}
raw jq_bin {{ jq_bin }}
raw curl_bin {{ curl_bin }}
raw mysql_bin {{ parameter_dict['mariadb-location'] }}/bin/mysql
${:extra-context}
[simplefile]
< = jinja2-template-base
template = inline:{{ '{{ content }}' }}
...
...
@@ -107,30 +123,24 @@ init-script = ${init-script:rendered}
mysql_tzinfo_to_sql = ${binary-wrap-mysql_tzinfo_to_sql:wrapper-path}
[{{ section('update-mysql-script') }}]
< = jinja2-template-
executabl
e
< = jinja2-template-
script-bas
e
rendered = ${directory:scripts}/mariadb_update
init-password = ${directory:etc}/.init-passwd.done
upgrade-done = ${directory:lib}/mariadb-update-done
context =
extra-
context =
key init_password_done :init-password
key upgrade_done :upgrade-done
key init_root_sql init-root-sql:rendered
key mysql_update update-mysql:output
key init_database_sql init-script:rendered
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'] }}
< = jinja2-template-script-base
rendered = ${directory:bin}/manage_slave_db
extra-context =
raw database_name {{ slapparameter_dict['database-name'] }}
template = {{ parameter_dict['template-manage-db'] }}
[mysqld]
< = jinja2-template-executable
...
...
software/repman/instance-repman.cfg.jinja2.in
View file @
b30539a9
...
...
@@ -107,7 +107,7 @@ config-monitor-passwd = ${publish-early:monitor-password}
config-root-password = ${publish-early:db-root-password}
config-repman-user = ${repman-parameter:username}
config-heartbeat-user = ${repman-parameter:heartbeat-user}
#
config-repman-passwd = ${repman-parameter:password}
config-repman-passwd = ${repman-parameter:password}
config-repman-url = ${nginx-parameter:backend-url}
config-repman-secure-url = ${nginx-parameter:backend-ssl-url}
config-cluster = {{ name }}
...
...
software/repman/instance.cfg.in
View file @
b30539a9
...
...
@@ -85,7 +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
}}
template-
manage-db = {{ template_slave_db_manage
}}
link-binary = {{ dumps(mariadb_link_binary) }}
check-computer-memory-binary = {{ bin_directory }}/check-computer-memory
bin-directory = {{ bin_directory }}
...
...
software/repman/software.cfg
View file @
b30539a9
...
...
@@ -84,7 +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 template_slave_db_
manage slave-db-manage
.in:target
key unixodbc_location unixodbc:location
key sysbench_location sysbench:location
key proxysql_location proxysql:location
...
...
@@ -148,5 +148,5 @@ link-binary =
[proxy-need-start-stop.sh.in]
<= download-file
[slave-db-
cleanup
.in]
[slave-db-
manage
.in]
<= download-file
software/repman/templates/mariadb_initial_setup.sql.in
View file @
b30539a9
...
...
@@ -19,22 +19,6 @@ 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 -%}
software/repman/templates/slave-db-cleanup.in
deleted
100644 → 0
View file @
688cc6bd
#!/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
software/repman/templates/slave-db-manage.in
0 → 100644
View file @
b30539a9
#!/bin/bash
curl
()
{
{{
curl_bin
}}
-k
--silent
-H
"Accept: application/json"
"
$@
"
}
get_token
()
{
curl
-s
-X
POST
--data
'{"username":"{{ username }}","password":"{{ password}}"}'
{{
secure_url
}}
/api/login
}
run_mysql
()
{
{{
mysql_bin
}}
--defaults-file
=
"{{ mysql_conf }}"
\
--protocol
=
socket
-uroot
-hlocalhost
"
$@
"
}
TOKEN
=
$(
get_token |
{{
jq_bin
}}
-r
'.token'
)
DATADIR
=
$(
curl
-H
"Authorization: Bearer
${
TOKEN
}
"
\
{{
secure_url
}}
/api/clusters/
{{
cluster_name
}}
/topology/master |
{{
jq_bin
}}
-r
'.slaposDatadir'
)
# Only write or delete on master database else, we break replication.
if
[
"
$DATADIR
"
=
"{{ partition_dir }}"
]
;
then
cat
<<
EOF
> {{ tmp_dir }}/.script.sql
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 database_name.split(' ') -%}
REPLACE INTO
\`
slave
\`
VALUES ('{{ name }}', true);
{% endfor -%}
EOF
# Update requested slaves database
run_mysql <
{{
tmp_dir
}}
/.script.sql
rm
-f
{{
tmp_dir
}}
/.script.sql
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 IF EXISTS
$NAME
"
;
run_mysql
-e
"DELETE FROM repman_slave_definition.slave WHERE name='
$NAME
'"
;
echo
"Done."
fi
done
fi
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