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

« back to all changes in this revision

Viewing changes to tests/randgen/lib/GenTest/Validator/DrizzledumpMigrate.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) 2010 Patrick Crews. 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
 
# DrizzledumpMigrate
19
 
# Validator for testing drizzledump client's ability to migrate MySQL
20
 
# databases to Drizzle
21
 
# This requires a MySQL database, a running Drizzle validation server
22
 
# with some values hard-coded below (sorry).
23
 
# The grammar is conf/drizzle/drizzledump_migrate.yy
24
 
# The gendata files are conf/drizzle/drizzledump_migrate.zz
25
 
#                       conf/drizzle/drizzledump_migrate_no_blobs.zz
26
 
# This is intended for single-threaded scenarios
27
 
 
28
 
package GenTest::Validator::DrizzledumpMigrate;
29
 
 
30
 
require Exporter;
31
 
@ISA = qw(GenTest GenTest::Validator);
32
 
 
33
 
use constant SERVER1_FILE_NAME  => 0;
34
 
use constant SERVER2_FILE_NAME  => 1;
35
 
 
36
 
use strict;
37
 
 
38
 
use Data::Dumper;
39
 
use GenTest;
40
 
use GenTest::Constants;
41
 
use GenTest::Result;
42
 
use GenTest::Validator;
43
 
 
44
 
sub validate {
45
 
        my ($validator, $executors, $results) = @_;
46
 
        my $fail_count ;
47
 
        my $total_count ;
48
 
        my $query_value = $results->[0]->[0] ;
49
 
        my $mysql_port = '19300';
50
 
        say("$query_value");
51
 
        if ($query_value eq ' SELECT 1')
52
 
        {
53
 
          # do some setup and whatnot
54
 
          
55
 
          # info for MySQL db
56
 
          my $database = 'drizzledump_db' ;
57
 
          my @basedir = $executors->[0]->dbh()->selectrow_array('SELECT @@basedir') ;
58
 
          # little kludge to get the proper basedir if MySQL was started via 
59
 
          #       lib/v1/mysql-test-run.pl --start-and-exit
60
 
          # such a situation sets basedir to the drizzle/tests directory and can
61
 
          # muck up efforts to get to the client directory
62
 
          my @basedir_split = split(/\//, @basedir->[0]) ;
63
 
          if (@basedir_split[-1] eq 'mysql-test')
64
 
          {
65
 
            pop(@basedir_split); 
66
 
            @basedir = join('/',@basedir_split);
67
 
          }
68
 
 
69
 
          # info for Drizzle validation db
70
 
          my $drizzle_port = '9306';
71
 
          my $drizzle_dsn="dbi:drizzle:host=localhost:port=$drizzle_port:user=root:password='':database=test";
72
 
          my $drizzle_dbh = DBI->connect($drizzle_dsn, undef, undef, {PrintError => 0});
73
 
          my @drizzle_basedir = $drizzle_dbh->selectrow_array('SELECT @@basedir');
74
 
          my $drizzledump = @drizzle_basedir->[0].'/client/drizzledump' ;
75
 
          my $drizzle_client = @drizzle_basedir->[0].'/client/drizzle' ;
76
 
          if (rqg_debug())
77
 
          {
78
 
            say ("Cleaning up validation server...");
79
 
          }
80
 
          system("$drizzle_client --host=127.0.0.1 --port=$drizzle_port --user=root -e 'DROP SCHEMA $database'");
81
 
 
82
 
          if (rqg_debug())
83
 
          {
84
 
            say ("Resetting validation server...");
85
 
          }
86
 
          system("$drizzle_client --host=127.0.0.1 --port=$drizzle_port --user=root -e 'CREATE SCHEMA $database'");
87
 
 
88
 
          if (rqg_debug()) 
89
 
          {
90
 
            say("Preparing to migrate MySQL database via drizzledump...");
91
 
          }
92
 
          
93
 
          # call to drizzledump / migrate
94
 
          my $drizzledump_result = system("$drizzledump --compact --host=127.0.0.1 --port=$mysql_port --destination-type=database --destination-host=localhost --destination-port=$drizzle_port --destination-user=root --destination-database=$database --user=root $database ") ;
95
 
          say("$drizzledump --compact --host=127.0.0.1 --port=$mysql_port --destination-type=database --destination-host=localhost --destination-port=$drizzle_port --destination-user=root --destination-database=$database --user=root $database ");
96
 
          say("$drizzledump_result");
97
 
          return STATUS_UNKNOWN_ERROR if $drizzledump_result > 0 ;
98
 
 
99
 
          # dump original + migrated DB's and compare dumpfiles
100
 
          my @files;
101
 
          my @ports = ($mysql_port, $drizzle_port);
102
 
 
103
 
          foreach my $port_id (0..1) 
104
 
          {
105
 
            $files[$port_id] = tmpdir()."/translog_rpl_dump_".$$."_".$ports[$port_id].".sql";
106
 
            say("$files[$port_id]");
107
 
            my $drizzledump_result = system("$drizzledump --compact --skip-extended-insert --host=127.0.0.1 --port=$ports[$port_id] --user=root $database >$files[$port_id]");
108
 
            # disable pipe to 'sort' from drizzledump call above
109
 
            #| sort > $files[$port_id]");
110
 
            return STATUS_UNKNOWN_ERROR if $drizzledump_result > 0;
111
 
          }
112
 
          if (rqg_debug())
113
 
          {
114
 
            say ("Executing diff --unified $files[SERVER1_FILE_NAME] $files[SERVER2_FILE_NAME]");
115
 
          }
116
 
          my $diff_result = system("diff --unified $files[SERVER1_FILE_NAME] $files[SERVER2_FILE_NAME]");
117
 
          $diff_result = $diff_result >> 8;
118
 
         
119
 
 
120
 
          return STATUS_UNKNOWN_ERROR if $diff_result > 1;
121
 
 
122
 
          if ($diff_result == 1) 
123
 
          {
124
 
            say("Differences between the two servers were found after comparing dumpfiles");
125
 
            say("diff command:  diff --unified $files[SERVER1_FILE_NAME] $files[SERVER2_FILE_NAME]");
126
 
            say("Master dumpfile:  $files[SERVER1_FILE_NAME]");
127
 
            say("Slave dumpfile:   $files[SERVER2_FILE_NAME]");
128
 
            return STATUS_REPLICATION_FAILURE;
129
 
          } 
130
 
          else 
131
 
          {
132
 
            #foreach my $file (@files) 
133
 
            #{
134
 
            #  unlink($file);
135
 
            #}
136
 
            return STATUS_OK;
137
 
          }        
138
 
 
139
 
  }
140
 
 
141
 
return STATUS_OK ;
142
 
}
143
 
 
144
 
 
145
 
1;