~ubuntu-branches/ubuntu/trusty/drizzle/trusty-updates

« back to all changes in this revision

Viewing changes to tests/kewpie/randgen/lib/GenTest/Reporter/ReplicationConnectionKiller.pm

  • Committer: Package Import Robot
  • Author(s): Tobias Frost
  • Date: 2012-04-04 15:12:07 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20120404151207-xwsgn1xegslle4p0
Tags: 1:7.1.32-rc-1
* New upstream release.
* Plugin-filtered-replicator upstream removed and will no longer be built.
* Updating d/*install files to accommodate upstream changes from drizzle7
  to drizzle
* Added symlink in libdrizzledmessage-dev to library
* libdrizzle: soname-bump
* Rename package drizzle-plugin-performance-dictionary to shorten package name
  (due to linitan warning package-has-long-file-name)
* Debian/control: removed unused substitution variable ${shlibs:Depends} for
  -dbg and -dev packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
18
package GenTest::Reporter::ReplicationConnectionKiller;
 
19
 
 
20
require Exporter;
 
21
@ISA = qw(GenTest::Reporter);
 
22
 
 
23
use strict;
 
24
use GenTest;
 
25
use GenTest::Reporter;
 
26
use GenTest::Constants;
 
27
 
 
28
my $tcpkill_pid;
 
29
 
 
30
use constant KILL_DURATION => 5;
 
31
 
 
32
sub monitor {
 
33
        local $SIG{INT} = sub {
 
34
                kill(15, $tcpkill_pid) if defined $tcpkill_pid;
 
35
                exit(STATUS_OK);
 
36
        };
 
37
 
 
38
        my $reporter = shift;
 
39
 
 
40
        my $dsn = $reporter->dsn();
 
41
 
 
42
        my $dbh = DBI->connect($dsn);
 
43
 
 
44
        my $slave_host = $reporter->serverInfo('slave_host');
 
45
        my $master_port = $reporter->serverVariable('port');
 
46
 
 
47
        # If interface is not specified, tcpkill will auto-pick the first available
 
48
 
 
49
        my $interface = $slave_host eq '127.0.0.1' ? 'lo' : '';
 
50
 
 
51
        my $slave_local = $dbh->selectrow_array("
 
52
                SELECT HOST
 
53
                FROM INFORMATION_SCHEMA.PROCESSLIST
 
54
                WHERE COMMAND = 'Binlog Dump'
 
55
        ");
 
56
        
 
57
        my ($slave_local_host, $slave_local_port) = split (':', $slave_local);
 
58
 
 
59
        $tcpkill_pid = fork();
 
60
 
 
61
        if ($tcpkill_pid) {     # parent
 
62
                sleep(KILL_DURATION);
 
63
                say("Killing tcpkill with pid $tcpkill_pid");
 
64
                kill (15, $tcpkill_pid);
 
65
                $tcpkill_pid = undef;
 
66
                return(STATUS_OK);
 
67
        } else {
 
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");
 
70
                exec($command);
 
71
                exit(STATUS_OK);
 
72
        }
 
73
}
 
74
 
 
75
sub type {
 
76
        return REPORTER_TYPE_PERIODIC;
 
77
}
 
78
 
 
79
1;