|
|||||||||||
|
table locking with forking
From: Jeremy Kister <perl-mysql(at)jeremykister.com>
Date: Wed Sep 19 2007 - 00:43:58 EDT
I expect the parent to start, lock the table, and spawn the child. I then expect the child to die without inserting data, because the parent had the table locked longer than the child was allowed to wait. The parent should then say "count: 0" and exit. But instead, the child spawns, waits for the parent to unlock (ignoring the alarm?), and inserts the data. What do I have to do to change the behavior so that the child times out and immediately stops trying to insert the data after a specified time period ? my $dbh = DBI->connect($dsn, $dbun, $dbpw, {RaiseError => 1});
$dbh->do('DELETE FROM table1 WHERE field1 > 1');
$dbh->do('LOCK TABLE table1 READ');
print "PARENT: starting.\n";
print "PARENT: sleeping [$_/5]\n";
sleep 1;
} $dbh->do('UNLOCK TABLES'); print "PARENT: exiting.\n";
my $sql = 'SELECT COUNT(*) FROM table1 WHERE field1 = 5';
my $sth = $dbh->prepare($sql);
}else{
print "CHILD: starting.\n";
eval {
local $SIG{ALRM} = sub { die "timeout."; };
alarm(3);
my $dbh = DBI->connect($dsn, $dbun, $dbpw, {RaiseError => 1});
print "CHILD: db connection succeeded\n";
my $sql = 'INSERT INTO table1 (field1) VALUES (5)';
my $sth = $dbh->prepare($sql);
$sth->execute;
print "CHILD: inserted data.\n";
alarm(0);
}; alarm(0); if($@){
print "CHILD: $@\n";
-- Jeremy Kister http://jeremy.kister.net./ -- MySQL Perl Mailing List For list archives: http://lists.mysql.com/perl To unsubscribe: http://lists.mysql.com/perl?unsub=lists@pantek.comReceived on Wed Sep 19 00:46:30 2007 This archive was generated by hypermail 2.1.8 : Sun Oct 07 2007 - 10:15:35 EDT |
||||||||||
|
|||||||||||