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

« back to all changes in this revision

Viewing changes to tests/randgen/lib/GenTest/Reporter/DrizzleTransactionLog.pm

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

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::DrizzleTransactionLog;
 
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
        my $main_port;
 
40
        my $validator_port;
 
41
        my $basedir ;
 
42
        
 
43
        # do some setup and whatnot
 
44
        if (exists $ENV{'MASTER_MYPORT'})
 
45
        {
 
46
            $main_port = $ENV{'MASTER_MYPORT'};
 
47
        }
 
48
        else
 
49
        {
 
50
            $main_port = '9306';
 
51
        }
 
52
        if (exists $ENV{'BOT0_S1'})
 
53
        {
 
54
            $validator_port = $ENV{'BOT0_S1'};
 
55
        }
 
56
        else
 
57
        {
 
58
            $validator_port = '9307';
 
59
        }
 
60
        if (exists $ENV{'DRIZZLE_BASEDIR'})
 
61
        {
 
62
            $basedir = $ENV{'DRIZZLE_BASEDIR'};
 
63
        }
 
64
        else
 
65
        {
 
66
            $basedir= $reporter->serverVariable('basedir');
 
67
        }
 
68
        my $drizzledump = $basedir.'/client/drizzledump' ;
 
69
        my $drizzle_client = $basedir.'/client/drizzle' ;
 
70
        my $transaction_reader; 
 
71
        if (exists $ENV{'DRIZZLE_TRX_READER'})
 
72
        {
 
73
            $transaction_reader = $ENV{'DRIZZLE_TRX_READER'}
 
74
        } 
 
75
        elsif (-e $basedir.'/drizzled/message/transaction_reader')
 
76
        {
 
77
            $transaction_reader = $basedir.'/drizzled/message/transaction_reader';
 
78
        }
 
79
        else 
 
80
        {
 
81
            $transaction_reader = $basedir.'/plugin/transaction_log/utilities/drizzletrx' ;
 
82
        }
 
83
 
 
84
        # transaction log location can vary depending on how we start the server
 
85
        # we really only account for test-run and drizzle-automation starts
 
86
        my $transaction_log = '';
 
87
        if (-e $basedir.'/var/local/transaction.log')
 
88
        {
 
89
          $transaction_log = $basedir.'/var/local/transaction.log' ;
 
90
        }
 
91
        elsif (-e $basedir.'/tests/workdir/bot0/s0/var/master-data/local/transaction.log')
 
92
        {
 
93
          $transaction_log = $basedir.'/tests/workdir/bot0/s0/var/master-data/local/transaction.log' ;
 
94
        }
 
95
        else
 
96
        {
 
97
          $transaction_log = $basedir.'/tests/var/master-data/local/transaction.log' ;
 
98
        }
 
99
        my $transaction_log_copy = tmpdir()."/translog_".$$."_.log" ;
 
100
        copy($transaction_log, $transaction_log_copy);
 
101
 
 
102
 
 
103
        # We now attempt to replicate from the transaction log
 
104
        # We call transaction_reader and send the output
 
105
        # via the drizzle client to the validation server (slave)
 
106
        my $transaction_log_sql_file = tmpdir()."/translog_".$$."_.sql" ;
 
107
        say("transaction_log output file:  $transaction_log_sql_file");
 
108
        say("$transaction_reader -uroot $transaction_log > $transaction_log_sql_file");
 
109
        system("$transaction_reader -uroot $transaction_log > $transaction_log_sql_file") ;
 
110
        say("Replicating from transaction_log output...");
 
111
        my $rpl_command = "$drizzle_client --host=127.0.0.1 --port=$validator_port --user=root test <  $transaction_log_sql_file";
 
112
        say ("$rpl_command");
 
113
        my $drizzle_rpl_result = system($rpl_command) ;
 
114
        return STATUS_UNKNOWN_ERROR if $drizzle_rpl_result > 0 ;
 
115
 
 
116
          
 
117
        say("Validating replication via dumpfile compare...");
 
118
        my @files;
 
119
        my @ports = ($main_port, $validator_port);
 
120
 
 
121
        foreach my $port_id (0..1) 
 
122
          {
 
123
            $files[$port_id] = tmpdir()."/translog_rpl_dump_".$$."_".$ports[$port_id].".sql";
 
124
            say("$files[$port_id]");
 
125
            say("$drizzledump --compact --skip-extended-insert --host=127.0.0.1 --port=$ports[$port_id] --user=root test >$files[$port_id]");
 
126
            my $drizzledump_result = system("$drizzledump --compact --skip-extended-insert --host=127.0.0.1 --port=$ports[$port_id] --user=root test >$files[$port_id]");
 
127
            # disable pipe to 'sort' from drizzledump call above
 
128
            #| sort > $files[$port_id]");
 
129
            return STATUS_UNKNOWN_ERROR if $drizzledump_result > 0;
 
130
          }
 
131
         say ("Executing diff --unified $files[SERVER1_FILE_NAME] $files[SERVER2_FILE_NAME]");
 
132
         my $diff_result = system("diff --unified $files[SERVER1_FILE_NAME] $files[SERVER2_FILE_NAME]");
 
133
         $diff_result = $diff_result >> 8;
 
134
         say ("Cleaning up validation server...");
 
135
         system("$drizzle_client --host=127.0.0.1 --port=$validator_port --user=root -e 'DROP SCHEMA test'");
 
136
 
 
137
         say ("Resetting validation server...");
 
138
         my $create_schema_result = system("$drizzle_client --host=127.0.0.1 --port=$validator_port --user=root -e 'CREATE SCHEMA test'");
 
139
         say("$create_schema_result");      
 
140
 
 
141
         return STATUS_UNKNOWN_ERROR if $diff_result > 1;
 
142
 
 
143
         if ($diff_result == 1) 
 
144
         {
 
145
           say("Differences between the two servers were found after comparing dumpfiles");
 
146
           say("diff command:  diff --unified $files[SERVER1_FILE_NAME] $files[SERVER2_FILE_NAME]");
 
147
           say("Master dumpfile:  $files[SERVER1_FILE_NAME]");
 
148
           say("Slave dumpfile:   $files[SERVER2_FILE_NAME]");
 
149
           say("transaction_log output file:  $transaction_log_sql_file");
 
150
           say("Transaction log:  $transaction_log_copy");
 
151
           return STATUS_REPLICATION_FAILURE;
 
152
         } 
 
153
         else 
 
154
         {
 
155
           foreach my $file (@files) 
 
156
           {
 
157
             unlink($file);
 
158
           }
 
159
           unlink($transaction_log_sql_file);
 
160
           unlink($transaction_log_copy);
 
161
           return STATUS_OK;
 
162
         }
 
163
 
 
164
   }    
 
165
        
 
166
 
 
167
 
 
168
sub type {
 
169
        return REPORTER_TYPE_ALWAYS;
 
170
}
 
171
 
 
172
1;