List:Commits« Previous MessageNext Message »
From:Jorgen Loland Date:August 26 2009 12:36pm
Subject:bzr commit into mysql-6.0-backup branch (jorgen.loland:2863) WL#4769
View as plain text  
#At file:///localhome/jl208045/mysql/mysql-6.0-backup-review1/ based on revid:hema@stripped

 2863 Jorgen Loland	2009-08-26
      WL#4769 - Backup: Test validity point without micro-managing sync points
            
      In backup terminology, the validity point (VP) is the transaction consistent
      point in the transaction history where the backed up data is captured. All
      transactions committed before the VP should be fully reflected after restore.
      Further, nothing from transactions that are uncommitted at VP time should be
      reflected after restore.
     @ mysql-test/suite/backup_extra/r/flightstat_stress_delete.result
        Stress test result file
     @ mysql-test/suite/backup_extra/r/flightstat_stress_insert.result
        Stress test result file
     @ mysql-test/suite/backup_extra/r/flightstat_stress_update.result
        Stress test result file
     @ mysql-test/suite/backup_extra/r/start_masterslave.result
        Test file to start two mysql servers
     @ mysql-test/suite/backup_extra/run_flightstat_stress.txt
        Stress test file
     @ mysql-test/suite/backup_extra/stress_basedir
        Base dir for stress test
     @ mysql-test/suite/backup_extra/t/flightstat_stress_delete.test
        Stress test file
     @ mysql-test/suite/backup_extra/t/flightstat_stress_insert.test
        Stress test file
     @ mysql-test/suite/backup_extra/t/flightstat_stress_update.test
        Stress test file
     @ mysql-test/suite/backup_extra/t/start_masterslave.test
        Test file to start two mysql servers
     @ mysql-test/suite/backup_extra/vptest
        Basedir for WL#4769 perl Backup test
     @ mysql-test/suite/backup_extra/vptest/flightstats_alter.sql
        Modify the default flightstats database schema before using it for backup validity point testing.
     @ mysql-test/suite/backup_extra/vptest/run_vp_test.pl
        WL#4769 Backup perl test script
     @ mysql-test/suite/backup_extra/vptest/tmp
        Location to store temporary files for WL#4769 test.

    added:
      mysql-test/suite/backup_extra/r/flightstat_stress_delete.result
      mysql-test/suite/backup_extra/r/flightstat_stress_insert.result
      mysql-test/suite/backup_extra/r/flightstat_stress_update.result
      mysql-test/suite/backup_extra/r/start_masterslave.result
      mysql-test/suite/backup_extra/run_flightstat_stress.txt
      mysql-test/suite/backup_extra/stress_basedir/
      mysql-test/suite/backup_extra/t/flightstat_stress_delete.test
      mysql-test/suite/backup_extra/t/flightstat_stress_insert.test
      mysql-test/suite/backup_extra/t/flightstat_stress_update.test
      mysql-test/suite/backup_extra/t/start_masterslave.test
      mysql-test/suite/backup_extra/vptest/
      mysql-test/suite/backup_extra/vptest/flightstats_alter.sql
      mysql-test/suite/backup_extra/vptest/run_vp_test.pl
      mysql-test/suite/backup_extra/vptest/tmp/
=== added file 'mysql-test/suite/backup_extra/r/flightstat_stress_delete.result'
--- a/mysql-test/suite/backup_extra/r/flightstat_stress_delete.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup_extra/r/flightstat_stress_delete.result	2009-08-26 12:36:04 +0000
@@ -0,0 +1,14 @@
+USE FlightStats_test;
+SET @tmp_num=int_rand(18524);
+START TRANSACTION;
+SET @tmp_num=@tmp_num+1;
+DELETE FROM ontime_1week WHERE id=@tmp_num;
+SET @tmp_num=@tmp_num+1;
+DELETE FROM ontime_1week WHERE id=@tmp_num;
+SET @tmp_num=@tmp_num+1;
+DELETE FROM ontime_1week WHERE id=@tmp_num;
+SET @tmp_num=@tmp_num+1;
+DELETE FROM ontime_1week WHERE id=@tmp_num;
+SET @tmp_num=@tmp_num+1;
+DELETE FROM ontime_1week WHERE id=@tmp_num;
+COMMIT;

=== added file 'mysql-test/suite/backup_extra/r/flightstat_stress_insert.result'
--- a/mysql-test/suite/backup_extra/r/flightstat_stress_insert.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup_extra/r/flightstat_stress_insert.result	2009-08-26 12:36:04 +0000
@@ -0,0 +1,64 @@
+USE FlightStats_test;
+SET @tmp_num=int_rand(6279-5)+148000;
+START TRANSACTION;
+SET @tmp_num=@tmp_num+1;
+INSERT INTO ontime_all (
+id, carrier, origin, destination, flight_num, flight_time,
+tail_num, dep_time, arr_time, dep_delay, arr_delay,
+taxi_out, taxi_in, distance, cancelled, diverted
+) 
+SELECT 
+id, '--', origin, destination, flight_num, flight_time,
+tail_num, dep_time, arr_time, dep_delay, arr_delay,
+taxi_out, taxi_in, distance, cancelled, diverted
+FROM ontime_1week 
+WHERE id = @tmp_num;
+SET @tmp_num=@tmp_num+1;
+INSERT INTO ontime_all (
+id, carrier, origin, destination, flight_num, flight_time,
+tail_num, dep_time, arr_time, dep_delay, arr_delay,
+taxi_out, taxi_in, distance, cancelled, diverted
+) 
+SELECT 
+id, '--', origin, destination, flight_num, flight_time,
+tail_num, dep_time, arr_time, dep_delay, arr_delay,
+taxi_out, taxi_in, distance, cancelled, diverted
+FROM ontime_1week 
+WHERE id = @tmp_num;
+SET @tmp_num=@tmp_num+1;
+INSERT INTO ontime_all (
+id, carrier, origin, destination, flight_num, flight_time,
+tail_num, dep_time, arr_time, dep_delay, arr_delay,
+taxi_out, taxi_in, distance, cancelled, diverted
+) 
+SELECT 
+id, '--', origin, destination, flight_num, flight_time,
+tail_num, dep_time, arr_time, dep_delay, arr_delay,
+taxi_out, taxi_in, distance, cancelled, diverted
+FROM ontime_1week 
+WHERE id = @tmp_num;
+SET @tmp_num=@tmp_num+1;
+INSERT INTO ontime_all (
+id, carrier, origin, destination, flight_num, flight_time,
+tail_num, dep_time, arr_time, dep_delay, arr_delay,
+taxi_out, taxi_in, distance, cancelled, diverted
+) 
+SELECT 
+id, '--', origin, destination, flight_num, flight_time,
+tail_num, dep_time, arr_time, dep_delay, arr_delay,
+taxi_out, taxi_in, distance, cancelled, diverted
+FROM ontime_1week 
+WHERE id = @tmp_num;
+SET @tmp_num=@tmp_num+1;
+INSERT INTO ontime_all (
+id, carrier, origin, destination, flight_num, flight_time,
+tail_num, dep_time, arr_time, dep_delay, arr_delay,
+taxi_out, taxi_in, distance, cancelled, diverted
+) 
+SELECT 
+id, '--', origin, destination, flight_num, flight_time,
+tail_num, dep_time, arr_time, dep_delay, arr_delay,
+taxi_out, taxi_in, distance, cancelled, diverted
+FROM ontime_1week 
+WHERE id = @tmp_num;
+COMMIT;

=== added file 'mysql-test/suite/backup_extra/r/flightstat_stress_update.result'
--- a/mysql-test/suite/backup_extra/r/flightstat_stress_update.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup_extra/r/flightstat_stress_update.result	2009-08-26 12:36:04 +0000
@@ -0,0 +1,24 @@
+use FlightStats_test;
+SET @tmp_num=int_rand(6279-5)+148000;
+START TRANSACTION;
+SET @tmp=@tmp_num+1;
+UPDATE ontime_all  
+SET distance=distance+1 
+WHERE id=@tmp;
+SET @tmp=@tmp_num+1;
+UPDATE ontime_all  
+SET distance=distance+1 
+WHERE id=@tmp;
+SET @tmp=@tmp_num+1;
+UPDATE ontime_all  
+SET distance=distance+1 
+WHERE id=@tmp;
+SET @tmp=@tmp_num+1;
+UPDATE ontime_all  
+SET distance=distance+1 
+WHERE id=@tmp;
+SET @tmp=@tmp_num+1;
+UPDATE ontime_all  
+SET distance=distance+1 
+WHERE id=@tmp;
+COMMIT;

=== added file 'mysql-test/suite/backup_extra/r/start_masterslave.result'
--- a/mysql-test/suite/backup_extra/r/start_masterslave.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup_extra/r/start_masterslave.result	2009-08-26 12:36:04 +0000
@@ -0,0 +1,6 @@
+stop slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+reset master;
+reset slave;
+drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
+start slave;

=== added file 'mysql-test/suite/backup_extra/run_flightstat_stress.txt'
--- a/mysql-test/suite/backup_extra/run_flightstat_stress.txt	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup_extra/run_flightstat_stress.txt	2009-08-26 12:36:04 +0000
@@ -0,0 +1,3 @@
+flightstat_stress_insert
+flightstat_stress_update
+flightstat_stress_delete

=== added directory 'mysql-test/suite/backup_extra/stress_basedir'
=== added file 'mysql-test/suite/backup_extra/t/flightstat_stress_delete.test'
--- a/mysql-test/suite/backup_extra/t/flightstat_stress_delete.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup_extra/t/flightstat_stress_delete.test	2009-08-26 12:36:04 +0000
@@ -0,0 +1,29 @@
+USE FlightStats_test;
+
+# Number of deletes performed in this transaction
+let $total_it=5;
+
+# Assume that ontime_1week has been loaded. It contains records with
+# id values in an unbroken series between 1 and 18524. The stress test
+# will not run for longer than a couple of minutes, and the
+# transactions executed by mysql_stress_test using test file
+# run_flightstats_test.txt do not have time to delete more than ~100
+# records in this time. Hence, the delete transactions will not try to
+# delete a significant amount of non-existing records (delete of
+# non-existing record is a very cheap operation)
+
+--eval SET @tmp_num=int_rand(18524-$total_it)
+
+START TRANSACTION;
+
+LET $it=0;
+WHILE (`SELECT $it < $total_it `)
+{
+  INC $it;        
+  SET @tmp_num=@tmp_num+1;
+
+  DELETE FROM ontime_1week WHERE id=@tmp_num;
+}
+
+COMMIT;
+

=== added file 'mysql-test/suite/backup_extra/t/flightstat_stress_insert.test'
--- a/mysql-test/suite/backup_extra/t/flightstat_stress_insert.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup_extra/t/flightstat_stress_insert.test	2009-08-26 12:36:04 +0000
@@ -0,0 +1,35 @@
+# This test inserts rows into ontime_all by selecting values from
+# ontime_1week
+
+USE FlightStats_test;
+
+LET $total_it=5;
+
+# Assume that ontime_1week has been loaded. It contains records with
+# id values in an unbroken series between 148000 and 154279 (6279
+# records). 
+--eval SET @tmp_num=int_rand(6279-$total_it)+148000
+
+START TRANSACTION;
+
+LET $it=0;
+WHILE (`SELECT $it < $total_it `)
+{
+  INC $it;        
+  SET @tmp_num=@tmp_num+1;
+      
+  INSERT INTO ontime_all (
+      id, carrier, origin, destination, flight_num, flight_time,
+      tail_num, dep_time, arr_time, dep_delay, arr_delay,
+      taxi_out, taxi_in, distance, cancelled, diverted
+    ) 
+    SELECT 
+      id, '--', origin, destination, flight_num, flight_time,
+      tail_num, dep_time, arr_time, dep_delay, arr_delay,
+      taxi_out, taxi_in, distance, cancelled, diverted
+    FROM ontime_1week 
+    WHERE id = @tmp_num;
+}
+
+COMMIT;
+

=== added file 'mysql-test/suite/backup_extra/t/flightstat_stress_update.test'
--- a/mysql-test/suite/backup_extra/t/flightstat_stress_update.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup_extra/t/flightstat_stress_update.test	2009-08-26 12:36:04 +0000
@@ -0,0 +1,26 @@
+# This test inserts rows into ontime_all by selecting values from
+# ontime_1week
+
+USE FlightStats_test;
+
+LET $total_it=5;
+
+# Assume that ontime_1week has been loaded. It contains records with
+# id values in an unbroken series between 148000 and 154279 (6279
+# records). 
+--eval SET @tmp_num=int_rand(6279-$total_it)+148000
+
+START TRANSACTION;
+
+LET $it=0;
+WHILE (`SELECT $it < $total_it `)
+{
+  INC $it;        
+  SET @tmp_num=@tmp_num+1;
+
+  UPDATE ontime_all  
+    SET distance=distance+1 
+    WHERE id=@tmp_num;
+}
+
+COMMIT;
\ No newline at end of file

=== added file 'mysql-test/suite/backup_extra/t/start_masterslave.test'
--- a/mysql-test/suite/backup_extra/t/start_masterslave.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup_extra/t/start_masterslave.test	2009-08-26 12:36:04 +0000
@@ -0,0 +1,21 @@
+--source include/have_innodb.inc
+source include/master-slave.inc;
+# --disable_warnings
+# drop database if exists mysqltest;
+# --enable_warnings
+# # create database mysqltest;
+
+# create table mysqltest.t1 ( n int);
+# alter table mysqltest.t1 add m int;
+# insert into mysqltest.t1 values (1,2);
+# create table mysqltest.t2 (n int);
+# insert into mysqltest.t2 values (45);
+# rename table mysqltest.t2 to mysqltest.t3, mysqltest.t1 to mysqltest.t2;
+# sync_slave_with_master;
+# select * from mysqltest.t2;
+# select * from mysqltest.t3;
+# connection master;
+# drop database mysqltest;
+# sync_slave_with_master;
+
+# # End of 4.1 tests

=== added directory 'mysql-test/suite/backup_extra/vptest'
=== added file 'mysql-test/suite/backup_extra/vptest/flightstats_alter.sql'
--- a/mysql-test/suite/backup_extra/vptest/flightstats_alter.sql	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup_extra/vptest/flightstats_alter.sql	2009-08-26 12:36:04 +0000
@@ -0,0 +1,12 @@
+use FlightStats_test;
+
+CREATE TABLE `ontime_1week` LIKE `ontime_all`;
+
+DELIMITER //
+CREATE FUNCTION FlightStats_test.int_rand(num INT) RETURNS INT
+BEGIN
+   RETURN ROUND(num * RAND() + 0.5);
+END //
+DELIMITER ;
+ 
+

=== added file 'mysql-test/suite/backup_extra/vptest/run_vp_test.pl'
--- a/mysql-test/suite/backup_extra/vptest/run_vp_test.pl	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup_extra/vptest/run_vp_test.pl	2009-08-26 12:36:04 +0000
@@ -0,0 +1,565 @@
+#!/usr/bin/perl 
+
+use Getopt::Long;
+use POSIX;
+use Cwd qw ( cwd abs_path );
+use File::Basename;
+use File::Copy;
+use File::Path;
+use File::Spec;
+
+
+my $mtr_build_thread_def=74;
+my $mtr_build_thread_option; # May be set by CL option
+my $start_dir = cwd();
+my $ext=".exe" if windows();
+
+my $stress_duration = 2000; # But is killed once backup is done
+my $stress_threads = 2;     # Threads used in mysql-stress-test.pl
+my $stress_pid = 0;         # Used when killing mysql-stress-test.pl 
+
+my $datadump_dir = "";
+my $schema_file = "";
+my $mysql_dir = "../";      # May be changed by CL option
+my $client_dir;
+
+my $server_host = "127.0.0.1";
+my $server_port = 0;        # Port the main MySQL server listens to
+my $slave_port = 0;         # Port the server that replays binlog listens to
+
+# Binlog position of the backup image
+my $backup_binlog_file = "";
+my $backup_binlog_pos = 0;
+
+# Store command line options
+my $opt_result = GetOptions(
+        'mysql-dir=s' => \$mysql_dir,
+        'datadump-dir=s' => \$datadump_dir,
+        'schema-file=s' => \$schema_file,
+        'stress-threads=s' => \$stress_threads,
+        'mtr-build-thread=s' => \$mtr_build_thread_option,
+);
+
+# Expand all paths to absolute path
+$datadump_dir= abs_path($datadump_dir)."/";
+$mysql_dir= abs_path($mysql_dir)."/";
+$start_dir= abs_path($start_dir)."/";
+
+if (!$opt_result) {
+    print_usage("");
+    exit(1);
+}
+
+check_options();
+
+my $test_dir=$mysql_dir."/mysql-test/";
+my $master_dir=$test_dir."var/mysqld.1/";
+my $slave_dir=$test_dir."var/mysqld.2/";
+
+my $stress_suitedir=$test_dir."suite/backup_extra/";
+my $test_files_dir=$stress_suitedir;
+my $stress_basedir=$stress_suitedir."stress_basedir";
+my $stress_tests_file = $stress_suitedir."run_flightstat_stress.txt";
+my $tmpfile_dir=$stress_suitedir."vptest/tmp/";
+my $alter_file=$stress_suitedir."vptest/flightstats_alter.sql";
+
+my $backup_file="flight.bak";
+my $dump_file_orig=$tmpfile_dir."dump_orig_db.sql";
+my $dump_file_restore=$tmpfile_dir."dump_restored_db.sql";
+my $diff_file=$tmpfile_dir."dump.diff";
+my $sql_outfile=$tmpfile_dir."sql_out.diff";
+
+# Make sure version 2 of MTR is used
+$ENV{MTR_VERSION} = 2;
+# Setting the MTR_BUILD_THREAD env variable. 
+if ($mtr_build_thread_option) {
+    $ENV{MTR_BUILD_THREAD} = $mtr_build_thread_option;
+} elsif (!$ENV{MTR_BUILD_THREAD}) {
+    $ENV{MTR_BUILD_THREAD} = $mtr_build_thread_def;
+}
+
+$server_port=10*$ENV{MTR_BUILD_THREAD}+10000;
+$slave_port=$server_port+1;
+
+my $dbh;
+
+# ***********
+# Main script
+# ***********
+
+# ---------------------------
+# SCRIPT PART I: Preparations
+# ---------------------------
+
+# Remove old contents in dump directories
+rmtree(glob("$tmpfile_dir"), {keep_root => 1});
+rmtree(glob("$stress_basedir"), {keep_root => 1});
+
+
+# Start two server instances. 
+# * Main server listens to port $server_port
+# * Slave server listens to port $slave_port 
+# Note that replication is not started, but the servers are ready to
+# go to replication mode (e.g., binlogging is enabled on main server)
+start_server("");
+
+# Create a database on the main server
+create_database();
+
+# ---------------------------------------------------------------------
+# SCRIPT PART II: Backup database on main server during concurrent load 
+# ---------------------------------------------------------------------
+
+# Start load on main server
+start_stress_thread();
+
+# Backup database content on main server
+sleep(30);
+backup();
+# Make sure some transactions that will be gone after RESTORE execute 
+sleep(10); 
+
+stop_stress_thread();
+
+# ----------------------------------------------
+# SCRIPT PART III: Replay binlog on slave server
+# ----------------------------------------------
+
+# Get binlog info from main server
+get_binlog_info();
+# Redo binlog on the slave server
+redo_binlog_to_db_copy();
+
+# -------------------------------------------------------
+# SCRIPT PART IV: Compare images on main and slave server
+# -------------------------------------------------------
+
+# Make sure that AUTO_INC in both db versions are equal. Otherwise
+# diff of the dump files will fail
+set_autoincrement($slave_port, 100000);
+# Database on slave server can be dumped - binlog has been replayed
+dump_database($slave_port, $dump_file_orig);
+
+# Drop existing database on main server and dump the restored database
+restore();
+# Make sure that AUTO_INC in both db versions are equal. Otherwise
+# diff of the dump files will fail
+set_autoincrement($server_port, 100000);
+dump_database($server_port, $dump_file_restore);
+
+# Check that the two database dumps are equal
+diff_dumps();
+
+cleanup();
+
+print ("####################################\n");
+print ("#  TEST COMPLETED SUCCESSFULLY     #\n");
+print ("####################################\n");
+
+exit(0);
+
+# ***********
+# Subroutines
+# ***********
+
+sub print_usage {
+
+    my ($message) =@_;
+    print($message);
+    print("Usage:\n");
+    print("  perl run_test.pl --datadump-dir=PATH [OPTIONS]\n");
+    print("Options:\n");
+    print("  mtr-build-thread=INT (default: Value of env variable MTR_BUILD_THREAD, \n".
+          "                        74 if env variable has not been set)\n");
+    print("  mysql-dir=PATH       (default: '../')\n");
+    print("  schema-file=FILE     (default: DATADUMP_DIR/flightstats_schema.sql)\n");
+    print("  stress-threads=INT   (default: 2)\n");
+    print("Example:\n");
+    print("  perl run_test.pl --datadump-dir=/mysql/flightstat/datadump/\n");
+    print("  perl run_test.pl --datadump-dir=/mysql/flightstat/datadump/ \\ \n".
+          "                   --mysql-dir=/mysql/mysql-5.4 \\ \n".
+          "                   --mtr-build-thread=50 \\ \n".
+          "                   --schema-file=/mysql/my_schema.sql \\ \n".
+          "                   --stress-threads=20\n");
+}
+
+sub cleanup {
+
+    shutdown_server();
+}
+
+sub diff_dumps {
+    $ret_code= system("diff $dump_file_orig $dump_file_restore >$diff_file");
+    if ($ret_code >> 8) {
+
+        print ("####################################\n");
+        print ("# The two dump files are NOT equal  \n");
+        print ("# Writing diff to dump.diff         \n");
+        print ("####################################\n");
+
+        cleanup();
+        exit(1);
+    }
+}
+
+sub restore {
+    chdir $test_dir;
+    
+    print ("Restoring database...");
+
+    execute_sql($server_port, "DROP DATABASE FlightStats_test");
+    execute_sql($server_port, "RESTORE FROM \'".$backup_file."\'");
+    print ("done\n");
+}
+
+sub dump_database {
+    my ($port,$dumpfile) =@_;
+
+    print ("mysqldump from server on port ".$port." to file ".$dumpfile."...");
+
+    unlink($dumpfile);
+
+    my $dump_args= "--user=root --port=".$port." --protocol=tcp --compact ".
+        "--order-by-primary --skip-extended-insert FlightStats_test > "
+        .$dumpfile;
+
+    $ret_code=system($client_dir."/mysqldump ".$dump_args);
+    if ($ret_code >> 8) { 
+        print("\n Failed to dump database - Aborting\n");
+        cleanup();
+        exit(1);
+    }
+    print ("done\n");
+}
+
+sub redo_binlog_to_db_copy {
+
+    print ("Playing forward binlog to copy of original database...");
+
+    my $cmd = 'CHANGE MASTER TO MASTER_PORT='.$server_port.
+              ', MASTER_USER=\'root\', MASTER_HOST=\''.$server_host.'\'';
+    execute_sql($slave_port, $cmd);
+
+    $cmd ="START SLAVE UNTIL MASTER_LOG_FILE=\'".$backup_binlog_file.
+          "\', MASTER_LOG_POS=".$backup_binlog_pos;
+
+    execute_sql($slave_port, $cmd);
+
+    # Wait until slave has reached requested binlog position
+    $cmd ="select MASTER_POS_WAIT(\'".$backup_binlog_file.
+          "\', \'".$backup_binlog_pos."\')";
+    execute_sql($slave_port, $cmd);
+
+    execute_sql($slave_port, "STOP SLAVE");
+
+    # execute_sql($slave_port, "SHOW SLAVE STATUS");
+    # execute_sql($slave_port, "SELECT COUNT(*) FROM FlightStats_test.aircraft");
+    sleep(5);
+    print("done\n");
+}
+
+sub get_binlog_info {
+
+    print ("Getting binlog info...");
+    my $binlog_info = execute_sql($server_port,
+                                  "SELECT binlog_start_pos, binlog_file ".
+                                  "FROM mysql.backup_history LIMIT 1");
+
+    @tokens = split("\t",$binlog_info);
+
+    ($backup_binlog_pos,$backup_binlog_file)=@tokens;
+
+    $backup_binlog_file =rtrim($backup_binlog_file);
+
+    print ("done\n");
+}
+
+# Right trim function to remove trailing whitespace
+sub rtrim($)
+{
+	my $string = shift;
+	$string =~ s/\s+$//;
+	return $string;
+}
+
+sub backup {
+    chdir $test_dir;
+    
+    print ("Backing up database...");
+
+    unlink ($backup_file); #Remove file if already exists
+    execute_sql($server_port,"PURGE BACKUP LOGS");
+
+    my $time_before=time();
+    execute_sql($server_port,
+                "BACKUP DATABASE FlightStats_test TO \'".$backup_file."\'");
+    my $time_after=time();
+    my $difference=$time_after-$time_before;
+    print ("BACKUP took: ".$difference." sec...");
+    print ("done\n");
+}
+
+
+sub stop_stress_thread {
+    # Wait for stress test to complete
+    print("Stopping stress test...");
+
+    # TODO: Replace with kill(SIGNAL, PID) 
+    #   Problem: kill(x, $stress_pid) only kills one thread (x=1 or 9 or 15)
+    # system ("kill $stress_pid"); #only kills one of the stress test threads
+    system("killall mysql-stress-test.pl"); # works
+    #Wait until PID of mysql_stress_test no longer exists
+    waitpid($stress_pid, 0); 
+    print ("done\n");
+}
+
+sub start_stress_thread {
+
+    my $pid = fork();
+    if ($pid == 0) {
+        # This is the stress test thread
+        run_stress();
+        exit(0);
+    } else {
+        # This is the main thread
+        $stress_pid= $pid;
+        # Make sure the stress test has started
+        sleep(10);
+    }
+    return 0;
+}
+
+sub run_stress {
+    chdir $test_dir;
+
+    print("STARTING STRESS TEST\n");
+    my $stress_param ="--stress-basedir=$stress_basedir ".
+        "--stress-suite-basedir=$stress_suitedir/ ".
+        "--server-logs-dir=$stress_basedir ".
+        "--stress-tests-file=$stress_tests_file --server-user=root ".
+        "--server-port=$server_port --server-host=$server_host ".
+        "--mysqltest=$client_dir/mysqltest --test-duration=$stress_duration ".
+        "--threads=$stress_threads > $stress_basedir/run.out 2>&1";
+
+    ## If exec is replaced with system, kill must be changed because stress_pid is wrong
+    exec("./mysql-stress-test.pl ".$stress_param); 
+    print("STRESS TEST DONE\n"); # Not printed because 'exec' never returns
+
+}    
+
+sub create_slave_copy {
+    shutdown_server();
+
+    # Copy database
+    print("Delete existing slave data files\n");    
+    # Equivalent to 'rm -r'
+    rmtree(glob("$slave_dir/"),  {keep_root => 1});
+    print("Copying database to slave location\n");    
+    dircopy($master_dir, $slave_dir);
+
+    start_server("--start-dirty");
+    return 0;
+}
+
+sub shutdown_server {
+    print("Shutdown server\n");
+    $mysql_args="--user=root --protocol=tcp --port=".$server_port;
+    system($client_dir."/mysqladmin ".$mysql_args." shutdown");
+
+    $mysql_args="--user=root --protocol=tcp --port=".$slave_port;
+    system($client_dir."/mysqladmin ".$mysql_args." shutdown");
+
+    sleep(10);
+    return 0;
+}
+
+sub dircopy {
+    my ($from, $to) =@_;
+    opendir my($handle), $from or die "Could not open dir '$from': $!";
+    for my $file (readdir $handle) {
+        next if ($file eq '.') or ($file eq '..');
+        my $source = "$from/$file";
+        my $destination = "$to/$file";
+        if (-d $source) {
+            mkdir $destination or die "mkdir '$destination' failed: $!";
+            dircopy($source, $destination);
+        } else {
+            copy($source, $destination) or die $!;
+        }
+    }
+    closedir $handle;
+    return 0;
+}
+
+
+sub create_database {
+
+    # Creating flightstats_test dabase and insert data
+    # ------------------------------------------------
+    $mysql_args="--user=root --protocol=tcp --port=".$server_port;
+
+    print("Creating database...");
+
+    execute_sql($server_port, "DROP DATABASE IF EXISTS FlightStats_test");
+    execute_sql($server_port, "CREATE DATABASE FlightStats_test");
+    
+    $ret_code=system($client_dir."/mysql ".$mysql_args." < ".$schema_file);
+    if ($ret_code >> 8) { 
+        print("\n Failed to create database - Aborting\n");
+        cleanup();
+        exit(1);
+    }
+
+    $ret_code=system($client_dir."/mysql ".$mysql_args." < ".$alter_file);
+    if ($ret_code >> 8) { 
+        print("\n Failed to alter database - Aborting\n");
+        cleanup();
+        exit(1);
+    }
+    print("done\n");
+
+    # Load data from dump files
+    # -------------------------
+
+    my $pre_sql="load data infile '".$datadump_dir;
+    my $post_sql=" fields terminated by '\\t' lines terminated by '\\n';\n";
+
+    my $sql=$sql."use FlightStats_test;\n";
+    $sql=$sql.$pre_sql."aircraft.dat' into table aircraft".$post_sql;
+    $sql=$sql.$pre_sql."aircraft_engine_types.dat' ".
+        "into table aircraft_engine_types".$post_sql;
+    $sql=$sql.$pre_sql."aircraft_engines.dat' into table aircraft_engines".
+        $post_sql;
+    $sql=$sql.$pre_sql."aircraft_models.dat' into table aircraft_models".
+        $post_sql;
+    $sql=$sql.$pre_sql."aircraft_types.dat' into table aircraft_types".
+        $post_sql;
+    $sql=$sql.$pre_sql."airport_remarks.dat' into table airport_remarks".
+        $post_sql;
+    $sql=$sql.$pre_sql."airports.dat' into table airports".$post_sql;
+    $sql=$sql.$pre_sql."carriers.dat' into table carriers".$post_sql;
+    $sql=$sql.$pre_sql."exceptions.dat' into table exceptions".$post_sql;
+    $sql=$sql.$pre_sql."states.dat' into table states".$post_sql;
+    $sql=$sql.$pre_sql."zipcodes.dat' into table zipcodes".$post_sql;
+    $sql=$sql.$pre_sql."ontime_1week.dat' into table ontime_1week".$post_sql;
+    # ontime_1day can be used if fewer records are wanted
+    # $sql=$sql.$pre_sql."ontime_1day.dat' into table ontime_1week".$post_sql;
+
+    print("Loading data...");
+    execute_sql($server_port,$sql);
+    print("done\n");
+
+    return 0;
+}
+
+sub execute_sql {
+    my($port,$sql) =@_;
+
+    my $do_sql = "END_OF_SQL\n".$sql."\nEND_OF_SQL\n";
+    $mysql_args="--user=root --protocol=tcp --port=".$port;
+    my $command = $client_dir."/mysql ".$mysql_args.
+        " << ".$do_sql;
+
+    open(OUT, $command."|") or die "Failed to open pipe";
+    my $output;
+    while (<OUT>) {
+        $output = <OUT>."\n";
+    }
+    close(OUT);
+
+    ## Print SQL and it's output to file so you can see what happens 
+    open FILE, ">>".$sql_outfile;
+    print FILE $command."\n";
+    print FILE $output."\n";
+    close FILE;
+    
+    return $output;
+}
+
+sub start_server {
+    chdir($test_dir);
+
+    # setting the command line arguments for mysql-test-run.pl
+    my ($arg)=@_;
+    print("Starting server with additional argument: ".$arg."\n");
+
+    my $mysql_args="--start --mysqld=--secure-file-priv= ".
+                   "--mysqld=--innodb --mysqld=--log-output=file ".
+                   "--mysqld=--default-storage-engine=innodb ".
+                   "--mysqld=--mysql-backup ".
+                   $arg." start_masterslave --suite=backup_extra";
+
+    my $server_start_script = File::Spec->catfile( abs_path( $mysql_dir ), 
+                                                   'mysql-test', 
+                                                   'mysql-test-run.pl' );
+
+    my $pid = fork();
+    if ($pid == 0) {
+        # This is the thread that starts the servers;
+        # start_masterslave starts both servers
+        chdir($test_dir);
+        $ret_code=system("perl $server_start_script ".$mysql_args);
+        exit(0);
+    } else {
+        # This is the main thread
+        # Wait until the servers have started
+        sleep(10);
+    }
+
+    # Let main thread check that the servers started without error
+    if ($ret_code >> 8) { 
+        print("\n Failed to start the Server - Aborting\n");
+        cleanup();
+        exit(1);
+    }
+}
+
+sub check_options {
+    # Check if value of base_dir and mysql_dir are valid
+    if (-e $mysql_dir."/bin/mysql".$ext) {
+        $client_dir = $mysql_dir."/bin";
+    } elsif (-e $mysql_dir."/client/mysql".$ext) {
+        $client_dir = $mysql_dir."/client";
+    } else { 
+        print_usage("Could not find MySQL in: \'".$mysql_dir."\'\n");
+        exit(1);
+    }
+
+    if (! -e $datadump_dir."/aircraft.dat") {
+        print_usage("Could not find test data in: \'".$datadump_dir."\'\n");
+        exit(1);
+    }
+
+    if (!$schema_file) {
+        if (! -e $datadump_dir."/flightstats_schema.sql") {    
+            print_usage("Could not find schema file \'".$datadump_dir.
+                        "/flightstats_schema.sql\'\n".
+                        "Copy the file to this location or specify schema ".
+                        "file using --schema-file\n");
+            exit(1);
+        } else {
+            $schema_file=$datadump_dir."/flightstats_schema.sql";
+        }
+    } elsif (! -e $schema_file) {
+        print_usage("Could not find schema file \'".$schema_file."\'\n");
+        exit(1);
+    }
+
+    if (! -e $datadump_dir."/aircraft.dat") {
+        print_usage("Could not find test data in: \'".$datadump_dir."\'\n");
+        exit(1);
+    }
+}
+
+sub set_autoincrement {
+    my ($port,$autoinc_value)=@_;
+    execute_sql($port, "ALTER TABLE FlightStats_test.ontime_all ".
+                       "AUTO_INCREMENT=".$autoinc_value);
+}
+
+sub windows {
+   if ( ($^O eq 'MSWin32') || 
+        ($^O eq 'MSWin64') ||
+        ($^O eq 'cygwin' )
+      ) { return 1; } else { return 0; }
+}

=== added directory 'mysql-test/suite/backup_extra/vptest/tmp'

Attachment: [text/bzr-bundle] bzr/jorgen.loland@sun.com-20090826123604-087wwgozrd06yp3s.bundle
Thread
bzr commit into mysql-6.0-backup branch (jorgen.loland:2863) WL#4769Jorgen Loland26 Aug
  • Re: bzr commit into mysql-6.0-backup branch (jorgen.loland:2863)WL#4769Rafal Somla7 Sep