~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to lib/GenTest/Reporter/ReplicationConnectionKiller.pm

initial import from internal tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package GenTest::Reporter::ReplicationConnectionKiller;
 
2
 
 
3
require Exporter;
 
4
@ISA = qw(GenTest::Reporter);
 
5
 
 
6
use strict;
 
7
use GenTest;
 
8
use GenTest::Reporter;
 
9
use GenTest::Constants;
 
10
 
 
11
my $tcpkill_pid;
 
12
 
 
13
use constant KILL_DURATION => 5;
 
14
 
 
15
sub monitor {
 
16
        local $SIG{INT} = sub {
 
17
                kill(15, $tcpkill_pid) if defined $tcpkill_pid;
 
18
                exit(STATUS_OK);
 
19
        };
 
20
 
 
21
        my $reporter = shift;
 
22
 
 
23
        my $dsn = $reporter->dsn();
 
24
 
 
25
        my $dbh = DBI->connect($dsn);
 
26
 
 
27
        my $slave_host = $reporter->serverInfo('slave_host');
 
28
        my $master_port = $reporter->serverVariable('port');
 
29
 
 
30
        # If interface is not specified, tcpkill will auto-pick the first available
 
31
 
 
32
        my $interface = $slave_host eq '127.0.0.1' ? 'lo' : '';
 
33
 
 
34
        my $slave_local = $dbh->selectrow_array("
 
35
                SELECT HOST
 
36
                FROM INFORMATION_SCHEMA.PROCESSLIST
 
37
                WHERE COMMAND = 'Binlog Dump'
 
38
        ");
 
39
        
 
40
        my ($slave_local_host, $slave_local_port) = split (':', $slave_local);
 
41
 
 
42
        $tcpkill_pid = fork();
 
43
 
 
44
        if ($tcpkill_pid) {     # parent
 
45
                sleep(KILL_DURATION);
 
46
                say("Killing tcpkill with pid $tcpkill_pid");
 
47
                kill (15, $tcpkill_pid);
 
48
                $tcpkill_pid = undef;
 
49
                return(STATUS_OK);
 
50
        } else {
 
51
                my $command = "/usr/sbin/tcpkill -i $interface src host $slave_local_host and src port $slave_local_port and dst port $master_port";
 
52
                say("Executing $command");
 
53
                exec($command);
 
54
                exit(STATUS_OK);
 
55
        }
 
56
}
 
57
 
 
58
sub type {
 
59
        return REPORTER_TYPE_PERIODIC;
 
60
}
 
61
 
 
62
1;