2 system ? builtins.currentSystem,
4 pkgs ? import ../../.. { inherit system config; },
9 inherit (import ./common.nix { inherit pkgs lib; }) mkTestName mariadbPackages;
11 makeTest = import ./../make-test-python.nix;
13 # Common user configuration
17 name ? mkTestName mariadbPackage,
18 galeraPackage ? pkgs.mariadb-galera,
21 name = "${name}-galera-mariabackup";
23 maintainers = with lib.maintainers; [ izorkin ] ++ lib.teams.helsinki-systems.members;
26 # 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,
27 # and checking the table's presence on the other node.
36 address = "192.168.1.${toString id}";
37 isFirstClusterNode = id == 1 || id == 4;
45 groups.testusers = { };
56 ipv6.addresses = lib.mkForce [ ];
58 extraHosts = lib.concatMapStringsSep "\n" (i: "192.168.1.${toString i} galera_0${toString i}") (
61 firewall.allowedTCPPorts = [
67 firewall.allowedUDPPorts = [ 4567 ];
69 systemd.services.mysql = with pkgs; {
88 package = mariadbPackage;
89 ensureDatabases = lib.mkIf isFirstClusterNode [ "testdb" ];
90 ensureUsers = lib.mkIf isFirstClusterNode [
94 "testdb.*" = "ALL PRIVILEGES";
98 initialScript = lib.mkIf isFirstClusterNode (
99 pkgs.writeText "mariadb-init.sql" ''
100 GRANT ALL PRIVILEGES ON *.* TO 'check_repl'@'localhost' IDENTIFIED BY 'check_pass' WITH GRANT OPTION;
106 bind_address = "0.0.0.0";
110 wsrep_debug = "NONE";
111 wsrep_retry_autocommit = "3";
112 wsrep_provider = "${galeraPackage}/lib/galera/libgalera_smm.so";
113 wsrep_cluster_address =
115 + lib.optionalString (id == 2 || id == 3) "galera_01,galera_02,galera_03"
116 + lib.optionalString (id == 5 || id == 6) "galera_04,galera_05,galera_06";
117 wsrep_cluster_name = "galera";
118 wsrep_node_address = address;
119 wsrep_node_name = "galera_0${toString id}";
120 wsrep_sst_method = method;
121 wsrep_sst_auth = "check_repl:check_pass";
122 binlog_format = "ROW";
123 enforce_storage_engine = "InnoDB";
124 innodb_autoinc_lock_mode = "2";
131 galera_01 = mkGaleraNode {
133 method = "mariabackup";
136 galera_02 = mkGaleraNode {
138 method = "mariabackup";
141 galera_03 = mkGaleraNode {
143 method = "mariabackup";
146 galera_04 = mkGaleraNode {
151 galera_05 = mkGaleraNode {
156 galera_06 = mkGaleraNode {
165 galera_01.wait_for_unit("mysql")
166 galera_01.wait_for_open_port(3306)
168 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db1 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
171 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db1 values (37);'"
174 galera_02.wait_for_unit("mysql")
175 galera_02.wait_for_open_port(3306)
177 galera_03.wait_for_unit("mysql")
178 galera_03.wait_for_open_port(3306)
180 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db1;' -N | grep 37"
183 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db2 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
185 galera_02.succeed("systemctl stop mysql")
187 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db2 values (38);'"
190 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db3 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
193 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db3 values (39);'"
195 galera_02.succeed("systemctl start mysql")
196 galera_02.wait_for_open_port(3306)
198 "sudo -u testuser mysql -u testuser -e 'show status' -N | grep 'wsrep_cluster_size.*3'"
201 "sudo -u testuser mysql -u testuser -e 'show status' -N | grep 'wsrep_local_state_comment.*Synced'"
204 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db3;' -N | grep 39"
207 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db2;' -N | grep 38"
210 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db1;' -N | grep 37"
212 galera_01.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db3;'")
213 galera_02.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db2;'")
214 galera_03.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db1;'")
220 galera_04.wait_for_unit("mysql")
221 galera_04.wait_for_open_port(3306)
223 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db1 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
226 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db1 values (41);'"
229 galera_05.wait_for_unit("mysql")
230 galera_05.wait_for_open_port(3306)
232 galera_06.wait_for_unit("mysql")
233 galera_06.wait_for_open_port(3306)
235 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db1;' -N | grep 41"
238 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db2 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
240 galera_05.succeed("systemctl stop mysql")
242 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db2 values (42);'"
245 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db3 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
248 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db3 values (43);'"
250 galera_05.succeed("systemctl start mysql")
251 galera_05.wait_for_open_port(3306)
253 "sudo -u testuser mysql -u testuser -e 'show status' -N | grep 'wsrep_cluster_size.*3'"
256 "sudo -u testuser mysql -u testuser -e 'show status' -N | grep 'wsrep_local_state_comment.*Synced'"
259 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db3;' -N | grep 43"
262 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db2;' -N | grep 42"
265 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db1;' -N | grep 41"
267 galera_04.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db3;'")
268 galera_05.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db2;'")
269 galera_06.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db1;'")
273 lib.mapAttrs (_: mariadbPackage: makeGaleraTest { inherit mariadbPackage; }) mariadbPackages