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

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-10-29 15:43:40 UTC
  • mfrom: (1.2.12) (2.1.19 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029154340-2gp39el6cv8bwf2o
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
 
package GenTest::Reporter::DrizzleSlavePlugin;
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 Data::Dumper;
29
 
use IPC::Open2;
30
 
use IPC::Open3;
31
 
use File::Copy;
32
 
 
33
 
use constant SERVER1_FILE_NAME  => 0;
34
 
use constant SERVER2_FILE_NAME  => 1;
35
 
 
36
 
sub report 
37
 
  {
38
 
        my $reporter = shift;
39
 
 
40
 
        
41
 
        # do some setup and whatnot
42
 
        my $main_port;
43
 
        my $validator_port;
44
 
        my $basedir;
45
 
 
46
 
        if (exists $ENV{'MASTER_MYPORT'})
47
 
        {
48
 
            $main_port = $ENV{'MASTER_MYPORT'};
49
 
        }
50
 
        else
51
 
        {
52
 
            $main_port = '9306';
53
 
        }
54
 
        if (exists $ENV{'BOT0_S1'})
55
 
        {
56
 
            $validator_port = $ENV{'BOT0_S1'};
57
 
        }
58
 
        else
59
 
        {
60
 
            $validator_port = '9307';
61
 
        }
62
 
        if (exists $ENV{'DRIZZLE_BASEDIR'})
63
 
        {
64
 
            $basedir = $ENV{'DRIZZLE_BASEDIR'};
65
 
        }
66
 
        else
67
 
        {
68
 
            $basedir= $reporter->serverVariable('basedir');
69
 
        }
70
 
        my $drizzledump = $basedir.'/client/drizzledump' ;
71
 
        my $drizzle_client = $basedir.'/client/drizzle' ;
72
 
        my $transaction_reader; 
73
 
        if (exists $ENV{'DRIZZLE_TRX_READER'})
74
 
        {
75
 
            $transaction_reader = $ENV{'DRIZZLE_TRX_READER'}
76
 
        } 
77
 
        elsif (-e $basedir.'/drizzled/message/transaction_reader')
78
 
        {
79
 
            $transaction_reader = $basedir.'/drizzled/message/transaction_reader';
80
 
        }
81
 
        else 
82
 
        {
83
 
            $transaction_reader = $basedir.'/plugin/transaction_log/utilities/drizzletrx' ;
84
 
        }
85
 
 
86
 
        # transaction log location can vary depending on how we start the server
87
 
        # we really only account for test-run and drizzle-automation starts
88
 
        my $transaction_log = '';
89
 
        if (-e $basedir.'/var/local/transaction.log')
90
 
        {
91
 
          $transaction_log = $basedir.'/var/local/transaction.log' ;
92
 
        }
93
 
        elsif (-e $basedir.'/tests/workdir/bot0/s0/var/master-data/local/transaction.log')
94
 
        {
95
 
          $transaction_log = $basedir.'/tests/workdir/bot0/s0/var/master-data/local/transaction.log' ;
96
 
        }
97
 
        else
98
 
        {
99
 
          $transaction_log = $basedir.'/tests/var/master-data/local/transaction.log' ;
100
 
        }
101
 
        my $transaction_log_copy = tmpdir()."/translog_".$$."_.log" ;
102
 
        copy($transaction_log, $transaction_log_copy);
103
 
 
104
 
        say("Waiting for slave to catch up...");
105
 
        #sleep 60;
106
 
        my $slave_dsn="dbi:drizzle:host=localhost:port=$validator_port:user=root:password='':database=sys_replication";
107
 
        my $slave_dbh = DBI->connect($slave_dsn, undef, undef, {PrintError => 0});
108
 
        my $master_dbh = DBI->connect($reporter->dsn(), undef, undef, {PrintError => 0});
109
 
        my $not_done = 1;
110
 
        while ($not_done)
111
 
        {
112
 
            my @max_slave_id_res = $slave_dbh->selectrow_array('SELECT last_applied_commit_id from applier_state');
113
 
            my $max_slave_id = @max_slave_id_res->[0] ;
114
 
            my @max_master_id_res = $master_dbh->selectrow_arrayref("SELECT MAX(commit_id) from DATA_DICTIONARY.SYS_REPLICATION_LOG");
115
 
            my $max_master_id = @max_master_id_res->[0]->[0] ;
116
 
            if ($max_slave_id == $max_master_id)
117
 
            {
118
 
                $not_done = 0 ;
119
 
            }
120
 
            sleep 1;
121
 
            #say ("$max_slave_id");
122
 
            #say ("$max_master_id");
123
 
            #$not_done = 0;
124
 
        }
125
 
        say("Validating replication via dumpfile compare...");
126
 
        my @files;
127
 
        my @ports = ($main_port, $validator_port);
128
 
 
129
 
        foreach my $port_id (0..1) 
130
 
          {
131
 
            $files[$port_id] = tmpdir()."/translog_rpl_dump_".$$."_".$ports[$port_id].".sql";
132
 
            say("$files[$port_id]");
133
 
            say("$drizzledump --compact --skip-extended-insert --host=127.0.0.1 --port=$ports[$port_id] --user=root test >$files[$port_id]");
134
 
            my $drizzledump_result = system("$drizzledump --compact --skip-extended-insert --host=127.0.0.1 --port=$ports[$port_id] --user=root test >$files[$port_id]");
135
 
            # disable pipe to 'sort' from drizzledump call above
136
 
            #| sort > $files[$port_id]");
137
 
            return STATUS_UNKNOWN_ERROR if $drizzledump_result > 0;
138
 
          }
139
 
         say ("Executing diff --unified $files[SERVER1_FILE_NAME] $files[SERVER2_FILE_NAME]");
140
 
         my $diff_result = system("diff --unified $files[SERVER1_FILE_NAME] $files[SERVER2_FILE_NAME]");
141
 
         $diff_result = $diff_result >> 8;
142
 
       
143
 
 
144
 
         return STATUS_UNKNOWN_ERROR if $diff_result > 1;
145
 
 
146
 
         if ($diff_result == 1) 
147
 
         {
148
 
           say("Differences between the two servers were found after comparing dumpfiles");
149
 
           say("diff command:  diff --unified $files[SERVER1_FILE_NAME] $files[SERVER2_FILE_NAME]");
150
 
           say("Master dumpfile:  $files[SERVER1_FILE_NAME]");
151
 
           say("Slave dumpfile:   $files[SERVER2_FILE_NAME]");
152
 
           #say ("$max_slave_id");
153
 
           #say ("$max_master_id");
154
 
           return STATUS_REPLICATION_FAILURE;
155
 
         } 
156
 
         else 
157
 
         {
158
 
           foreach my $file (@files) 
159
 
           {
160
 
             unlink($file);
161
 
           }
162
 
           return STATUS_OK;
163
 
         }
164
 
 
165
 
   }    
166
 
        
167
 
 
168
 
 
169
 
sub type {
170
 
        return REPORTER_TYPE_ALWAYS;
171
 
}
172
 
 
173
 
1;