~ubuntu-branches/ubuntu/saucy/drizzle/saucy

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.2.11) (2.1.16 sid)
  • Revision ID: package-import@ubuntu.com-20120619104649-9ij634mxm4x8pp4l
Tags: 1:7.1.36-stable-1ubuntu1
* Merge from Debian unstable. (LP: #987575)
  Remaining changes:
  - Added upstart script.
* debian/drizzle.upstart: dropped logger since upstart logs job
  output now.

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::AriaDoubleRecovery;
 
19
 
 
20
require Exporter;
 
21
@ISA = qw(GenTest::Reporter);
 
22
 
 
23
use strict;
 
24
use DBI;
 
25
use GenTest;
 
26
use GenTest::Constants;
 
27
use GenTest::Reporter;
 
28
use GenTest::Comparator;
 
29
use Data::Dumper;
 
30
use IPC::Open2;
 
31
use POSIX;
 
32
 
 
33
my $first_reporter;
 
34
 
 
35
sub monitor {
 
36
        my $reporter = shift;
 
37
 
 
38
        # In case of two servers, we will be called twice.
 
39
        # Only kill the first server and ignore the second call.
 
40
        
 
41
        $first_reporter = $reporter if not defined $first_reporter;
 
42
        return STATUS_OK if $reporter ne $first_reporter;
 
43
 
 
44
        my $pid = $reporter->serverInfo('pid');
 
45
 
 
46
        if (time() > $reporter->testEnd() - 19) {
 
47
                say("Sending SIGKILL to server with pid $pid in order to force a recovery.");
 
48
                kill(9, $pid);
 
49
                return STATUS_SERVER_KILLED;
 
50
        } else {
 
51
                return STATUS_OK;
 
52
        }
 
53
}
 
54
 
 
55
sub report {
 
56
        my $reporter = shift;
 
57
 
 
58
        #
 
59
        # If there is a hang during recovery in one engine, another engine may continue to print
 
60
        # periodic diagnostic output forever. This prevents PB2 timeout mechanisms from kicking in
 
61
        # In order to avoid that, we set our own crude alarm as a stop-gap measure
 
62
        #
 
63
        alarm(3600);
 
64
 
 
65
        $first_reporter = $reporter if not defined $first_reporter;
 
66
        return STATUS_OK if $reporter ne $first_reporter;
 
67
 
 
68
        my $binary = $reporter->serverInfo('binary');
 
69
        my $language = $reporter->serverVariable('language');
 
70
        my $lc_messages_dir = $reporter->serverVariable('lc_messages_dir');
 
71
        my $datadir = $reporter->serverVariable('datadir');
 
72
        $datadir =~ s{[\\/]$}{}sgio;
 
73
        my $recovery_datadir = $datadir.'_recovery';
 
74
        my $socket = $reporter->serverVariable('socket');
 
75
        my $port = $reporter->serverVariable('port');
 
76
        my $pid = $reporter->serverInfo('pid');
 
77
        my $aria_block_size = $reporter->serverVariable('maria_block_size') || $reporter->serverVariable('aria_block_size');
 
78
        my $plugin_dir = $reporter->serverVariable('plugin_dir');
 
79
        my $plugins = $reporter->serverPlugins();
 
80
        my $binlog_format = $reporter->serverVariable('binlog_format');
 
81
        my $binlog_on = $reporter->serverVariable('log_bin');
 
82
 
 
83
        my $engine = $reporter->serverVariable('storage_engine');
 
84
 
 
85
        my $dbh_prev = DBI->connect($reporter->dsn());
 
86
 
 
87
        if (defined $dbh_prev) {
 
88
                # Server is still running, kill it.
 
89
                $dbh_prev->disconnect();
 
90
 
 
91
                say("Sending SIGKILL to server with pid $pid in order to force a recovery.");
 
92
                kill(9, $pid);
 
93
                sleep(5);
 
94
        }
 
95
 
 
96
        say("Copying datadir... (interrupting the copy operation may cause a false recovery failure to be reported below");
 
97
        system("cp -r $datadir $recovery_datadir");
 
98
        system("rm -f $recovery_datadir/core*");        # Remove cores from any previous crash
 
99
 
 
100
        my $recovery_datadir_aria = $recovery_datadir.'-aria';
 
101
 
 
102
        say("Attempting database recovery using aria_read_log ...");
 
103
        say("Copying Aria log files from $datadir to $recovery_datadir_aria ...");
 
104
 
 
105
        # Copy just the *aria* files in an empty location and create a test "database"
 
106
        system("mkdir $recovery_datadir_aria");
 
107
        system("cp $datadir/*aria_log* $recovery_datadir_aria");
 
108
        system("mkdir $recovery_datadir_aria/test");
 
109
        system("mkdir $recovery_datadir_aria/smf");
 
110
        system("mkdir $recovery_datadir_aria/smf2");
 
111
 
 
112
        say("Copying complete.");
 
113
 
 
114
        my $aria_read_log_path;
 
115
        if (-e $reporter->serverVariable('basedir')."/../storage/maria/aria_read_log") {
 
116
                $aria_read_log_path = $reporter->serverVariable('basedir')."/../storage/maria/aria_read_log";
 
117
        } else {
 
118
                $aria_read_log_path = $reporter->serverVariable('basedir')."/../storage/maria/maria_read_log";                  
 
119
        }
 
120
 
 
121
        my $aria_chk_path;
 
122
 
 
123
        if (-e $reporter->serverVariable('basedir')."/../storage/maria/aria_chk") {
 
124
                $aria_chk_path = $reporter->serverVariable('basedir')."/../storage/maria/aria_chk";
 
125
        } else {
 
126
                $aria_chk_path = $reporter->serverVariable('basedir')."/../storage/maria/maria_chk";
 
127
        }
 
128
 
 
129
        chdir($recovery_datadir_aria);
 
130
        my $aria_read_log_command = $aria_read_log_path." --aria-log-dir-path $recovery_datadir_aria --apply --check --silent";
 
131
 
 
132
        my $recovery_pid;
 
133
        my $recovery_duration = 4;
 
134
        my $child_pid = fork();
 
135
        if ($child_pid == 0) {
 
136
                say("Executing first $aria_read_log_command");
 
137
                exec($aria_read_log_command);
 
138
                exit();
 
139
        } else {
 
140
                $recovery_pid = $child_pid;
 
141
                say("Will kill the first aria_read_log via kill -9 $recovery_pid in $recovery_duration seconds");
 
142
                local $SIG{ALRM} = sub { kill 9 , $recovery_pid } ;
 
143
                alarm($recovery_duration);
 
144
                sleep($recovery_duration);
 
145
        }
 
146
 
 
147
        alarm(0);
 
148
        print "\n";
 
149
        sleep(1);
 
150
 
 
151
        say("Executing second $aria_read_log_command");
 
152
        my $aria_read_log_result = system($aria_read_log_command);
 
153
        return STATUS_RECOVERY_FAILURE if $aria_read_log_result > 0;
 
154
        say("$aria_read_log_path apparently returned success");
 
155
 
 
156
        my $aria_chk_result = system("$aria_chk_path --extend-check */*.MAI");
 
157
        return STATUS_RECOVERY_FAILURE if $aria_chk_result > 0;
 
158
        say("$aria_chk_path apparently returned success");
 
159
        return STATUS_OK;
 
160
}
 
161
 
 
162
sub type {
 
163
        return REPORTER_TYPE_ALWAYS | REPORTER_TYPE_PERIODIC;
 
164
}
 
165
 
 
166
1;