2021-12-08 09:47:07 +00:00
{
system ? builtins . currentSystem ,
2024-09-23 18:00:19 +00:00
config ? { } ,
2021-12-08 09:47:07 +00:00
pkgs ? import ../../.. { inherit system config ; } ,
2024-09-23 18:00:19 +00:00
lib ? pkgs . lib ,
2021-12-08 09:47:07 +00:00
} :
let
inherit ( import ./common.nix { inherit pkgs lib ; } ) mkTestName mariadbPackages ;
makeTest = import ./../make-test-python.nix ;
# Common user configuration
2024-09-23 18:00:19 +00:00
makeGaleraTest =
{
mariadbPackage ,
name ? mkTestName mariadbPackage ,
galeraPackage ? pkgs . mariadb-galera ,
} :
makeTest {
name = " ${ name } - g a l e r a - m a r i a b a c k u p " ;
meta = {
maintainers = with lib . maintainers ; [ izorkin ] ++ lib . teams . helsinki-systems . members ;
} ;
2021-12-08 09:47:07 +00:00
2024-09-23 18:00:19 +00:00
# The test creates a Galera cluster with 3 nodes and is checking if mariabackup-based SST works. The cluster is tested by creating a DB and an empty table on one node,
# and checking the table's presence on the other node.
nodes =
let
mkGaleraNode =
{
id ,
method ,
} :
let
address = " 1 9 2 . 1 6 8 . 1 . ${ toString id } " ;
isFirstClusterNode = id == 1 || id == 4 ;
in
{
users = {
users . testuser = {
isSystemUser = true ;
group = " t e s t u s e r s " ;
} ;
groups . testusers = { } ;
} ;
2021-12-08 09:47:07 +00:00
2024-09-23 18:00:19 +00:00
networking = {
interfaces . eth1 = {
ipv4 . addresses = [
{
inherit address ;
prefixLength = 24 ;
}
] ;
ipv6 . addresses = lib . mkForce [ ] ;
} ;
extraHosts = lib . concatMapStringsSep " \n " ( i : " 1 9 2 . 1 6 8 . 1 . ${ toString i } g a l e r a _ 0 ${ toString i } " ) (
lib . range 1 6
) ;
firewall . allowedTCPPorts = [
3306
4444
4567
4568
] ;
firewall . allowedUDPPorts = [ 4567 ] ;
} ;
systemd . services . mysql = with pkgs ; {
path = with pkgs ; [
bash
gawk
gnutar
gzip
inetutils
iproute2
netcat
procps
pv
rsync
socat
stunnel
which
] ;
} ;
services . mysql = {
enable = true ;
package = mariadbPackage ;
ensureDatabases = lib . mkIf isFirstClusterNode [ " t e s t d b " ] ;
ensureUsers = lib . mkIf isFirstClusterNode [
{
name = " t e s t u s e r " ;
ensurePermissions = {
" t e s t d b . * " = " A L L P R I V I L E G E S " ;
} ;
}
] ;
initialScript = lib . mkIf isFirstClusterNode (
pkgs . writeText " m a r i a d b - i n i t . s q l " ''
GRANT ALL PRIVILEGES ON * . * TO ' check_repl' @ ' localhost' IDENTIFIED BY ' check_pass' WITH GRANT OPTION ;
FLUSH PRIVILEGES ;
''
) ;
settings = {
mysqld = {
bind_address = " 0 . 0 . 0 . 0 " ;
} ;
galera = {
wsrep_on = " O N " ;
wsrep_debug = " N O N E " ;
wsrep_retry_autocommit = " 3 " ;
wsrep_provider = " ${ galeraPackage } / l i b / g a l e r a / l i b g a l e r a _ s m m . s o " ;
wsrep_cluster_address =
" g c o m m : / / "
+ lib . optionalString ( id == 2 || id == 3 ) " g a l e r a _ 0 1 , g a l e r a _ 0 2 , g a l e r a _ 0 3 "
+ lib . optionalString ( id == 5 || id == 6 ) " g a l e r a _ 0 4 , g a l e r a _ 0 5 , g a l e r a _ 0 6 " ;
wsrep_cluster_name = " g a l e r a " ;
wsrep_node_address = address ;
wsrep_node_name = " g a l e r a _ 0 ${ toString id } " ;
wsrep_sst_method = method ;
wsrep_sst_auth = " c h e c k _ r e p l : c h e c k _ p a s s " ;
binlog_format = " R O W " ;
enforce_storage_engine = " I n n o D B " ;
innodb_autoinc_lock_mode = " 2 " ;
} ;
} ;
} ;
2021-12-08 09:47:07 +00:00
} ;
2024-09-23 18:00:19 +00:00
in
{
galera_01 = mkGaleraNode {
id = 1 ;
method = " m a r i a b a c k u p " ;
2021-12-08 09:47:07 +00:00
} ;
2024-09-23 18:00:19 +00:00
galera_02 = mkGaleraNode {
id = 2 ;
method = " m a r i a b a c k u p " ;
} ;
2021-12-08 09:47:07 +00:00
2024-09-23 18:00:19 +00:00
galera_03 = mkGaleraNode {
id = 3 ;
method = " m a r i a b a c k u p " ;
} ;
2021-12-08 09:47:07 +00:00
2024-09-23 18:00:19 +00:00
galera_04 = mkGaleraNode {
id = 4 ;
method = " r s y n c " ;
} ;
2021-12-08 09:47:07 +00:00
2024-09-23 18:00:19 +00:00
galera_05 = mkGaleraNode {
id = 5 ;
method = " r s y n c " ;
} ;
2021-12-08 09:47:07 +00:00
2024-09-23 18:00:19 +00:00
galera_06 = mkGaleraNode {
id = 6 ;
method = " r s y n c " ;
} ;
2021-12-08 09:47:07 +00:00
2024-09-23 18:00:19 +00:00
} ;
2021-12-08 09:47:07 +00:00
2024-09-23 18:00:19 +00:00
testScript = ''
galera_01 . start ( )
galera_01 . wait_for_unit ( " m y s q l " )
galera_01 . wait_for_open_port ( 3306 )
galera_01 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; c r e a t e t a b l e d b 1 ( t e s t _ i d I N T , P R I M A R Y K E Y ( t e s t _ i d ) ) E N G I N E = I n n o D B ; ' "
)
galera_01 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; i n s e r t i n t o d b 1 v a l u e s ( 3 7 ) ; ' "
)
galera_02 . start ( )
galera_02 . wait_for_unit ( " m y s q l " )
galera_02 . wait_for_open_port ( 3306 )
galera_03 . start ( )
galera_03 . wait_for_unit ( " m y s q l " )
galera_03 . wait_for_open_port ( 3306 )
galera_02 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; s e l e c t t e s t _ i d f r o m d b 1 ; ' - N | g r e p 3 7 "
)
galera_02 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; c r e a t e t a b l e d b 2 ( t e s t _ i d I N T , P R I M A R Y K E Y ( t e s t _ i d ) ) E N G I N E = I n n o D B ; ' "
)
galera_02 . succeed ( " s y s t e m c t l s t o p m y s q l " )
galera_01 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; i n s e r t i n t o d b 2 v a l u e s ( 3 8 ) ; ' "
)
galera_03 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; c r e a t e t a b l e d b 3 ( t e s t _ i d I N T , P R I M A R Y K E Y ( t e s t _ i d ) ) E N G I N E = I n n o D B ; ' "
)
galera_01 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; i n s e r t i n t o d b 3 v a l u e s ( 3 9 ) ; ' "
)
galera_02 . succeed ( " s y s t e m c t l s t a r t m y s q l " )
galera_02 . wait_for_open_port ( 3306 )
galera_02 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' s h o w s t a t u s ' - N | g r e p ' w s r e p _ c l u s t e r _ s i z e . * 3 ' "
)
galera_03 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' s h o w s t a t u s ' - N | g r e p ' w s r e p _ l o c a l _ s t a t e _ c o m m e n t . * S y n c e d ' "
)
galera_01 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; s e l e c t t e s t _ i d f r o m d b 3 ; ' - N | g r e p 3 9 "
)
galera_02 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; s e l e c t t e s t _ i d f r o m d b 2 ; ' - N | g r e p 3 8 "
)
galera_03 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; s e l e c t t e s t _ i d f r o m d b 1 ; ' - N | g r e p 3 7 "
)
galera_01 . succeed ( " s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; d r o p t a b l e d b 3 ; ' " )
galera_02 . succeed ( " s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; d r o p t a b l e d b 2 ; ' " )
galera_03 . succeed ( " s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; d r o p t a b l e d b 1 ; ' " )
galera_01 . crash ( )
galera_02 . crash ( )
galera_03 . crash ( )
2021-12-08 09:47:07 +00:00
2024-09-23 18:00:19 +00:00
galera_04 . start ( )
galera_04 . wait_for_unit ( " m y s q l " )
galera_04 . wait_for_open_port ( 3306 )
galera_04 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; c r e a t e t a b l e d b 1 ( t e s t _ i d I N T , P R I M A R Y K E Y ( t e s t _ i d ) ) E N G I N E = I n n o D B ; ' "
)
galera_04 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; i n s e r t i n t o d b 1 v a l u e s ( 4 1 ) ; ' "
)
galera_05 . start ( )
galera_05 . wait_for_unit ( " m y s q l " )
galera_05 . wait_for_open_port ( 3306 )
galera_06 . start ( )
galera_06 . wait_for_unit ( " m y s q l " )
galera_06 . wait_for_open_port ( 3306 )
galera_05 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; s e l e c t t e s t _ i d f r o m d b 1 ; ' - N | g r e p 4 1 "
)
galera_05 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; c r e a t e t a b l e d b 2 ( t e s t _ i d I N T , P R I M A R Y K E Y ( t e s t _ i d ) ) E N G I N E = I n n o D B ; ' "
)
galera_05 . succeed ( " s y s t e m c t l s t o p m y s q l " )
galera_04 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; i n s e r t i n t o d b 2 v a l u e s ( 4 2 ) ; ' "
)
galera_06 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; c r e a t e t a b l e d b 3 ( t e s t _ i d I N T , P R I M A R Y K E Y ( t e s t _ i d ) ) E N G I N E = I n n o D B ; ' "
)
galera_04 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; i n s e r t i n t o d b 3 v a l u e s ( 4 3 ) ; ' "
)
galera_05 . succeed ( " s y s t e m c t l s t a r t m y s q l " )
galera_05 . wait_for_open_port ( 3306 )
galera_05 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' s h o w s t a t u s ' - N | g r e p ' w s r e p _ c l u s t e r _ s i z e . * 3 ' "
)
galera_06 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' s h o w s t a t u s ' - N | g r e p ' w s r e p _ l o c a l _ s t a t e _ c o m m e n t . * S y n c e d ' "
)
galera_04 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; s e l e c t t e s t _ i d f r o m d b 3 ; ' - N | g r e p 4 3 "
)
galera_05 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; s e l e c t t e s t _ i d f r o m d b 2 ; ' - N | g r e p 4 2 "
)
galera_06 . succeed (
" s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; s e l e c t t e s t _ i d f r o m d b 1 ; ' - N | g r e p 4 1 "
)
galera_04 . succeed ( " s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; d r o p t a b l e d b 3 ; ' " )
galera_05 . succeed ( " s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; d r o p t a b l e d b 2 ; ' " )
galera_06 . succeed ( " s u d o - u t e s t u s e r m y s q l - u t e s t u s e r - e ' u s e t e s t d b ; d r o p t a b l e d b 1 ; ' " )
'' ;
} ;
2021-12-08 09:47:07 +00:00
in
2024-09-23 18:00:19 +00:00
lib . mapAttrs ( _ : mariadbPackage : makeGaleraTest { inherit mariadbPackage ; } ) mariadbPackages