~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to lib/GenTest/Validator/ReplicationSlaveStatus.pm

initial import from internal tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package GenTest::Validator::ReplicationSlaveStatus;
 
2
 
 
3
require Exporter;
 
4
@ISA = qw(GenTest::Validator GenTest);
 
5
 
 
6
use strict;
 
7
 
 
8
use DBI;
 
9
use GenTest;
 
10
use GenTest::Constants;
 
11
use GenTest::Result;
 
12
use GenTest::Validator;
 
13
 
 
14
use constant SLAVE_STATUS_LAST_ERROR            => 19;
 
15
use constant SLAVE_STATUS_LAST_SQL_ERROR        => 35;
 
16
use constant SLAVE_STATUS_LAST_IO_ERROR         => 38;
 
17
 
 
18
sub init {
 
19
        my ($validator, $executors) = @_;
 
20
        my $master_executor = $executors->[0];
 
21
 
 
22
        my ($slave_host, $slave_port) = $master_executor->slaveInfo();
 
23
 
 
24
        if (
 
25
                ($slave_host eq '') || 
 
26
                ($slave_port eq '')
 
27
        ) {
 
28
                say("SHOW SLAVE HOSTS returns no data.");
 
29
                return STATUS_REPLICATION_FAILURE;
 
30
        }
 
31
        my $slave_dsn = 'dbi:mysql:host='.$slave_host.':port='.$slave_port.':user=root';
 
32
 
 
33
        my $slave_dbh = DBI->connect($slave_dsn, undef, undef, { PrintError => 0 });
 
34
        $validator->setDbh($slave_dbh);
 
35
        return STATUS_OK;
 
36
}
 
37
 
 
38
sub validate {
 
39
        my ($validator, $executors, $results) = @_;
 
40
 
 
41
        my $master_executor = $executors->[0];
 
42
 
 
43
        my $slave_status = $validator->dbh()->selectrow_arrayref("SHOW SLAVE STATUS");
 
44
 
 
45
        if ($slave_status->[SLAVE_STATUS_LAST_IO_ERROR] ne '') {
 
46
                say("Slave IO thread has stopped with error: ".$slave_status->[SLAVE_STATUS_LAST_IO_ERROR]);
 
47
                return STATUS_REPLICATION_FAILURE;
 
48
        } elsif ($slave_status->[SLAVE_STATUS_LAST_SQL_ERROR] ne '') {
 
49
                say("Slave SQL thread has stopped with error: ".$slave_status->[SLAVE_STATUS_LAST_SQL_ERROR]);
 
50
                return STATUS_REPLICATION_FAILURE;
 
51
        } elsif ($slave_status->[SLAVE_STATUS_LAST_ERROR] ne '') {
 
52
                say("Slave has stopped with error: ".$slave_status->[SLAVE_STATUS_LAST_ERROR]);
 
53
                return STATUS_REPLICATION_FAILURE;
 
54
        } else {
 
55
                return STATUS_OK;
 
56
        }
 
57
}
 
58
 
 
59
1;