1
# Copyright (C) 2010 Sun Microsystems, Inc. All rights reserved.
2
# Use is subject to license terms.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18
package GenTest::Server::ReplMySQLd;
24
use GenTest::Constants;
25
use GenTest::Server::MySQLd;
26
use if windows(), Win32::Process;
34
use constant REPLMYSQLD_BASEDIR => 0;
35
use constant REPLMYSQLD_MASTER_VARDIR => 1;
36
use constant REPLMYSQLD_SLAVE_VARDIR => 2;
37
use constant REPLMYSQLD_MASTER_PORT => 3;
38
use constant REPLMYSQLD_SLAVE_PORT => 4;
39
use constant REPLMYSQLD_MODE => 5;
40
use constant REPLMYSQLD_START_DIRTY => 6;
41
use constant REPLMYSQLD_SERVER_OPTIONS => 7;
42
use constant REPLMYSQLD_MASTER => 8;
43
use constant REPLMYSQLD_SLAVE => 9;
48
my $self = $class->SUPER::new({'basedir' => REPLMYSQLD_BASEDIR,
49
'master_vardir' => REPLMYSQLD_MASTER_VARDIR,
50
'master_port' => REPLMYSQLD_MASTER_PORT,
51
'slave_vardir' => REPLMYSQLD_SLAVE_VARDIR,
52
'slave_port' => REPLMYSQLD_SLAVE_PORT,
53
'mode' => REPLMYSQLD_MODE,
54
'server_options' => REPLMYSQLD_SERVER_OPTIONS,
55
'start_dirty' => REPLMYSQLD_START_DIRTY},@_);
57
if (not defined $self->[REPLMYSQLD_MASTER_PORT]) {
58
$self->[REPLMYSQLD_MASTER_PORT] = GenTest::Server::MySQLd::MYSQLD_DEFAULT_PORT;
61
if (not defined $self->[REPLMYSQLD_SLAVE_PORT]) {
62
$self->[REPLMYSQLD_SLAVE_PORT] = $self->[REPLMYSQLD_MASTER_PORT] + 2;
65
if (not defined $self->[REPLMYSQLD_MODE]) {
66
$self->[REPLMYSQLD_MODE] = 'default';
72
"--report-host=127.0.0.1",
73
"--report_port=".$self->[REPLMYSQLD_MASTER_PORT]);
74
if (defined $self->[REPLMYSQLD_SERVER_OPTIONS]) {
76
@{$self->[REPLMYSQLD_SERVER_OPTIONS]});
80
$self->[REPLMYSQLD_MASTER] = GenTest::Server::MySQLd->new(basedir => $self->basedir,
81
vardir => $self->[REPLMYSQLD_MASTER_VARDIR],
82
port => $self->[REPLMYSQLD_MASTER_PORT],
83
server_options => \@master_options,
84
start_dirty => $self->[REPLMYSQLD_START_DIRTY]);
86
if (not defined $self->master) {
87
croak("Could not create master");
93
"--report-host=127.0.0.1",
94
"--report_port=".$self->[REPLMYSQLD_SLAVE_PORT]);
95
if (defined $self->[REPLMYSQLD_SERVER_OPTIONS]) {
97
@{$self->[REPLMYSQLD_SERVER_OPTIONS]});
101
$self->[REPLMYSQLD_SLAVE] = GenTest::Server::MySQLd->new(basedir => $self->basedir,
102
vardir => $self->[REPLMYSQLD_SLAVE_VARDIR],
103
port => $self->[REPLMYSQLD_SLAVE_PORT],
104
server_options => \@slave_options,
105
start_dirty => $self->[REPLMYSQLD_START_DIRTY]);
107
if (not defined $self->slave) {
108
croak("Could not create slave");
115
return $_[0]->[REPLMYSQLD_BASEDIR];
119
return $_[0]->[REPLMYSQLD_MASTER];
123
return $_[0]->[REPLMYSQLD_SLAVE];
127
return $_[0]->[REPLMYSQLD_MODE];
133
$self->master->startServer;
134
my $master_dbh = $self->master->dbh;
135
$self->slave->startServer;
136
my $slave_dbh = $self->slave->dbh;
138
my ($foo, $master_version) = $master_dbh->selectrow_array("SHOW VARIABLES LIKE 'version'");
140
if (($master_version !~ m{^5\.0}sio) && ($self->mode ne 'default')) {
141
$master_dbh->do("SET GLOBAL BINLOG_FORMAT = '".$self->mode."'");
142
$slave_dbh->do("SET GLOBAL BINLOG_FORMAT = '".$self->mode."'");
145
$slave_dbh->do("STOP SLAVE");
147
# $slave_dbh->do("SET GLOBAL storage_engine = '$engine'") if defined $engine;
149
$slave_dbh->do("CHANGE MASTER TO
150
MASTER_PORT = ".$self->master->port.",
151
MASTER_HOST = '127.0.0.1',
152
MASTER_USER = 'root',
153
MASTER_CONNECT_RETRY = 1
156
$slave_dbh->do("START SLAVE");
165
$self->master->stopServer;
166
$self->slave->stopServer;