1
# Copyright (C) 2008-2009 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::Reporter::ReplicationConnectionKiller;
21
@ISA = qw(GenTest::Reporter);
25
use GenTest::Reporter;
26
use GenTest::Constants;
30
use constant KILL_DURATION => 5;
33
local $SIG{INT} = sub {
34
kill(15, $tcpkill_pid) if defined $tcpkill_pid;
40
my $dsn = $reporter->dsn();
42
my $dbh = DBI->connect($dsn);
44
my $slave_host = $reporter->serverInfo('slave_host');
45
my $master_port = $reporter->serverVariable('port');
47
# If interface is not specified, tcpkill will auto-pick the first available
49
my $interface = $slave_host eq '127.0.0.1' ? 'lo' : '';
51
my $slave_local = $dbh->selectrow_array("
53
FROM INFORMATION_SCHEMA.PROCESSLIST
54
WHERE COMMAND = 'Binlog Dump'
57
my ($slave_local_host, $slave_local_port) = split (':', $slave_local);
59
$tcpkill_pid = fork();
61
if ($tcpkill_pid) { # parent
63
say("Killing tcpkill with pid $tcpkill_pid");
64
kill (15, $tcpkill_pid);
68
my $command = "/usr/sbin/tcpkill -i $interface src host $slave_local_host and src port $slave_local_port and dst port $master_port";
69
say("Executing $command");
76
return REPORTER_TYPE_PERIODIC;