#!/user/bin/perl -w #/* Copyright (C) 2000-2005 MySQL AB # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Version 1.1 ####################### Includes ############################ use DBI; ####################### Globals ############################ my $m_host=''; my $m_port=''; my $m_user=''; my $m_pass=''; my $dbhM=''; my $transCounter=0; ####################### Sub Pototypes ############################ sub CollectCommandPromptInfo(); sub ConnectToDatabases(); sub DisconnectFromDatabases(); sub CreateDB_Tbl_Insert(); sub Delete_DropDB(); sub main(); ######################## Program Main ########################### main(); sub main () { CollectCommandPromptInfo(); while(! -e "/tmp/stop.ini") { ConnectToDatabases(); CreateDB_Tbl_Insert(); Delete_DropDB(); DisconnectFromDatabases(); $transCounter++; if ( -e "/tmp/stop.ini"){ print "\n\nStop file stop.ini detected. Exiting program\n"; print "Total Transaction for cid_ndb_dd = $transCounter\n"; } } } ###################### Collect Command Prompt Info ############# sub CollectCommandPromptInfo () { ### Check that user has supplied correct number of command line args die "Usage:\n cid_ndb_dd.pl < master pass>\n All 4 arguments must be passed. Use BLANK for NULL passwords\n" unless @ARGV == 4; $m_host=$ARGV[0]; $m_port=$ARGV[1]; $m_user= $ARGV[2]; $m_pass= $ARGV[3]; if ($m_pass eq "BLANK") { $m_pass = '';} } ###################### Collect Command Prompt Info ############# sub ConnectToDatabases () { ### Connect to both master and slave clusters databases ### Connect to master $dbhM = DBI->connect("dbi:mysql:database=test;host=$m_host;port=$m_port", "$m_user", "$m_pass") or die "Can't connect to Master Cluster MySQL process! Error: $DBI::errstr\n"; } sub DisconnectFromDatabases () { ### Disconnect from master $dbhM->disconnect() or warn " Disconnection failed: $DBI::errstr\n"; } sub CreateDB_Tbl_Insert () { $sth = $dbhM->prepare("CREATE DATABASE TESTER2;") or die "Prepare error: ", $dbhM->errstr; $sth->execute() or die "Create DB Error: ", $sth->errstr; $sth->finish(); $sth = $dbhM->prepare("USE TESTER2;") or die "Prepare error: ", $dbhM->errstr; $sth->execute() or die "Create DB Error: ", $sth->errstr; $sth->finish(); print "Database Created.\n"; #$sth = $dbhM->prepare("CREATE LOGFILE GROUP TESTER2_LOG # ADD UNDOFILE './tester2_log/undofile.dat' # INITIAL_SIZE 150M # UNDO_BUFFER_SIZE = 1M # ENGINE=NDB;") # or die "Prepare CREATE LOGFILE GROUP error: ", $dbhM->errstr; #$sth->execute() # or die "CREATE LOGFILE GROUP error: ", $sth->errstr; #$sth->finish(); #$sth = $dbhM->prepare("ALTER LOGFILE GROUP TESTER2_LOG # ADD UNDOFILE './tester2_log/undofile2.dat' # INITIAL_SIZE 150M # ENGINE=NDB;") # or die "Prepare ALTER LOGFILE GROUP error: ", $dbhM->errstr; #$sth->execute() # or die "ALTER LOGFILE GROUP error: ", $sth->errstr; #$sth->finish(); #print "Log Group Created.\n"; $sth = $dbhM->prepare("CREATE TABLESPACE TESTER2_TS ADD DATAFILE './tester2_ts/datafile.dat' USE LOGFILE GROUP lg1 INITIAL_SIZE 100M ENGINE=NDB;") or die "Prepare CREATE TABLESPACE error: ", $dbhM->errstr; $sth->execute() or die "CREATE TABLESPACE error: ", $sth->errstr; $sth->finish(); print "Table Space Created.\n"; $sth = $dbhM->prepare("CREATE TABLE t1 (c1 INT, c2 CHAR(4), c3 FLOAT, c4 DOUBLE, c5 BIT(4), c6 VARCHAR(100), PRIMARY KEY (c1)) TABLESPACE TESTER2_TS STORAGE DISK ENGINE=NDB;") or die "Prepare error: ", $dbhM->errstr; $sth->execute() or die "Create Table Error: ", $sth->errstr; $sth->finish(); print "Table Created.\n"; $sth = $dbhM->prepare("INSERT INTO t1 VALUES(1,'txt',3.00008,145.00, b'1111','Testing Disk Data'),(2,'txt',3.00008,145.00, b'1111','Testing Disk Data'),(3,'TXT',3.00008,145.00, b'1111','Testing Disk Data'),(223,'TXT',3.00008,145.00, b'1111','Testing Disk Data'),(31,'TXT',3.00008,145.00, b'1111','Testing Disk Data'),(399,'TXT',3.00008,145.00, b'1111','Testing Disk Data'),(301,'TXT',3.00008,145.00, b'1111','Testing Disk Data'),(103,'TXT',3.00008,145.00, b'1111','Testing Disk Data'),(20,'TXT',3.00008,145.00, b'1111','Testing Disk Data');") or die "Prepare error: ", $dbhM->errstr; $sth->execute or die "Insert Error: ", $sth->errstr; $sth->finish; print "Data Inserted Created.\n"; } sub Delete_DropDB () { sleep 20; $sth = $dbhM->prepare("DELETE FROM t1") or die "Prepare delete from error: ", $dbhM->errstr; $sth->execute() or die "Delete Error: ", $sth->errstr; $sth->finish(); print "Data Deleted.\n"; $sth = $dbhM->prepare("DROP TABLE t1") or die "Prepare drop table error: ", $dbhM->errstr; $sth->execute() or die "Drop table error: ", $sth->errstr; $sth->finish(); print "Table Dropped.\n"; $sth = $dbhM->prepare("ALTER TABLESPACE TESTER2_TS DROP DATAFILE './tester2_ts/datafile.dat' ENGINE = NDB;") or die "Prepare drop data file error: ", $dbhM->errstr; $sth->execute() or die "Drop Data file Error: ", $sth->errstr; $sth->finish(); print "Data File Dropped.\n"; $sth = $dbhM->prepare("DROP TABLESPACE TESTER2_TS ENGINE = NDB;") or die "Prepare drop table space error: ", $dbhM->errstr; $sth->execute() or die "Drop table space Error: ", $sth->errstr; $sth->finish(); print "Tables Space Dropped.\n"; #$sth = $dbhM->prepare("DROP LOGFILE GROUP TESTER2_LOG ENGINE =NDB;") # or die "Prepare drop Log Group error: ", $dbhM->errstr; # $sth->execute() # or die "Drop Log Group Error: ", $sth->errstr; # $sth->finish(); # print "Log Group Dropped.\n"; $sth = $dbhM->prepare("DROP DATABASE TESTER2;") or die "Prepare drop error: ", $dbhM->errstr; $sth->execute() or die "drop error: ", $sth->errstr; print "Database Dropped.\n"; }