Updated the fles in /lib to use the new VersionParser

This commit is contained in:
Brian Fraser
2012-07-11 15:10:33 -03:00
parent acd5281e3c
commit f30c50be44
5 changed files with 17 additions and 36 deletions

View File

@@ -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'/;
}

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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');

View File

@@ -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
},
},
};