~drizzle-trunk/drizzle/development

0.67.305 by Bernt M. Johnsen
Copyright headres and license added
1
# Copyright (C) 2008-2009 Sun Microsystems, Inc. All rights reserved.
2
# Use is subject to license terms.
3
#
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.
7
#
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.
12
#
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
16
# USA
17
0.67.1 by Philip Stoev
initial import from internal tree
18
package GenTest::Validator::ReplicationSlaveStatus;
19
20
require Exporter;
21
@ISA = qw(GenTest::Validator GenTest);
22
23
use strict;
24
25
use DBI;
26
use GenTest;
27
use GenTest::Constants;
28
use GenTest::Result;
29
use GenTest::Validator;
30
31
use constant SLAVE_STATUS_LAST_ERROR		=> 19;
32
use constant SLAVE_STATUS_LAST_SQL_ERROR	=> 35;
33
use constant SLAVE_STATUS_LAST_IO_ERROR		=> 38;
34
35
sub init {
36
	my ($validator, $executors) = @_;
37
	my $master_executor = $executors->[0];
38
39
	my ($slave_host, $slave_port) = $master_executor->slaveInfo();
40
41
	if (
42
		($slave_host eq '') || 
43
		($slave_port eq '')
44
	) {
45
		say("SHOW SLAVE HOSTS returns no data.");
46
		return STATUS_REPLICATION_FAILURE;
47
	}
48
	my $slave_dsn = 'dbi:mysql:host='.$slave_host.':port='.$slave_port.':user=root';
49
50
	my $slave_dbh = DBI->connect($slave_dsn, undef, undef, { PrintError => 0 });
51
	$validator->setDbh($slave_dbh);
52
	return STATUS_OK;
53
}
54
55
sub validate {
56
	my ($validator, $executors, $results) = @_;
57
58
	my $master_executor = $executors->[0];
59
60
	my $slave_status = $validator->dbh()->selectrow_arrayref("SHOW SLAVE STATUS");
61
62
	if ($slave_status->[SLAVE_STATUS_LAST_IO_ERROR] ne '') {
63
		say("Slave IO thread has stopped with error: ".$slave_status->[SLAVE_STATUS_LAST_IO_ERROR]);
64
		return STATUS_REPLICATION_FAILURE;
65
	} elsif ($slave_status->[SLAVE_STATUS_LAST_SQL_ERROR] ne '') {
66
		say("Slave SQL thread has stopped with error: ".$slave_status->[SLAVE_STATUS_LAST_SQL_ERROR]);
67
		return STATUS_REPLICATION_FAILURE;
68
	} elsif ($slave_status->[SLAVE_STATUS_LAST_ERROR] ne '') {
69
		say("Slave has stopped with error: ".$slave_status->[SLAVE_STATUS_LAST_ERROR]);
70
		return STATUS_REPLICATION_FAILURE;
71
        } else {
72
                return STATUS_OK;
73
        }
74
}
75
76
1;