~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/randgen/server.pl

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved.
 
4
# Use is subject to license terms.
 
5
#
 
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.
 
9
#
 
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.
 
14
#
 
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
 
18
# USA
 
19
 
 
20
#################### FOR THE MOMENT THIS SCRIPT IS FOR TESTING PURPOSES
 
21
 
 
22
use lib 'lib','lib/DBServer';
 
23
use lib "$ENV{RQG_HOME}/lib";
 
24
use Carp;
 
25
use strict;
 
26
use DBServer::DBServer;
 
27
use DBServer::MySQL::MySQLd;
 
28
use DBServer::MySQL::ReplMySQLd;
 
29
 
 
30
$| = 1;
 
31
if (osWindows()) {
 
32
        $SIG{CHLD} = "IGNORE";
 
33
}
 
34
 
 
35
if (defined $ENV{RQG_HOME}) {
 
36
    if (osWindows()) {
 
37
        $ENV{RQG_HOME} = $ENV{RQG_HOME}.'\\';
 
38
    } else {
 
39
        $ENV{RQG_HOME} = $ENV{RQG_HOME}.'/';
 
40
    }
 
41
}
 
42
 
 
43
use Getopt::Long;
 
44
use GenTest::Constants;
 
45
use DBI;
 
46
use Cwd;
 
47
 
 
48
my $database = 'test';
 
49
my @dsns;
 
50
 
 
51
my ($gendata, @basedirs, @mysqld_options, @vardirs, $rpl_mode,
 
52
    $engine, $help, $debug, 
 
53
    $valgrind, @valgrind_options, 
 
54
    $start_dirty, $build_thread);
 
55
 
 
56
my @ARGV_saved = @ARGV;
 
57
 
 
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,
 
72
        'help' => \$help,
 
73
        'debug' => \$debug,
 
74
        'valgrind!'     => \$valgrind,
 
75
        'valgrind_options=s@'   => \@valgrind_options,
 
76
        'start-dirty'   => \$start_dirty,
 
77
    'mtr-build-thread=i' => \$build_thread
 
78
    );
 
79
 
 
80
if (!$opt_result || $help || $basedirs[0] eq '') {
 
81
        help();
 
82
        exit($help ? 0 : 1);
 
83
}
 
84
 
 
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));
 
88
 
 
89
 
 
90
#
 
91
# Calculate master and slave ports based on MTR_BUILD_THREAD (MTR
 
92
# Version 1 behaviour)
 
93
#
 
94
 
 
95
if (not defined $build_thread) {
 
96
    if (defined $ENV{MTR_BUILD_THREAD}) {
 
97
        $build_thread = $ENV{MTR_BUILD_THREAD}
 
98
    } else {
 
99
        $build_thread = DEFAULT_MTR_BUILD_THREAD;
 
100
    }
 
101
}
 
102
 
 
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);
 
106
}
 
107
 
 
108
my @ports = (10000 + 10 * $build_thread, 10000 + 10 * $build_thread + 2);
 
109
 
 
110
say("master_port : $ports[0] slave_port : $ports[1] ports : @ports MTR_BUILD_THREAD : $build_thread ");
 
111
 
 
112
#
 
113
# If the user has provided two vardirs and one basedir, start second
 
114
# server using the same basedir
 
115
#
 
116
 
 
117
if (
 
118
        ($vardirs[1] ne '') && 
 
119
        ($basedirs[1] eq '')
 
120
    ) {
 
121
        $basedirs[1] = $basedirs[0];    
 
122
}
 
123
 
 
124
 
 
125
if (
 
126
        ($mysqld_options[1] ne '') && 
 
127
        ($basedirs[1] eq '')
 
128
    ) {
 
129
        $basedirs[1] = $basedirs[0];    
 
130
}
 
131
 
 
132
#
 
133
# If the user has provided identical basedirs and vardirs, warn of a
 
134
# potential overlap.
 
135
#
 
136
 
 
137
if (
 
138
        ($basedirs[0] eq $basedirs[1]) &&
 
139
        ($vardirs[0] eq $vardirs[1]) &&
 
140
        ($rpl_mode eq '')
 
141
    ) {
 
142
        croak("Please specify either different --basedir[12] or different --vardir[12] in order to start two MySQL servers");
 
143
}
 
144
 
 
145
my $client_basedir;
 
146
 
 
147
foreach my $path ("$basedirs[0]/client/RelWithDebInfo", "$basedirs[0]/client/Debug", "$basedirs[0]/client", "$basedirs[0]/bin") {
 
148
        if (-e $path) {
 
149
                $client_basedir = $path;
 
150
                last;
 
151
        }
 
152
}
 
153
 
 
154
#
 
155
# Start servers. Use rpl_alter if replication is needed.
 
156
#
 
157
 
 
158
my @server;
 
159
my $rplsrv;
 
160
 
 
161
if ($rpl_mode ne '') {
 
162
    my @options;
 
163
    push @options, lc("--$engine") if defined $engine && lc($engine) ne lc('myisam');
 
164
    
 
165
    push @options, "--sql-mode=no_engine_substitution" if join(' ', @ARGV_saved) !~ m{sql-mode}io;
 
166
    
 
167
    if (defined $mysqld_options[0]) {
 
168
        push @options, @{$mysqld_options[0]};
 
169
    }
 
170
    
 
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],
 
176
                                               mode => $rpl_mode,
 
177
                                               server_options => \@options,
 
178
                                               valgrind => $valgrind,
 
179
                                               valgrind_options => \@valgrind_options,
 
180
                                               start_dirty => $start_dirty);
 
181
    
 
182
    my $status = $rplsrv->startServer();
 
183
    
 
184
    if ($status > STATUS_OK) {
 
185
        stopServers();
 
186
        say(system("ls -l ".$rplsrv->master->datadir));
 
187
        say(system("ls -l ".$rplsrv->slave->datadir));
 
188
        croak("Could not start replicating server pair");
 
189
    }
 
190
    
 
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;
 
195
    
 
196
} else {
 
197
    if ($#basedirs != $#vardirs) {
 
198
        croak ("The number of basedirs and vardirs must match $#basedirs != $#vardirs")
 
199
    }
 
200
    foreach my $server_id (0..1) {
 
201
        next if $basedirs[$server_id] eq '';
 
202
        
 
203
        my @options;
 
204
        push @options, lc("--$engine") if defined $engine && lc($engine) ne lc('myisam');
 
205
        
 
206
        push @options, "--sql-mode=no_engine_substitution" if join(' ', @ARGV_saved) !~ m{sql-mode}io;
 
207
        
 
208
        if (defined $mysqld_options[$server_id]) {
 
209
            push @options, @{$mysqld_options[$server_id]};
 
210
        }
 
211
        
 
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);
 
219
        
 
220
        my $status = $server[$server_id]->startServer;
 
221
        
 
222
        if ($status > STATUS_OK) {
 
223
            stopServers();
 
224
            say(system("ls -l ".$server[$server_id]->datadir));
 
225
            croak("Could not start all servers");
 
226
        }
 
227
        
 
228
        if (
 
229
            ($server_id == 0) ||
 
230
            ($rpl_mode eq '') 
 
231
            ) {
 
232
            $dsns[$server_id] = $server[$server_id]->dsn($database);
 
233
        }
 
234
    
 
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'");
 
238
        }
 
239
    }
 
240
}
 
241
 
 
242
say("\n\nHit return to stop server(s)");
 
243
 
 
244
my $something = <STDIN>;
 
245
 
 
246
stopServers();
 
247
 
 
248
sub stopServers {
 
249
    if ($rpl_mode ne '') {
 
250
        $rplsrv->stopServer();
 
251
    } else {
 
252
        foreach my $srv (@server) {
 
253
            if ($srv) {
 
254
                $srv->stopServer;
 
255
            }
 
256
        }
 
257
    }
 
258
}
 
259
 
 
260
 
 
261
sub help {
 
262
    
 
263
        print <<EOF
 
264
Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.
 
265
 
 
266
$0 - Run a complete random query generation test, including server start with replication and master/slave verification
 
267
    
 
268
    Options related to one standalone MySQL server:
 
269
 
 
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);
 
273
 
 
274
    Options related to two MySQL servers
 
275
 
 
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);
 
282
 
 
283
    General options
 
284
 
 
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
 
292
    --mtr-build-thread: 
 
293
                  Value used for MTR_BUILD_THREAD when servers are started and accessed.
 
294
    --debug     : Debug mode
 
295
    --help      : This help message
 
296
 
 
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.
 
299
EOF
 
300
        ;
 
301
        print "$0 arguments were: ".join(' ', @ARGV_saved)."\n";
 
302
        exit_test(STATUS_UNKNOWN_ERROR);
 
303
}
 
304
 
 
305
sub exit_test {
 
306
        my $status = shift;
 
307
    stopServers();
 
308
        say("[$$] $0 will exit with exit status $status");
 
309
        safe_exit($status);
 
310
}