~ubuntu-branches/ubuntu/vivid/drizzle/vivid

« back to all changes in this revision

Viewing changes to tests/test_tools/randgen/lib/GenTest/Reporter/DrizzleRecoveryConsistency.pm

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-10-29 15:43:40 UTC
  • mfrom: (20.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20131029154340-j36v7gxq9tm1gi5f
Tags: 1:7.2.3-2ubuntu1
* Merge from debian, remaining changes:
  - Link against boost_system because of boost_thread.
  - Add required libs to message/include.am
  - Add upstart job and adjust init script to be upstart compatible.
  - Disable -floop-parallelize-all due to gcc-4.8/4.9 compiler ICE
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57732

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
# We need to revisit the grammar we use / how we validate consistency
 
19
# if we need to keep using this reporter
 
20
 
 
21
package GenTest::Reporter::DrizzleRecoveryConsistency;
 
22
 
 
23
require Exporter;
 
24
@ISA = qw(GenTest::Reporter);
 
25
 
 
26
use strict;
 
27
use DBI;
 
28
use GenTest;
 
29
use GenTest::Constants;
 
30
use GenTest::Reporter;
 
31
 
 
32
sub monitor {
 
33
        my $reporter = shift;
 
34
                my $dbh = DBI->connect($reporter->dsn(), undef, undef, {PrintError => 0});
 
35
 
 
36
        if (time() > $reporter->testEnd() - 20) {
 
37
                say("Sending shutdown() call to server.");
 
38
                $dbh->selectrow_array('SELECT shutdown()');
 
39
                sleep(5);
 
40
                return STATUS_SERVER_KILLED;
 
41
        } else {
 
42
                return STATUS_OK;
 
43
        }
 
44
}
 
45
 
 
46
 
 
47
sub report {
 
48
        my $reporter = shift;
 
49
        my $dbh = DBI->connect($reporter->dsn(), undef, undef, {PrintError => 0});
 
50
        my $basedir = $reporter->serverVariable('basedir');
 
51
        say("$basedir");
 
52
        my $binary = $basedir.'/drizzled/drizzled' ;
 
53
        my $datadir = '';
 
54
        if (-e $basedir.'/var')
 
55
        {
 
56
            $datadir = $basedir.'/var/';
 
57
        }
 
58
        else
 
59
        {
 
60
            $datadir = $basedir.'tests/var/master-data';
 
61
        }
 
62
        $datadir =~ s{[\\/]$}{}sgio;
 
63
        my $recovery_datadir = $datadir.'_recovery';
 
64
        my $port = $reporter->serverVariable('mysql_protocol_port');
 
65
        
 
66
        say("Sending shutdown() call to server.");
 
67
        $dbh->selectrow_array('SELECT shutdown()');
 
68
        sleep(5);
 
69
 
 
70
 
 
71
        system("cp -r $datadir $recovery_datadir");
 
72
        
 
73
        say("Attempting database recovery...");
 
74
 
 
75
        my @drizzled_options = (
 
76
                '--no-defaults',
 
77
                '--core-file',  
 
78
                '--datadir="'.$recovery_datadir.'"',
 
79
                '--basedir="'.$basedir.'"',
 
80
                '--plugin-add=shutdown_function',
 
81
                '--mysql-protocol.port='.$port,
 
82
 
 
83
        );
 
84
 
 
85
        my $drizzled_command = $binary.' '.join(' ', @drizzled_options).' 2>&1';
 
86
        say("Executing $drizzled_command .");
 
87
 
 
88
        open(DRIZZLED, "$drizzled_command|");
 
89
        my $recovery_status = STATUS_OK;
 
90
        while (<DRIZZLED>) {
 
91
                $_ =~ s{[\r\n]}{}siog;
 
92
                say($_);
 
93
                if ($_ =~ m{exception}sio) {
 
94
                        $recovery_status = STATUS_DATABASE_CORRUPTION;
 
95
                } elsif ($_ =~ m{ready for connections}sio) {
 
96
                        say("Server Recovery was apparently successfull.") if $recovery_status == STATUS_OK ;
 
97
                        last;
 
98
                } elsif ($_ =~ m{got signal}sio) {
 
99
                        $recovery_status = STATUS_DATABASE_CORRUPTION;
 
100
 
 
101
                }
 
102
        }
 
103
 
 
104
        say("Checking database consistency...");
 
105
        my $dbh = DBI->connect($reporter->dsn());
 
106
 
 
107
        my $tables = $dbh->selectcol_arrayref("SHOW TABLES");
 
108
 
 
109
        foreach my $table (@$tables) {
 
110
                my $average = $dbh->selectrow_array("
 
111
                        SELECT (SUM(`col_int_key`)  + SUM(`col_int`)) / COUNT(*)
 
112
                        FROM `$table`
 
113
                ");
 
114
 
 
115
                if ($average ne '200.0000') {
 
116
                        say("Bad average on table: $table; average: $average");
 
117
                        $recovery_status = STATUS_DATABASE_CORRUPTION;
 
118
                } else {
 
119
                        say("Average is $average");
 
120
                }
 
121
        }
 
122
 
 
123
        say("Shutting down the recovered server...");
 
124
 
 
125
        if (not defined $dbh) {
 
126
                $recovery_status = STATUS_DATABASE_CORRUPTION;
 
127
        } else {
 
128
                say("Sending shutdown() call to server.");
 
129
                $dbh->selectrow_array('SELECT shutdown()');
 
130
        }
 
131
 
 
132
        close(DRIZZLED);
 
133
 
 
134
        if ($recovery_status > STATUS_OK) {
 
135
                say("Recovery has failed.");
 
136
        }
 
137
 
 
138
        return $recovery_status;
 
139
}       
 
140
 
 
141
sub type {
 
142
        return REPORTER_TYPE_CRASH | REPORTER_TYPE_DEADLOCK | REPORTER_TYPE_SUCCESS | REPORTER_TYPE_PERIODIC | REPORTER_TYPE_SERVER_KILLED;
 
143
}
 
144
 
 
145
1;