3
# Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
4
# Use is subject to license terms.
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; version 2 of the License.
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
# General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
20
#################### FOR THE MOMENT THIS SCRIPT IS FOR TESTING PURPOSES
22
use lib 'lib','lib/DBServer';
23
use lib "$ENV{RQG_HOME}/lib";
26
use DBServer::DBServer;
27
use DBServer::MySQL::MySQLd;
28
use DBServer::MySQL::ReplMySQLd;
32
$SIG{CHLD} = "IGNORE";
35
if (defined $ENV{RQG_HOME}) {
37
$ENV{RQG_HOME} = $ENV{RQG_HOME}.'\\';
39
$ENV{RQG_HOME} = $ENV{RQG_HOME}.'/';
44
use GenTest::Constants;
48
my $database = 'test';
51
my ($gendata, @basedirs, @mysqld_options, @vardirs, $rpl_mode,
52
$engine, $help, $debug,
53
$valgrind, @valgrind_options,
54
$start_dirty, $build_thread);
56
my @ARGV_saved = @ARGV;
58
my $opt_result = GetOptions(
59
'mysqld=s@' => \$mysqld_options[0],
60
'mysqld1=s@' => \$mysqld_options[0],
61
'mysqld2=s@' => \$mysqld_options[1],
62
'basedir=s' => \$basedirs[0],
63
'basedir1=s' => \$basedirs[0],
64
'basedir2=s' => \$basedirs[1],
65
#'basedir=s@' => \@basedirs,
66
'vardir=s' => \$vardirs[0],
67
'vardir1=s' => \$vardirs[0],
68
'vardir2=s' => \$vardirs[1],
69
#'vardir=s@' => \@vardirs,
70
'rpl_mode=s' => \$rpl_mode,
71
'engine=s' => \$engine,
74
'valgrind!' => \$valgrind,
75
'valgrind_options=s@' => \@valgrind_options,
76
'start-dirty' => \$start_dirty,
77
'mtr-build-thread=i' => \$build_thread
80
if (!$opt_result || $help || $basedirs[0] eq '') {
85
say("Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.");
86
say("Please see http://forge.mysql.com/wiki/Category:RandomQueryGenerator for more information on this test framework.");
87
say("Starting \n# $0 \\ \n# ".join(" \\ \n# ", @ARGV_saved));
91
# Calculate master and slave ports based on MTR_BUILD_THREAD (MTR
92
# Version 1 behaviour)
95
if (not defined $build_thread) {
96
if (defined $ENV{MTR_BUILD_THREAD}) {
97
$build_thread = $ENV{MTR_BUILD_THREAD}
99
$build_thread = DEFAULT_MTR_BUILD_THREAD;
103
if ( $build_thread eq 'auto' ) {
104
say ("Please set the environment variable MTR_BUILD_THREAD to a value <> 'auto' (recommended) or unset it (will take the value ".DEFAULT_MTR_BUILD_THREAD.") ");
105
exit (STATUS_ENVIRONMENT_FAILURE);
108
my @ports = (10000 + 10 * $build_thread, 10000 + 10 * $build_thread + 2);
110
say("master_port : $ports[0] slave_port : $ports[1] ports : @ports MTR_BUILD_THREAD : $build_thread ");
113
# If the user has provided two vardirs and one basedir, start second
114
# server using the same basedir
118
($vardirs[1] ne '') &&
121
$basedirs[1] = $basedirs[0];
126
($mysqld_options[1] ne '') &&
129
$basedirs[1] = $basedirs[0];
133
# If the user has provided identical basedirs and vardirs, warn of a
138
($basedirs[0] eq $basedirs[1]) &&
139
($vardirs[0] eq $vardirs[1]) &&
142
croak("Please specify either different --basedir[12] or different --vardir[12] in order to start two MySQL servers");
147
foreach my $path ("$basedirs[0]/client/RelWithDebInfo", "$basedirs[0]/client/Debug", "$basedirs[0]/client", "$basedirs[0]/bin") {
149
$client_basedir = $path;
155
# Start servers. Use rpl_alter if replication is needed.
161
if ($rpl_mode ne '') {
163
push @options, lc("--$engine") if defined $engine && lc($engine) ne lc('myisam');
165
push @options, "--sql-mode=no_engine_substitution" if join(' ', @ARGV_saved) !~ m{sql-mode}io;
167
if (defined $mysqld_options[0]) {
168
push @options, @{$mysqld_options[0]};
171
$rplsrv = DBServer::MySQL::ReplMySQLd->new(basedir => $basedirs[0],
172
master_vardir => $vardirs[0],
173
master_port => $ports[0],
174
slave_vardir => $vardirs[1],
175
slave_port => $ports[1],
177
server_options => \@options,
178
valgrind => $valgrind,
179
valgrind_options => \@valgrind_options,
180
start_dirty => $start_dirty);
182
my $status = $rplsrv->startServer();
184
if ($status > STATUS_OK) {
186
say(system("ls -l ".$rplsrv->master->datadir));
187
say(system("ls -l ".$rplsrv->slave->datadir));
188
croak("Could not start replicating server pair");
191
$dsns[0] = $rplsrv->master->dsn($database);
192
$dsns[1] = undef; ## passed to gentest. No dsn for slave!
193
$server[0] = $rplsrv->master;
194
$server[1] = $rplsrv->slave;
197
if ($#basedirs != $#vardirs) {
198
croak ("The number of basedirs and vardirs must match $#basedirs != $#vardirs")
200
foreach my $server_id (0..1) {
201
next if $basedirs[$server_id] eq '';
204
push @options, lc("--$engine") if defined $engine && lc($engine) ne lc('myisam');
206
push @options, "--sql-mode=no_engine_substitution" if join(' ', @ARGV_saved) !~ m{sql-mode}io;
208
if (defined $mysqld_options[$server_id]) {
209
push @options, @{$mysqld_options[$server_id]};
212
$server[$server_id] = DBServer::MySQL::MySQLd->new(basedir => $basedirs[$server_id],
213
vardir => $vardirs[$server_id],
214
port => $ports[$server_id],
215
start_dirty => $start_dirty,
216
valgrind => $valgrind,
217
valgrind_options => \@valgrind_options,
218
server_options => \@options);
220
my $status = $server[$server_id]->startServer;
222
if ($status > STATUS_OK) {
224
say(system("ls -l ".$server[$server_id]->datadir));
225
croak("Could not start all servers");
232
$dsns[$server_id] = $server[$server_id]->dsn($database);
235
if ((defined $dsns[$server_id]) && (defined $engine)) {
236
my $dbh = DBI->connect($dsns[$server_id], undef, undef, { RaiseError => 1 } );
237
$dbh->do("SET GLOBAL storage_engine = '$engine'");
242
say("\n\nHit return to stop server(s)");
244
my $something = <STDIN>;
249
if ($rpl_mode ne '') {
250
$rplsrv->stopServer();
252
foreach my $srv (@server) {
264
Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.
266
$0 - Run a complete random query generation test, including server start with replication and master/slave verification
268
Options related to one standalone MySQL server:
270
--basedir : Specifies the base directory of the stand-alone MySQL installation;
271
--mysqld : Options passed to the MySQL server
272
--vardir : Optional. (default \$basedir/mysql-test/var);
274
Options related to two MySQL servers
276
--basedir1 : Specifies the base directory of the first MySQL installation;
277
--basedir2 : Specifies the base directory of the second MySQL installation;
278
--mysqld1 : Options passed to the first MySQL server
279
--mysqld2 : Options passed to the second MySQL server
280
--vardir1 : Optional. (default \$basedir1/mysql-test/var);
281
--vardir2 : Optional. (default \$basedir2/mysql-test/var);
285
--grammar : Grammar file to use when generating queries (REQUIRED);
286
--redefine : Grammar file to redefine and/or add rules to the given grammar
287
--rpl_mode : Replication type to use (statement|row|mixed) (default: no replication);
288
--vardir1 : Optional.
289
--vardir2 : Optional.
290
--engine : Table engine to use when creating tables with gendata (default no ENGINE in CREATE TABLE);
291
--valgrind : Passed to gentest.pl
293
Value used for MTR_BUILD_THREAD when servers are started and accessed.
295
--help : This help message
297
If you specify --basedir1 and --basedir2 or --vardir1 and --vardir2, two servers will be started and the results from the queries
298
will be compared between them.
301
print "$0 arguments were: ".join(' ', @ARGV_saved)."\n";
302
exit_test(STATUS_UNKNOWN_ERROR);
308
say("[$$] $0 will exit with exit status $status");