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
16 name ? mkTestName mariadbPackage,
17 galeraPackage ? pkgs.mariadb-galera
19 name = "${name}-galera-mariabackup";
20 meta = with pkgs.lib.maintainers; {
21 maintainers = [ izorkin ajs124 das_j ];
24 # 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,
25 # and checking the table's presence on the other node.
31 address = "192.168.1.${toString id}";
32 isFirstClusterNode = id == 1 || id == 4;
39 groups.testusers = { };
45 { inherit address; prefixLength = 24; }
48 extraHosts = lib.concatMapStringsSep "\n" (i: "192.168.1.${toString i} galera_0${toString i}") (lib.range 1 6);
49 firewall.allowedTCPPorts = [ 3306 4444 4567 4568 ];
50 firewall.allowedUDPPorts = [ 4567 ];
52 systemd.services.mysql = with pkgs; {
71 package = mariadbPackage;
72 ensureDatabases = lib.mkIf isFirstClusterNode [ "testdb" ];
73 ensureUsers = lib.mkIf isFirstClusterNode [{
76 "testdb.*" = "ALL PRIVILEGES";
79 initialScript = lib.mkIf isFirstClusterNode (pkgs.writeText "mariadb-init.sql" ''
80 GRANT ALL PRIVILEGES ON *.* TO 'check_repl'@'localhost' IDENTIFIED BY 'check_pass' WITH GRANT OPTION;
85 bind_address = "0.0.0.0";
90 wsrep_retry_autocommit = "3";
91 wsrep_provider = "${galeraPackage}/lib/galera/libgalera_smm.so";
92 wsrep_cluster_address = "gcomm://"
93 + lib.optionalString (id == 2 || id == 3) "galera_01,galera_02,galera_03"
94 + lib.optionalString (id == 5 || id == 6) "galera_04,galera_05,galera_06";
95 wsrep_cluster_name = "galera";
96 wsrep_node_address = address;
97 wsrep_node_name = "galera_0${toString id}";
98 wsrep_sst_method = method;
99 wsrep_sst_auth = "check_repl:check_pass";
100 binlog_format = "ROW";
101 enforce_storage_engine = "InnoDB";
102 innodb_autoinc_lock_mode = "2";
108 galera_01 = mkGaleraNode {
110 method = "mariabackup";
113 galera_02 = mkGaleraNode {
115 method = "mariabackup";
118 galera_03 = mkGaleraNode {
120 method = "mariabackup";
123 galera_04 = mkGaleraNode {
128 galera_05 = mkGaleraNode {
133 galera_06 = mkGaleraNode {
142 galera_01.wait_for_unit("mysql")
143 galera_01.wait_for_open_port(3306)
145 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db1 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
148 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db1 values (37);'"
151 galera_02.wait_for_unit("mysql")
152 galera_02.wait_for_open_port(3306)
154 galera_03.wait_for_unit("mysql")
155 galera_03.wait_for_open_port(3306)
157 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db1;' -N | grep 37"
160 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db2 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
162 galera_02.succeed("systemctl stop mysql")
164 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db2 values (38);'"
167 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db3 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
170 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db3 values (39);'"
172 galera_02.succeed("systemctl start mysql")
173 galera_02.wait_for_open_port(3306)
175 "sudo -u testuser mysql -u testuser -e 'show status' -N | grep 'wsrep_cluster_size.*3'"
178 "sudo -u testuser mysql -u testuser -e 'show status' -N | grep 'wsrep_local_state_comment.*Synced'"
181 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db3;' -N | grep 39"
184 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db2;' -N | grep 38"
187 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db1;' -N | grep 37"
189 galera_01.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db3;'")
190 galera_02.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db2;'")
191 galera_03.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db1;'")
197 galera_04.wait_for_unit("mysql")
198 galera_04.wait_for_open_port(3306)
200 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db1 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
203 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db1 values (41);'"
206 galera_05.wait_for_unit("mysql")
207 galera_05.wait_for_open_port(3306)
209 galera_06.wait_for_unit("mysql")
210 galera_06.wait_for_open_port(3306)
212 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db1;' -N | grep 41"
215 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db2 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
217 galera_05.succeed("systemctl stop mysql")
219 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db2 values (42);'"
222 "sudo -u testuser mysql -u testuser -e 'use testdb; create table db3 (test_id INT, PRIMARY KEY (test_id)) ENGINE = InnoDB;'"
225 "sudo -u testuser mysql -u testuser -e 'use testdb; insert into db3 values (43);'"
227 galera_05.succeed("systemctl start mysql")
228 galera_05.wait_for_open_port(3306)
230 "sudo -u testuser mysql -u testuser -e 'show status' -N | grep 'wsrep_cluster_size.*3'"
233 "sudo -u testuser mysql -u testuser -e 'show status' -N | grep 'wsrep_local_state_comment.*Synced'"
236 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db3;' -N | grep 43"
239 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db2;' -N | grep 42"
242 "sudo -u testuser mysql -u testuser -e 'use testdb; select test_id from db1;' -N | grep 41"
244 galera_04.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db3;'")
245 galera_05.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db2;'")
246 galera_06.succeed("sudo -u testuser mysql -u testuser -e 'use testdb; drop table db1;'")
250 lib.mapAttrs (_: mariadbPackage: makeGaleraTest { inherit mariadbPackage; }) mariadbPackages