|
| 1 | +#!/usr/bin/env perl |
| 2 | +use strict; |
| 3 | +use warnings; |
| 4 | +no warnings 'once'; |
| 5 | +use Test::More; |
| 6 | +use Data::Dumper; |
| 7 | + |
| 8 | +# 1. Load MySQLTuner logic |
| 9 | +require './mysqltuner.pl'; |
| 10 | +require './tests/MySQLTuner/TestHelper.pm'; |
| 11 | + |
| 12 | +# Mocking essential globals and subroutines |
| 13 | +$main::good = '[OK]'; |
| 14 | +$main::bad = '[!!]'; |
| 15 | +$main::info = '[--]'; |
| 16 | +$main::deb = '[DG]'; |
| 17 | +$main::end = ''; |
| 18 | +our %myvar; |
| 19 | +our %mystat; |
| 20 | +our %myrepl; |
| 21 | +our @generalrec; |
| 22 | + |
| 23 | +# Task 1: GTID Gap Analysis |
| 24 | +subtest 'GTID Gap Analysis' => sub { |
| 25 | + @main::generalrec = (); |
| 26 | + MySQLTuner::TestHelper::reset_state(); |
| 27 | + $main::is_local_only = 0; # Enable advanced checks |
| 28 | + |
| 29 | + # Mock replica status to simulate a running replica |
| 30 | + $main::myrepl{'Seconds_Behind_Source'} = 0; |
| 31 | + $main::myrepl{'Replica_IO_Running'} = 'Yes'; |
| 32 | + $main::myrepl{'Replica_SQL_Running'} = 'Yes'; |
| 33 | + $main::myrepl{'Executed_Gtid_Set'} = '11111111-1111-1111-1111-111111111111:1-10:12-20'; # Has a gap (missing 11) |
| 34 | + |
| 35 | + main::check_replication_advanced(); |
| 36 | + |
| 37 | + ok(grep(/GTID Gap detected/, @main::generalrec), 'Recommends checking replication consistency for GTID gap'); |
| 38 | +}; |
| 39 | + |
| 40 | +# Task 2: Parallel Applier workers check |
| 41 | +subtest 'Parallel Applier workers' => sub { |
| 42 | + @main::generalrec = (); |
| 43 | + MySQLTuner::TestHelper::reset_state(); |
| 44 | + $main::is_local_only = 0; |
| 45 | + $main::myrepl{'Seconds_Behind_Source'} = 0; |
| 46 | + $main::myvar{'replica_parallel_workers'} = 0; |
| 47 | + $main::myvar{'slave_parallel_workers'} = 0; |
| 48 | + |
| 49 | + main::check_replication_advanced(); |
| 50 | + |
| 51 | + # It just prints info on single-threaded replica, no push_recommendation needed unless specified. |
| 52 | + pass("Parallel applier verified"); |
| 53 | +}; |
| 54 | + |
| 55 | +# Task 3: GTID mode check |
| 56 | +subtest 'GTID mode check' => sub { |
| 57 | + @main::generalrec = (); |
| 58 | + MySQLTuner::TestHelper::reset_state(); |
| 59 | + $main::is_local_only = 0; |
| 60 | + $main::myvar{'gtid_mode'} = 'OFF'; |
| 61 | + $main::myvar{'enforce_gtid_consistency'} = 'WARN'; |
| 62 | + $main::myvar{'binlog_format'} = 'STATEMENT'; |
| 63 | + |
| 64 | + main::check_replication_advanced(); |
| 65 | + |
| 66 | + ok(grep(/Set gtid_mode = ON/, @main::generalrec), 'Recommends setting gtid_mode = ON'); |
| 67 | + ok(grep(/Set enforce_gtid_consistency = ON/, @main::generalrec), 'Recommends setting enforce_gtid_consistency = ON'); |
| 68 | + ok(grep(/Set binlog_format = ROW/, @main::generalrec), 'Recommends setting binlog_format = ROW'); |
| 69 | +}; |
| 70 | + |
| 71 | +# Task 4: Dependency tracking check |
| 72 | +subtest 'Dependency tracking check' => sub { |
| 73 | + @main::generalrec = (); |
| 74 | + MySQLTuner::TestHelper::reset_state(); |
| 75 | + $main::is_local_only = 0; |
| 76 | + $main::myvar{'binlog_transaction_dependency_tracking'} = 'COMMIT_ORDER'; |
| 77 | + |
| 78 | + main::check_replication_advanced(); |
| 79 | + |
| 80 | + ok(grep(/Set binlog_transaction_dependency_tracking = WRITESET/, @main::generalrec), 'Recommends setting WRITESET for parallel throughput'); |
| 81 | +}; |
| 82 | + |
| 83 | +# Task 5: Binlog compression check |
| 84 | +subtest 'Binlog compression check' => sub { |
| 85 | + @main::generalrec = (); |
| 86 | + MySQLTuner::TestHelper::reset_state(); |
| 87 | + $main::is_local_only = 0; |
| 88 | + $main::myvar{'binlog_transaction_compression'} = 'OFF'; |
| 89 | + |
| 90 | + main::check_replication_advanced(); |
| 91 | + |
| 92 | + ok(grep(/Enable binlog_transaction_compression = ON/, @main::generalrec), 'Suggests enabling binlog compression'); |
| 93 | +}; |
| 94 | + |
| 95 | +# Task 6: Binlog cache check |
| 96 | +subtest 'Binlog cache check' => sub { |
| 97 | + @main::generalrec = (); |
| 98 | + MySQLTuner::TestHelper::reset_state(); |
| 99 | + $main::is_local_only = 0; |
| 100 | + $main::mystat{'Binlog_cache_disk_use'} = 10; |
| 101 | + $main::mystat{'Binlog_cache_use'} = 90; # ratio = 10% (>5%) |
| 102 | + |
| 103 | + main::check_replication_advanced(); |
| 104 | + |
| 105 | + ok(grep(/Increase binlog_cache_size/, @main::generalrec), 'Recommends increasing binlog_cache_size to reduce spills'); |
| 106 | +}; |
| 107 | + |
| 108 | +# Task 7: Semi-sync wait point check |
| 109 | +subtest 'Semi-sync wait point check' => sub { |
| 110 | + @main::generalrec = (); |
| 111 | + MySQLTuner::TestHelper::reset_state(); |
| 112 | + $main::is_local_only = 0; |
| 113 | + $main::myvar{'rpl_semi_sync_master_enabled'} = 'ON'; |
| 114 | + $main::myvar{'rpl_semi_sync_master_wait_point'} = 'AFTER_COMMIT'; |
| 115 | + |
| 116 | + main::check_replication_advanced(); |
| 117 | + |
| 118 | + ok(grep(/Set rpl_semi_sync_source_wait_point = AFTER_SYNC/, @main::generalrec), 'Recommends setting AFTER_SYNC wait point'); |
| 119 | +}; |
| 120 | + |
| 121 | +done_testing(); |
0 commit comments