From f30c50be446bb9232a738edb07e14f9d70de6711 Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Wed, 11 Jul 2012 15:10:33 -0300 Subject: [PATCH] Updated the fles in /lib to use the new VersionParser --- lib/MasterSlave.pm | 3 +-- lib/TableChecksum.pm | 9 +++++---- lib/TableParser.pm | 5 ++--- lib/TableSyncer.pm | 8 +++----- lib/VariableAdvisorRules.pm | 28 ++++++---------------------- 5 files changed, 17 insertions(+), 36 deletions(-) diff --git a/lib/MasterSlave.pm b/lib/MasterSlave.pm index 91e61769..ef74a01a 100644 --- a/lib/MasterSlave.pm +++ b/lib/MasterSlave.pm @@ -279,8 +279,7 @@ sub get_connected_slaves { # user with USER(), quote it, and then add it to statement. my $show = "SHOW GRANTS FOR "; my $user = 'CURRENT_USER()'; - my $vp = $self->{VersionParser}; - if ( $vp && !$vp->version_ge($dbh, '4.1.2') ) { + if ( VersionParser->new($dbh) < '4.1.2' ) { $user = $dbh->selectrow_arrayref('SELECT USER()')->[0]; $user =~ s/([^@]+)@(.+)/'$1'\@'$2'/; } diff --git a/lib/TableChecksum.pm b/lib/TableChecksum.pm index f8a35ae9..714e7de0 100644 --- a/lib/TableChecksum.pm +++ b/lib/TableChecksum.pm @@ -39,7 +39,7 @@ our %ALGOS = ( sub new { my ( $class, %args ) = @_; - foreach my $arg ( qw(Quoter VersionParser) ) { + foreach my $arg ( qw(Quoter) ) { die "I need a $arg argument" unless defined $args{$arg}; } my $self = { %args }; @@ -107,23 +107,24 @@ sub get_crc_type { sub best_algorithm { my ( $self, %args ) = @_; my ( $alg, $dbh ) = @args{ qw(algorithm dbh) }; - my $vp = $self->{VersionParser}; my @choices = sort { $ALGOS{$a}->{pref} <=> $ALGOS{$b}->{pref} } keys %ALGOS; die "Invalid checksum algorithm $alg" if $alg && !$ALGOS{$alg}; + my $version = VersionParser->new($dbh); + # CHECKSUM is eliminated by lots of things... if ( $args{where} || $args{chunk} # CHECKSUM does whole table || $args{replicate} # CHECKSUM can't do INSERT.. SELECT - || !$vp->version_ge($dbh, '4.1.1')) # CHECKSUM doesn't exist + || $version < '4.1.1') # CHECKSUM doesn't exist { PTDEBUG && _d('Cannot use CHECKSUM algorithm'); @choices = grep { $_ ne 'CHECKSUM' } @choices; } # BIT_XOR isn't available till 4.1.1 either - if ( !$vp->version_ge($dbh, '4.1.1') ) { + if ( $version < '4.1.1' ) { PTDEBUG && _d('Cannot use BIT_XOR algorithm because MySQL < 4.1.1'); @choices = grep { $_ ne 'BIT_XOR' } @choices; } diff --git a/lib/TableParser.pm b/lib/TableParser.pm index f9cbbfc1..1e711d48 100644 --- a/lib/TableParser.pm +++ b/lib/TableParser.pm @@ -27,8 +27,7 @@ # # And some subs have an optional $opts param which is a hashref of options. # $opts->{mysql_version} is typically used, which is the return value from -# VersionParser::parser() (which returns a zero-padded MySQL version, -# e.g. 004001000 for 4.1.0). +# VersionParser->new() package TableParser; use strict; @@ -421,7 +420,7 @@ sub get_keys { my ( $type, $cols ) = $key =~ m/(?:USING (\w+))? \((.+)\)/; my ( $special ) = $key =~ m/(FULLTEXT|SPATIAL)/; $type = $type || $special || 'BTREE'; - if ( $opts->{mysql_version} && $opts->{mysql_version} lt '004001000' + if ( $opts->{mysql_version} && $opts->{mysql_version} lt '4.1' && $engine =~ m/HEAP|MEMORY/i ) { $type = 'HASH'; # MySQL pre-4.1 supports only HASH indexes on HEAP diff --git a/lib/TableSyncer.pm b/lib/TableSyncer.pm index b02a8854..24f48083 100644 --- a/lib/TableSyncer.pm +++ b/lib/TableSyncer.pm @@ -35,13 +35,12 @@ $Data::Dumper::Quotekeys = 0; # Arguments: # * MasterSlave A MasterSlave module # * Quoter A Quoter module -# * VersionParser A VersionParser module # * TableChecksum A TableChecksum module # * Retry A Retry module # * DSNParser (optional) sub new { my ( $class, %args ) = @_; - my @required_args = qw(MasterSlave Quoter VersionParser TableChecksum Retry); + my @required_args = qw(MasterSlave Quoter TableChecksum Retry); foreach my $arg ( @required_args ) { die "I need a $arg argument" unless defined $args{$arg}; } @@ -127,7 +126,6 @@ sub sync_table { $args{timeout_ok} ||= 0; my $q = $self->{Quoter}; - my $vp = $self->{VersionParser}; # ######################################################################## # Get and prepare the first plugin that can sync this table. @@ -145,8 +143,8 @@ sub sync_table { # Make an index hint for either the explicitly given chunk_index # or the chunk_index chosen by the plugin if index_hint is true. my $index_hint; - my $hint = ($vp->version_ge($src->{dbh}, '4.0.9') - && $vp->version_ge($dst->{dbh}, '4.0.9') ? 'FORCE' : 'USE') + my $hint = ((VersionParser->new($src->{dbh}) >= '4.0.9' + && VersionParser->new($dst->{dbh}) >= '4.0.9') ? 'FORCE' : 'USE') . ' INDEX'; if ( $args{chunk_index} ) { PTDEBUG && _d('Using given chunk index for index hint'); diff --git a/lib/VariableAdvisorRules.pm b/lib/VariableAdvisorRules.pm index 86ac033a..3905355e 100644 --- a/lib/VariableAdvisorRules.pm +++ b/lib/VariableAdvisorRules.pm @@ -539,27 +539,11 @@ sub get_rules { my ( %args ) = @_; my $mysql_version = $args{mysql_version}; return 0 unless $mysql_version; - my ($major, $minor, $patch) = $mysql_version =~ m/(\d{3})/g; - if ( $major eq '003' ) { - return $mysql_version lt '003023000' ? 1 : 0; # 3.23.x - } - elsif ( $major eq '004' ) { - return $mysql_version lt '004001020' ? 1 : 0; # 4.1.20 - } - elsif ( $major eq '005' ) { - if ( $minor eq '000' ) { - return $mysql_version lt '005000037' ? 1 : 0; # 5.0.37 - } - elsif ( $minor eq '001' ) { - return $mysql_version lt '005001030' ? 1 : 0; # 5.1.30 - } - else { - return 0; - } - } - else { - return 0; - } + return 1 if ($mysql_version eq '3' && $mysql_version lt '3.23') + || ($mysql_version eq '4' && $mysql_version lt '4.1.20') + || ($mysql_version eq '5.0' && $mysql_version lt '5.0.37') + || ($mysql_version eq '5.1' && $mysql_version lt '5.1.30'); + return 0; }, }, { @@ -568,7 +552,7 @@ sub get_rules { my ( %args ) = @_; my $mysql_version = $args{mysql_version}; return 0 unless $mysql_version; - return $mysql_version lt '005001000' ? 1 : 0; # 5.1.x + return $mysql_version lt '5.1' ? 1 : 0; # 5.1.x }, }, };