Skip to content
This repository has been archived by the owner on Apr 9, 2021. It is now read-only.

Commit

Permalink
Added --gtid option and mysqlsh temporary support
Browse files Browse the repository at this point in the history
- Added explicit return code to test_replication script
- Enables sbtool to remove incomplete group sandboxes
- Test_Helper now cleans environment variables before starting a test
- Added temporary support for mysqlsh
- merge contribution by kaiwangchen to fix make_sandbox_from source and make_sandbox with mysqld-debug
- Added --gtid option dor make_sandbox, make_replication_sandbox, and make_multiple_sandbox
  • Loading branch information
datacharmer committed May 9, 2016
1 parent afc175b commit 371f8fe
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 17 deletions.
7 changes: 6 additions & 1 deletion Changelog
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
3.1.06 12-Apr-2016
3.1.06 09-May-2016
- Added explicit return code to test_replication script
- Enables sbtool to remove incomplete group sandboxes
- Test_Helper now cleans environment variables before starting a test
- Added temporary support for mysqlsh
- merge contribution by kaiwangchen to fix make_sandbox_from source and
make_sandbox with mysqld-debug
- Added --gtid option dor make_sandbox, make_replication_sandbox, and
make_multiple_sandbox
3.1.05 17-Jan-2016
- Fixed mismatch in version checking to determnine whether to use
mysql_install_db or mysqld --initialize
Expand Down
52 changes: 51 additions & 1 deletion bin/low_level_make_sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,56 @@ if ($msb->{options}{'slaveof'} or $msb->{options}{'master'})
unshift @{ $msb->{options}{'my_clause'}}, $clause;
}
}

my $detected_mysql_version = qx($msb->{options}{basedir}/bin/mysql_config --version);
if ($detected_mysql_version)
{
$msb->{options}{detected_mysql_version} = $detected_mysql_version;
}
else
{
die "# Can't get MySQL version from mysql_config\n";
}

if ($msb->{options}{'gtid'})
{
my $mysql_version = $msb->{options}{detected_mysql_version};

my ($major, $minor, $rev) = split_version($mysql_version);

$mysql_version=sprintf('%d.%d.%d', $major,$minor, $rev);

if ((greater_version($mysql_version, '5.6.9') ) && ($major < 10)) # exclude MariaDB from this feature
{

my @clauses = ( "master-info-repository=table ",
"relay-log-info-repository=table",
"gtid_mode=ON",
"enforce-gtid-consistency");

unless ( grep {/log.bin/} @{ $msb->{options}{'my_clause'} })
{
push @clauses, 'log-bin' ;
}
unless ( grep {/server.id/} @{ $msb->{options}{'my_clause'} })
{
push @clauses, 'server-id=' . $msb->{options}{sandbox_port} ;
}
unless (greater_version($mysql_version, '5.7.9'))
{
push @clauses , "log-slave-updates";
}
for my $clause (@clauses)
{
unshift @{ $msb->{options}{'my_clause'}}, $clause;
}
}
else
{
print "# enabling GTID is supported for MySQL 5.6.10 + - Skipping \n"
}
}

# my $mysql_version = qx($msb->{options}{basedir}/bin/mysql_config --version);

if ($msb->{options}{'interactive'}) {
Expand Down Expand Up @@ -626,7 +676,7 @@ for my $file_spec ( @file_list) { #, @doc_file_list) {
if ($msb->{options}{datadir_from} eq 'script' ) {
my $additional_options = "";
my $script = sprintf '%s/scripts/mysql_install_db', $msb->{options}{basedir} ;
my $mysql_version = qx($msb->{options}{basedir}/bin/mysql_config --version);
my $mysql_version = $msb->{options}{detected_mysql_version} ;
if ($mysql_version)
{
chomp $mysql_version;
Expand Down
4 changes: 4 additions & 0 deletions bin/make_multiple_sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ $msb->write_to($circular_replication_script, '>>', "$group_directory/use_all 'st

for my $node (1 .. $msb->{options}{how_many_nodes}) {
my $additional_node_options = $ENV{NODE_OPTIONS} || '';
if ($msb->{options}{gtid})
{
$additional_node_options .= ' --gtid ';
}
my $this_node_options = $ENV{"NODE${node}_OPTIONS"} || '';
my $node_port = $replication_port+ $node;
if ($msb->{options}{'circular'}) {
Expand Down
5 changes: 5 additions & 0 deletions bin/make_replication_sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ if ($ENV{NODE_OPTIONS}) {
}
$additional_master_options .= q{ };
$additional_slave_options .= q{ };
if ( $msb->{options}{gtid}) {
$additional_master_options .= ' --gtid ';
$additional_slave_options .= ' --gtid ';
}

my $install_master='';
my $install_master_command = qq(
make_sandbox $msb->{options}{server_version} -- \\
Expand Down
2 changes: 2 additions & 0 deletions bin/test_sandbox
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ sub ok_sql {
$params->{'path'},
$params->{'query'},
$verbose);
$ENV{SQL_RESULT} = $result;
if ($wanted_result && ref($wanted_result) eq 'SCALAR') {
$$wanted_result = $result;
}
Expand Down Expand Up @@ -712,6 +713,7 @@ sub ok_exec {
if ($verbose) {
print $result, "\n";
}
$ENV{EXEC_RESULT} = $result;
if (! ref $params->{'expected'} ) {
if ($return_code_wanted) {
return ok($CHILD_ERROR == 0 , $params->{'msg'});
Expand Down
2 changes: 1 addition & 1 deletion lib/MySQL/Sandbox.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ our @EXPORT_OK= qw( is_port_open
split_version
) ;

our $VERSION="3.1.05";
our $VERSION=q{3.1.06};
our $DEBUG;

BEGIN {
Expand Down
2 changes: 1 addition & 1 deletion lib/MySQL/Sandbox/Recipes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package MySQL::Sandbox::Recipes;
use strict;
use warnings;

our $VERSION="3.1.05";
our $VERSION=q{3.1.06};

1;
__END__
Expand Down
59 changes: 58 additions & 1 deletion lib/MySQL/Sandbox/Scripts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ our @EXPORT_OK = qw(
);
our @EXPORT = @EXPORT_OK;

our $VERSION="3.1.05";
our $VERSION=q{3.1.06};

our @MANIFEST = (
'clear.sh',
Expand All @@ -31,6 +31,7 @@ our @MANIFEST = (
'load_grants.sh',
'use.sh',
'mycli.sh',
'mysqlsh.sh',
'proxy_start.sh',
'my.sh',
'change_paths.sh',
Expand Down Expand Up @@ -308,6 +309,15 @@ my %parse_options_low_level_make_sandbox = (
'configures the server for high performance'
]
},
gtid => {
value => 0,
parse => 'gtid',
so => 127,
export => 1,
help => [
'enables GTID for MySQL 5.6.10+'
]
},
prompt_prefix => {
value => 'mysql',
parse => 'prompt_prefix=s',
Expand Down Expand Up @@ -596,6 +606,16 @@ my %parse_options_replication = (
'(Default: "" )'
]
},
gtid => {
value => 0,
parse => 'gtid' ,
so => 140,
help => [
'Enables GTID for MYSQL 5.6.10+',
'(Default: NO )'
]
},


interactive => {
value => 0,
Expand Down Expand Up @@ -744,6 +764,16 @@ my %parse_options_many = (
'(Default: "" )'
]
},
gtid => {
value => 0,
parse => 'gtid' ,
so => 150,
help => [
'Enables GTID for MYSQL 5.6.10+',
'(Default: NO )'
]
},


interactive => {
value => 0,
Expand Down Expand Up @@ -1300,6 +1330,16 @@ export DYLD_LIBRARY_PATH=_BASEDIR_/lib:_BASEDIR_/lib/mysql:$DYLD_LIBRARY_PATH
SBDIR="_HOME_DIR_/_SANDBOXDIR_"
BASEDIR=_BASEDIR_
[ -z "$MYSQL_EDITOR" ] && MYSQL_EDITOR="$BASEDIR/bin/mysql"
if [ ! -x $MYSQL_EDITOR ]
then
if [ -x $SBDIR/$MYSQL_EDITOR ]
then
MYSQL_EDITOR=$SBDIR/$MYSQL_EDITOR
else
echo "MYSQL_EDITOR '$MYSQL_EDITOR' not found or not executable"
exit 1
fi
fi
HISTDIR=_HISTORY_DIR_
[ -z "$HISTDIR" ] && HISTDIR=$SBDIR
export MYSQL_HISTFILE="$HISTDIR/.mysql_history"
Expand Down Expand Up @@ -1329,6 +1369,23 @@ mycli --user=_DBUSER_ \
MYCLI_SCRIPT


'mysqlsh.sh' => <<'MYSQLSH_SCRIPT',
#!_BINBASH_
__LICENSE__
export LD_LIBRARY_PATH=_BASEDIR_/lib:_BASEDIR_/lib/mysql:$LD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=_BASEDIR_/lib:_BASEDIR_/lib/mysql:$DYLD_LIBRARY_PATH
SBDIR="_HOME_DIR_/_SANDBOXDIR_"
BASEDIR=_BASEDIR_
mysqlsh \
--sqlc \
--user=_DBUSER_ \
--password=_DBPASSWORD_ \
--port=_SERVERPORT_ \
--socket=_GLOBALTMPDIR_/mysql_sandbox_SERVERPORT_.sock "$@"
MYSQLSH_SCRIPT


'clear.sh' => <<'CLEAR_SCRIPT',
#!_BINBASH_
__LICENSE__
Expand Down
2 changes: 1 addition & 1 deletion mkdist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ TOOLS="$TOOLS make_sandbox_from_source msandbox msb sbtool test_sandbox"
LIBS="lib/MySQL/Sandbox.pm lib/MySQL/Sandbox/Scripts.pm lib/MySQL/Sandbox/Recipes.pm"

CHANGE_COPYRIGHT_YEAR='BEGIN{$y=shift;};s/(2006-)\d+(\s+)(Giuseppe\s+Maxia)/$1$y$2$3/'
CHANGE_VERSION='BEGIN{$V=shift;};s/^(our\s+$VERSION=)([^;]+)/${1}q{$V}/'
CHANGE_VERSION='BEGIN{$V=shift;};s/^(our\s+\$VERSION=)([^;]+)/${1}q{$V}/'
#set -x
for TOOL in $TOOLS
do
Expand Down
2 changes: 1 addition & 1 deletion t/19_replication_gtid.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ use Test_Helper;
use MySQL::Sandbox;

confirm_version('5.6.6','5.7.99');

$ENV{'GTID_FROM_FILE'}=1;
test_sandbox( 'test_sandbox --user_test=./t/replication_gtid.sb.pl', 16);
9 changes: 9 additions & 0 deletions t/21_replication_gtid_option.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use strict;
use warnings;
use lib './t';
use Test_Helper;
use MySQL::Sandbox;

confirm_version('5.6.6','5.7.99');
$ENV{'GTID_FROM_FILE'}=undef;
test_sandbox( 'test_sandbox --user_test=./t/replication_gtid.sb.pl', 13);
2 changes: 1 addition & 1 deletion t/Test_Helper.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ BEGIN {
$ENV{TEST_SANDBOX_HOME}="$ENV{PWD}/t/test_sb";
$ENV{PERL5LIB}="$ENV{PWD}/lib";
$ENV{PATH}="$ENV{PWD}/bin:$ENV{PATH}";
$ENV{TEST_VERSION} = $ENV{TEST_VERSION} || '5.6.26';
$ENV{TEST_VERSION} = $ENV{TEST_VERSION} || '5.6.29';
$ENV{SANDBOX_AS_ROOT} = 1;
for my $env_var (qw(NODE_OPTIONS MASTER_OPTIONS SLAVE_OPTIONS))
{
Expand Down
27 changes: 20 additions & 7 deletions t/replication_gtid.sb.pl
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@
my ($version, $name_version) = get_bare_version($TEST_VERSION);
my $replication_dir = "rsandbox_$name_version";

my $GTID_OPTION= ' --gtid';
if ( $ENV{'GTID_FROM_FILE'})
{
$GTID_OPTION='';
}

ok_exec({
command => "make_replication_sandbox $TEST_VERSION ",
command => "make_replication_sandbox $GTID_OPTION $TEST_VERSION",
expected => 'replication directory installed',
msg => 'replication directory installed',
});

ok( (-f "$sandbox_home/$replication_dir/enable_gtid" ), "file enable_gtid found ");
if ( $ENV{'GTID_FROM_FILE'})
{
ok( (-f "$sandbox_home/$replication_dir/enable_gtid" ), "file enable_gtid found ");

my $result = qx( $sandbox_home/$replication_dir/enable_gtid );
my $result = qx( $sandbox_home/$replication_dir/enable_gtid );

ok( $? == 0 , 'enable_gtid ran without errors');
ok( $? == 0 , 'enable_gtid ran without errors');

ok( $result && ($result =~ /# option 'gtid_mode=ON' added to \w+ configuration file/), "enable_gtid added options successfully");
ok( $result && ($result =~ /# option 'gtid_mode=ON' added to \w+ configuration file/), "enable_gtid added options successfully");
}

ok_sql({
path => "$sandbox_home/$replication_dir/master",
Expand Down Expand Up @@ -88,14 +97,18 @@
ok_sql({
path => "$sandbox_home/$replication_dir/master",
query => 'select @@global.gtid_executed',
expected => '1111-111111111111:1-2',
expected => '1111-111111111111:1-',
msg => 'Master has produced a GTID',
});

#my $executed_set = `$sandbox_home/$replication_dir/m -BN -e 'select \@\@global.gtid_executed'`;
#chomp $executed_set;
my $executed_set = $ENV{SQL_RESULT};

ok_sql({
path => "$sandbox_home/$replication_dir/node1",
query => 'select @@global.gtid_executed',
expected => '1111-111111111111:1-2',
expected => $executed_set,
msg => 'Slave has retrieved a GTID',
});

Expand Down
4 changes: 2 additions & 2 deletions test_versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
5.7.5
5.7.7
5.7.8
5.7.9
5.7.10
ma10.0.20
ma10.1.6
ma10.1.8
ma5.5.40
ps5.5.43
ps5.6.25

0 comments on commit 371f8fe

Please sign in to comment.