Skip to content

Commit ae3bbd9

Browse files
authored
Merge pull request #7 from jmrenouard/fix-wsrep-slave-threads-deprecation #819
Fix wsrep_slave_threads deprecation #819
2 parents 2dc796f + 86d5e61 commit ae3bbd9

File tree

1 file changed

+87
-52
lines changed

1 file changed

+87
-52
lines changed

mysqltuner.pl

Lines changed: 87 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,9 @@ sub hr_bytes_practical_rnd {
446446
my $num = shift;
447447
return "0B" unless defined($num) and $num > 0;
448448

449-
my $gbs = $num / (1024**3); # convert to GB
449+
my $gbs = $num / ( 1024**3 ); # convert to GB
450450
my $power_of_2_gb = 1;
451-
while ($power_of_2_gb < $gbs) {
451+
while ( $power_of_2_gb < $gbs ) {
452452
$power_of_2_gb *= 2;
453453
}
454454

@@ -5996,9 +5996,7 @@ sub trim {
59965996
sub get_wsrep_options {
59975997
return () unless defined $myvar{'wsrep_provider_options'};
59985998

5999-
my @galera_options = split /;/, $myvar{'wsrep_provider_options'};
6000-
my $wsrep_slave_threads = $myvar{'wsrep_slave_threads'};
6001-
push @galera_options, ' wsrep_slave_threads = ' . $wsrep_slave_threads;
5999+
my @galera_options = split /;/, $myvar{'wsrep_provider_options'};
60026000
@galera_options = remove_cr @galera_options;
60036001
@galera_options = remove_empty @galera_options;
60046002

@@ -6176,25 +6174,31 @@ sub mariadb_galera {
61766174
. hr_bytes_rnd( get_wsrep_option('gcache.mem_size') );
61776175

61786176
infoprint "CPU cores detected : " . (cpu_cores);
6179-
infoprint "wsrep_slave_threads: " . get_wsrep_option('wsrep_slave_threads');
6177+
my $wsrep_threads_var_name = 'wsrep_slave_threads';
6178+
if ( defined( $myvar{'wsrep_applier_threads'} ) ) {
6179+
$wsrep_threads_var_name = 'wsrep_applier_threads';
6180+
}
6181+
my $wsrep_threads_value = $myvar{$wsrep_threads_var_name} || 1;
6182+
6183+
infoprint "$wsrep_threads_var_name: " . $wsrep_threads_value;
61806184

6181-
if ( get_wsrep_option('wsrep_slave_threads') > ( (cpu_cores) * 4 )
6182-
or get_wsrep_option('wsrep_slave_threads') < ( (cpu_cores) * 2 ) )
6185+
if ( $wsrep_threads_value > ( (cpu_cores) * 4 )
6186+
or $wsrep_threads_value < ( (cpu_cores) * 2 ) )
61836187
{
61846188
badprint
6185-
"wsrep_slave_threads is not equal to 2, 3 or 4 times the number of CPU(s)";
6186-
push @adjvars, "wsrep_slave_threads = " . ( (cpu_cores) * 4 );
6189+
"$wsrep_threads_var_name is not equal to 2, 3 or 4 times the number of CPU(s)";
6190+
push @adjvars, "$wsrep_threads_var_name = " . ( (cpu_cores) * 4 );
61876191
}
61886192
else {
61896193
goodprint
6190-
"wsrep_slave_threads is equal to 2, 3 or 4 times the number of CPU(s)";
6194+
"$wsrep_threads_var_name is equal to 2, 3 or 4 times the number of CPU(s)";
61916195
}
61926196

6193-
if ( get_wsrep_option('wsrep_slave_threads') > 1 ) {
6197+
if ( $wsrep_threads_value > 1 ) {
61946198
infoprint
61956199
"wsrep parallel slave can cause frequent inconsistency crash.";
61966200
push @adjvars,
6197-
"Set wsrep_slave_threads to 1 in case of HA_ERR_FOUND_DUPP_KEY crash on slave";
6201+
"Set $wsrep_threads_var_name to 1 in case of HA_ERR_FOUND_DUPP_KEY crash on slave";
61986202

61996203
# check options for parallel slave
62006204
if ( get_wsrep_option('wsrep_slave_FK_checks') eq "OFF" ) {
@@ -6212,15 +6216,15 @@ sub mariadb_galera {
62126216
}
62136217
}
62146218

6215-
if ( get_wsrep_option('gcs.fc_limit') != $myvar{'wsrep_slave_threads'} * 5 )
6216-
{
6217-
badprint "gcs.fc_limit should be equal to 5 * wsrep_slave_threads (="
6218-
. ( $myvar{'wsrep_slave_threads'} * 5 ) . ")";
6219-
push @adjvars, "gcs.fc_limit= wsrep_slave_threads * 5 (="
6220-
. ( $myvar{'wsrep_slave_threads'} * 5 ) . ")";
6219+
if ( get_wsrep_option('gcs.fc_limit') != $wsrep_threads_value * 5 ) {
6220+
badprint
6221+
"gcs.fc_limit should be equal to 5 * $wsrep_threads_var_name (="
6222+
. ( $wsrep_threads_value * 5 ) . ")";
6223+
push @adjvars, "gcs.fc_limit= $wsrep_threads_var_name * 5 (="
6224+
. ( $wsrep_threads_value * 5 ) . ")";
62216225
}
62226226
else {
6223-
goodprint "gcs.fc_limit is equal to 5 * wsrep_slave_threads ( ="
6227+
goodprint "gcs.fc_limit is equal to 5 * $wsrep_threads_var_name ( ="
62246228
. get_wsrep_option('gcs.fc_limit') . ")";
62256229
}
62266230

@@ -6595,39 +6599,60 @@ sub mysql_innodb {
65956599
}
65966600
}
65976601
}
6598-
# InnoDB Log File Size / InnoDB Redo Log Capacity Recommendations
6599-
# For MySQL < 8.0.30, the recommendation is based on innodb_log_file_size and innodb_log_files_in_group.
6600-
# For MySQL >= 8.0.30, innodb_redo_log_capacity replaces the old system.
6601-
if ( mysql_version_ge( 8, 0, 30 ) && defined $myvar{'innodb_redo_log_capacity'} ) {
6602+
6603+
# InnoDB Log File Size / InnoDB Redo Log Capacity Recommendations
6604+
# For MySQL < 8.0.30, the recommendation is based on innodb_log_file_size and innodb_log_files_in_group.
6605+
# For MySQL >= 8.0.30, innodb_redo_log_capacity replaces the old system.
6606+
if ( mysql_version_ge( 8, 0, 30 )
6607+
&& defined $myvar{'innodb_redo_log_capacity'} )
6608+
{
66026609
# New recommendation logic for MySQL >= 8.0.30
6603-
infoprint "InnoDB Redo Log Capacity is set to " . hr_bytes($myvar{'innodb_redo_log_capacity'});
6610+
infoprint "InnoDB Redo Log Capacity is set to "
6611+
. hr_bytes( $myvar{'innodb_redo_log_capacity'} );
66046612

66056613
my $innodb_os_log_written = $mystat{'Innodb_os_log_written'} || 0;
6606-
my $uptime = $mystat{'Uptime'} || 1;
6614+
my $uptime = $mystat{'Uptime'} || 1;
66076615

6608-
if ($uptime > 3600) { # Only make a recommendation if server has been up for at least an hour
6616+
if ( $uptime > 3600 )
6617+
{ # Only make a recommendation if server has been up for at least an hour
66096618
my $hourly_rate = $innodb_os_log_written / ( $uptime / 3600 );
6610-
my $suggested_redo_log_capacity_str = hr_bytes_practical_rnd($hourly_rate);
6611-
my $suggested_redo_log_capacity_bytes = hr_raw($suggested_redo_log_capacity_str);
6619+
my $suggested_redo_log_capacity_str =
6620+
hr_bytes_practical_rnd($hourly_rate);
6621+
my $suggested_redo_log_capacity_bytes =
6622+
hr_raw($suggested_redo_log_capacity_str);
66126623

6613-
infoprint "Hourly InnoDB log write rate: " . hr_bytes_rnd($hourly_rate) . "/hour";
6624+
infoprint "Hourly InnoDB log write rate: "
6625+
. hr_bytes_rnd($hourly_rate) . "/hour";
66146626

6615-
if (hr_raw($myvar{'innodb_redo_log_capacity'}) < $hourly_rate) {
6616-
badprint "Your innodb_redo_log_capacity is not large enough to hold at least 1 hour of writes.";
6617-
push( @adjvars, "innodb_redo_log_capacity (>= " . $suggested_redo_log_capacity_str . ")" );
6618-
} else {
6619-
goodprint "Your innodb_redo_log_capacity is sized to handle more than 1 hour of writes.";
6627+
if ( hr_raw( $myvar{'innodb_redo_log_capacity'} ) < $hourly_rate ) {
6628+
badprint
6629+
"Your innodb_redo_log_capacity is not large enough to hold at least 1 hour of writes.";
6630+
push( @adjvars,
6631+
"innodb_redo_log_capacity (>= "
6632+
. $suggested_redo_log_capacity_str
6633+
. ")" );
6634+
}
6635+
else {
6636+
goodprint
6637+
"Your innodb_redo_log_capacity is sized to handle more than 1 hour of writes.";
66206638
}
66216639

66226640
# Sanity check against total InnoDB data size
6623-
if ( defined $enginestats{'InnoDB'} and $enginestats{'InnoDB'} > 0 ) {
6641+
if ( defined $enginestats{'InnoDB'} and $enginestats{'InnoDB'} > 0 )
6642+
{
66246643
my $total_innodb_size = $enginestats{'InnoDB'};
6625-
if ( $suggested_redo_log_capacity_bytes > $total_innodb_size * 0.25 ) {
6626-
infoprint "The suggested innodb_redo_log_capacity (" . $suggested_redo_log_capacity_str . ") is more than 25% of your total InnoDB data size. This might be unnecessarily large.";
6644+
if ( $suggested_redo_log_capacity_bytes >
6645+
$total_innodb_size * 0.25 )
6646+
{
6647+
infoprint "The suggested innodb_redo_log_capacity ("
6648+
. $suggested_redo_log_capacity_str
6649+
. ") is more than 25% of your total InnoDB data size. This might be unnecessarily large.";
66276650
}
66286651
}
6629-
} else {
6630-
infoprint "Server uptime is less than 1 hour. Cannot make a reliable recommendation for innodb_redo_log_capacity.";
6652+
}
6653+
else {
6654+
infoprint
6655+
"Server uptime is less than 1 hour. Cannot make a reliable recommendation for innodb_redo_log_capacity.";
66316656
}
66326657
}
66336658
else {
@@ -6648,11 +6673,12 @@ sub mysql_innodb {
66486673
. ") if possible, so InnoDB Redo log Capacity equals 25% of buffer pool size."
66496674
);
66506675
push( @generalrec,
6651-
"Be careful, increasing innodb_redo_log_capacity means higher crash recovery mean time"
6676+
"Be careful, increasing innodb_redo_log_capacity means higher crash recovery mean time"
66526677
);
66536678
}
66546679
else {
6655-
badprint "Ratio InnoDB log file size / InnoDB Buffer pool size ("
6680+
badprint
6681+
"Ratio InnoDB log file size / InnoDB Buffer pool size ("
66566682
. $mycalc{'innodb_log_size_pct'} . "%): "
66576683
. hr_bytes( $myvar{'innodb_log_file_size'} ) . " * "
66586684
. $myvar{'innodb_log_files_in_group'} . " / "
@@ -6678,12 +6704,12 @@ sub mysql_innodb {
66786704
. ") if possible, so InnoDB total log file size equals 25% of buffer pool size."
66796705
);
66806706
push( @generalrec,
6681-
"Be careful, increasing innodb_log_file_size / innodb_log_files_in_group means higher crash recovery mean time"
6707+
"Be careful, increasing innodb_log_file_size / innodb_log_files_in_group means higher crash recovery mean time"
66826708
);
66836709
}
66846710
if ( mysql_version_le( 5, 6, 2 ) ) {
66856711
push( @generalrec,
6686-
"For MySQL 5.6.2 and lower, total innodb_log_file_size should have a ceiling of (4096MB / log files in group) - 1MB."
6712+
"For MySQL 5.6.2 and lower, total innodb_log_file_size should have a ceiling of (4096MB / log files in group) - 1MB."
66876713
);
66886714
}
66896715
}
@@ -6697,9 +6723,10 @@ sub mysql_innodb {
66976723
}
66986724
else {
66996725
push( @generalrec,
6700-
"Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: https://bit.ly/2TcGgtU"
6726+
"Before changing innodb_log_file_size and/or innodb_log_files_in_group read this: https://bit.ly/2TcGgtU"
67016727
);
6702-
goodprint "Ratio InnoDB log file size / InnoDB Buffer pool size: "
6728+
goodprint
6729+
"Ratio InnoDB log file size / InnoDB Buffer pool size: "
67036730
. hr_bytes( $myvar{'innodb_log_file_size'} ) . " * "
67046731
. $myvar{'innodb_log_files_in_group'} . "/"
67056732
. hr_bytes( $myvar{'innodb_buffer_pool_size'} )
@@ -6762,10 +6789,14 @@ sub mysql_innodb {
67626789
}
67636790

67646791
# InnoDB Used Buffer Pool Size vs CHUNK size
6765-
if ( $myvar{'version'} =~ /MariaDB/i and mysql_version_ge(10, 8) and $myvar{'innodb_buffer_pool_chunk_size'} == 0) {
6766-
infoprint "innodb_buffer_pool_chunk_size is set to 'autosize' (0) in MariaDB >= 10.8. Skipping chunk size checks.";
6792+
if ( $myvar{'version'} =~ /MariaDB/i
6793+
and mysql_version_ge( 10, 8 )
6794+
and $myvar{'innodb_buffer_pool_chunk_size'} == 0 )
6795+
{
6796+
infoprint
6797+
"innodb_buffer_pool_chunk_size is set to 'autosize' (0) in MariaDB >= 10.8. Skipping chunk size checks.";
67676798
}
6768-
elsif ( !defined( $myvar{'innodb_buffer_pool_chunk_size'} )
6799+
elsif (!defined( $myvar{'innodb_buffer_pool_chunk_size'} )
67696800
|| $myvar{'innodb_buffer_pool_chunk_size'} == 0
67706801
|| !defined( $myvar{'innodb_buffer_pool_size'} )
67716802
|| $myvar{'innodb_buffer_pool_size'} == 0
@@ -6821,8 +6852,11 @@ sub mysql_innodb {
68216852
}
68226853

68236854
# InnoDB Read efficiency
6824-
if ( $mystat{'Innodb_buffer_pool_reads'} > $mystat{'Innodb_buffer_pool_read_requests'} ) {
6825-
infoprint "InnoDB Read buffer efficiency: metrics are not reliable (reads > read requests)";
6855+
if ( $mystat{'Innodb_buffer_pool_reads'} >
6856+
$mystat{'Innodb_buffer_pool_read_requests'} )
6857+
{
6858+
infoprint
6859+
"InnoDB Read buffer efficiency: metrics are not reliable (reads > read requests)";
68266860
}
68276861
elsif ( defined $mycalc{'pct_read_efficiency'}
68286862
&& $mycalc{'pct_read_efficiency'} < 90 )
@@ -6847,7 +6881,8 @@ sub mysql_innodb {
68476881

68486882
# InnoDB Write efficiency
68496883
if ( $mystat{'Innodb_log_writes'} > $mystat{'Innodb_log_write_requests'} ) {
6850-
infoprint "InnoDB Write Log efficiency: metrics are not reliable (writes > write requests)";
6884+
infoprint
6885+
"InnoDB Write Log efficiency: metrics are not reliable (writes > write requests)";
68516886
}
68526887
elsif ( defined $mycalc{'pct_write_efficiency'}
68536888
&& $mycalc{'pct_write_efficiency'} < 90 )

0 commit comments

Comments
 (0)