3
# This is a test of insert and repair/check.
6
$opt_loop_count=100000; # Change this to make test harder/easier
8
##################### Standard benchmark inits ##############################
16
$opt_skip_create=$opt_skip_in=$opt_verbose=$opt_fast_insert=
17
$opt_lock_tables=$opt_debug=$opt_skip_delete=$opt_fast=$opt_force=0;
18
$opt_host=$opt_user=$opt_password=""; $opt_db="test";
20
GetOptions("host=s","db=s","loop-count=i","skip-create","skip-in",
21
"skip-delete","verbose","fast-insert","lock-tables","debug","fast",
22
"force","user=s","password=s") || die "Aborted";
23
$opt_verbose=$opt_debug=$opt_lock_tables=$opt_fast_insert=$opt_fast=$opt_skip_in=$opt_force=undef; # Ignore warnings from these
25
$firsttable = "bench_f1";
26
$secondtable = "bench_f2";
29
#### Start timeing and start test
32
$start_time=new Benchmark;
33
if (!$opt_skip_create)
35
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
36
$opt_user, $opt_password,
37
{ PrintError => 0}) || die $DBI::errstr;
38
$dbh->do("drop table if exists $firsttable, $secondtable");
40
print "Creating tables $firsttable and $secondtable in database $opt_db\n";
41
$dbh->do("create table $firsttable (id int(7) not null, thread tinyint not null, info varchar(32), marker char(1), primary key(id,thread))") or die $DBI::errstr;
42
$dbh->do("create table $secondtable (id int(7) not null, thread tinyint not null, row int(3) not null,value double, primary key(id,thread,row)) delay_key_write=1") or die $DBI::errstr;
43
$dbh->disconnect; $dbh=0; # Close handler
51
insert_in_bench1() if (($pid=fork()) == 0); $work{$pid}="insert in bench1";
52
insert_in_bench2() if (($pid=fork()) == 0); $work{$pid}="insert in bench2";
53
repair_and_check() if (($pid=fork()) == 0); $work{$pid}="repair/check";
56
while (($pid=wait()) != -1)
59
print "thread '" . $work{$pid} . "' finished with exit code $ret\n";
60
$errors++ if ($ret != 0);
63
if (!$opt_skip_delete && !$errors)
65
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
66
$opt_user, $opt_password,
67
{ PrintError => 0}) || die $DBI::errstr;
68
$dbh->do("drop table $firsttable,$secondtable");
70
print ($errors ? "Test failed\n" :"Test ok\n");
72
$end_time=new Benchmark;
73
print "Total time: " .
74
timestr(timediff($end_time, $start_time),"noc") . "\n";
79
# Insert records in the two tables
84
my ($dbh,$rows,$found,$i);
86
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
87
$opt_user, $opt_password,
88
{ PrintError => 0}) || die $DBI::errstr;
90
for ($i=0 ; $i < $opt_loop_count; $i++)
92
$sth=$dbh->do("insert into $firsttable values ($i,0,'This is entry $i','')") || die "Got error on insert: $DBI::errstr\n";
93
$row_count=($i % 7)+1;
95
for ($j=0 ; $j < $row_count; $j++)
97
$sth=$dbh->do("insert into $secondtable values ($i,0,$j,0)") || die "Got error on insert: $DBI::errstr\n";
100
$dbh->disconnect; $dbh=0;
101
print "insert_in_bench1: Inserted $rows rows\n";
107
my ($dbh,$rows,$found,$i);
109
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
110
$opt_user, $opt_password,
111
{ PrintError => 0}) || die $DBI::errstr;
113
for ($i=0 ; $i < $opt_loop_count; $i++)
115
$sth=$dbh->do("insert into $firsttable values ($i,1,'This is entry $i','')") || die "Got error on insert: $DBI::errstr\n";
116
$row_count=((7-$i) % 7)+1;
118
for ($j=0 ; $j < $row_count; $j++)
120
$sth=$dbh->do("insert into $secondtable values ($i,1,$j,0)") || die "Got error on insert: $DBI::errstr\n";
123
$dbh->disconnect; $dbh=0;
124
print "insert_in_bench2: Inserted $rows rows\n";
131
my ($dbh,$row,@row,$found1,$found2,$last_found1,$last_found2,$i,$type,
133
$found1=$found2=0; $last_found1=$last_found2= -1;
135
$dbh = DBI->connect("DBI:mysql:$opt_db:$opt_host",
136
$opt_user, $opt_password,
137
{ PrintError => 0}) || die $DBI::errstr;
139
for ($i=0; $found1 != $last_found1 && $found2 != $last_found1 ; $i++)
141
$type=($i & 2) ? "repair" : "check";
145
$last_found1=$found1;
150
$last_found2=$found2;
152
$sth=$dbh->prepare("$type table $table") || die "Got error on prepare: $dbh->errstr\n";
153
$sth->execute || die $dbh->errstr;
155
while (($row=$sth->fetchrow_arrayref))
157
if ($row->[3] ne "OK")
159
print "Got error " . $row->[3] . " when doing $type on $table\n";
163
$sth=$dbh->prepare("select count(*) from $table") || die "Got error on prepare: $dbh->errstr\n";
164
$sth->execute || die $dbh->errstr;
165
@row = $sth->fetchrow_array();
177
$dbh->disconnect; $dbh=0;
178
print "check/repair: Did $i repair/checks\n";