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::AriaDoubleRecovery;
21
@ISA = qw(GenTest::Reporter);
26
use GenTest::Constants;
27
use GenTest::Reporter;
28
use GenTest::Comparator;
38
# In case of two servers, we will be called twice.
39
# Only kill the first server and ignore the second call.
41
$first_reporter = $reporter if not defined $first_reporter;
42
return STATUS_OK if $reporter ne $first_reporter;
44
my $pid = $reporter->serverInfo('pid');
46
if (time() > $reporter->testEnd() - 19) {
47
say("Sending SIGKILL to server with pid $pid in order to force a recovery.");
49
return STATUS_SERVER_KILLED;
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
65
$first_reporter = $reporter if not defined $first_reporter;
66
return STATUS_OK if $reporter ne $first_reporter;
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');
83
my $engine = $reporter->serverVariable('storage_engine');
85
my $dbh_prev = DBI->connect($reporter->dsn());
87
if (defined $dbh_prev) {
88
# Server is still running, kill it.
89
$dbh_prev->disconnect();
91
say("Sending SIGKILL to server with pid $pid in order to force a recovery.");
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
100
my $recovery_datadir_aria = $recovery_datadir.'-aria';
102
say("Attempting database recovery using aria_read_log ...");
103
say("Copying Aria log files from $datadir to $recovery_datadir_aria ...");
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");
112
say("Copying complete.");
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";
118
$aria_read_log_path = $reporter->serverVariable('basedir')."/../storage/maria/maria_read_log";
123
if (-e $reporter->serverVariable('basedir')."/../storage/maria/aria_chk") {
124
$aria_chk_path = $reporter->serverVariable('basedir')."/../storage/maria/aria_chk";
126
$aria_chk_path = $reporter->serverVariable('basedir')."/../storage/maria/maria_chk";
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";
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);
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);
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");
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");
163
return REPORTER_TYPE_ALWAYS | REPORTER_TYPE_PERIODIC;