Below is the list of changes that have just been committed into a local
5.0 repository of msvensson. When msvensson does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-11-05 15:10:01+01:00, msvensson@shellback.(none) +4 -0
Rename 'wait' to 'wait_one'
Fix problem with 'wait_one' always returning 1, apparently it's not
possible to return from a function inside an eval.
mysql-test/lib/My/SafeProcess.pm@stripped, 2007-11-05 15:09:41+01:00,
msvensson@shellback.(none) +38 -34
Rename 'wait' to 'wait_one'
Fix problem with 'wait_one' always returning 1, apparently it's not
possible to return from a function inside an eval.
mysql-test/lib/My/SafeProcess/safe_process.pl@stripped, 2007-11-05 15:09:41+01:00,
msvensson@shellback.(none) +0 -4
Remove some old printouts
mysql-test/lib/mtr_process.pl@stripped, 2007-11-05 15:09:40+01:00,
msvensson@shellback.(none) +1 -1
Rename 'wait' to 'wait_one'
mysql-test/lib/t/SafeProcessStress.pl@stripped, 2007-11-05 15:09:41+01:00,
msvensson@shellback.(none) +55 -10
Rename wait -> wait_one
Add tests for My::SafeProcess::shutdown(timeout, <process list>)
diff -Nrup a/mysql-test/lib/My/SafeProcess/safe_process.pl
b/mysql-test/lib/My/SafeProcess/safe_process.pl
--- a/mysql-test/lib/My/SafeProcess/safe_process.pl 2007-10-19 15:07:26 +02:00
+++ b/mysql-test/lib/My/SafeProcess/safe_process.pl 2007-11-05 15:09:41 +01:00
@@ -127,7 +127,6 @@ if ($ret > 0) {
else
{
if ($ret == 0){
- message("magnus: Killed child: $child_pid but it didn't exist");
if (kill(9, -$child_pid)){
message("kill of -$child_pid suceeded");
}
@@ -135,9 +134,6 @@ else
if (kill(9, $child_pid)){
message("kill of $child_pid suceeded");
}
- }
- else {
- message("magnus: Killed child ret: $ret");
}
}
diff -Nrup a/mysql-test/lib/My/SafeProcess.pm b/mysql-test/lib/My/SafeProcess.pm
--- a/mysql-test/lib/My/SafeProcess.pm 2007-11-05 13:53:43 +01:00
+++ b/mysql-test/lib/My/SafeProcess.pm 2007-11-05 15:09:41 +01:00
@@ -192,7 +192,7 @@ sub new {
sub run {
my $proc= new(@_);
- $proc->wait();
+ $proc->wait_one();
return $proc->exit_status();
}
@@ -254,10 +254,11 @@ sub shutdown {
return if (@processes == 0);
+ print "shutdown: @processes\n";
+
# Call shutdown function if process has one, else
# use kill
foreach my $proc (@processes){
- print $proc, "\n";
my $shutdown= $proc->{SAFE_SHUTDOWN};
if ($shutdown_timeout > 0 and defined $shutdown){
print "calling shutdown function\n";
@@ -272,8 +273,9 @@ sub shutdown {
# Wait for shutdown_timeout for processes to exit
foreach my $proc (@processes){
- if ($proc->wait($shutdown_timeout) != 0) {
- print "wait for $proc failed\n";
+ my $ret= $proc->wait_one($shutdown_timeout);
+ if ($ret != 0) {
+ print "wait_one for $proc failed, ret: $ret\n";
push(@kill_processes, $proc);
}
else
@@ -281,7 +283,7 @@ sub shutdown {
print "got shutdown of $proc\n";
}
# Only wait for the first process with shutdown timeout
- $shutdown_timeout= undef;
+ $shutdown_timeout= 0;
}
# Return if all servers has exited
@@ -293,7 +295,7 @@ sub shutdown {
}
foreach my $proc (@kill_processes){
- $proc->wait();
+ $proc->wait_one();
}
return;
}
@@ -305,7 +307,7 @@ sub shutdown {
sub start_kill {
my ($self)= @_;
die "usage: \$safe_proc->start_kill()" unless (@_ == 1 and ref $self);
- print "start_kill $self\n";
+ # print "start_kill $self\n";
if (defined $safe_kill and $self->{SAFE_WINPID}){
# Use my_safe_kill to tell my_safe_process
@@ -332,7 +334,7 @@ sub kill {
die "usage: \$safe_proc->kill()" unless (@_ == 1 and ref $self);
$self->start_kill();
- $self->wait();
+ $self->wait_one();
return 1;
}
@@ -352,13 +354,20 @@ sub _collect {
# Wait for process to exit
# optionally with a timeout
#
+# timeout
+# undef -> wait blocking infinitely
+# 0 -> just poll with WNOHANG
+# >0 -> wait blocking for max timeout seconds
+#
# RETURN VALUES
# 0 Not running
# 1 Still running
#
-sub wait {
+sub wait_one {
my ($self, $timeout)= @_;
- die "usage: \$safe_proc->wait([timeout])" unless ref $self;
+ die "usage: \$safe_proc->wait_one([timeout])" unless ref $self;
+
+ print "wait_one $self, $timeout\n";
if ( ! defined($self->{SAFE_PID}) ) {
# No pid => not running
@@ -371,50 +380,45 @@ sub wait {
}
my $pid= $self->{SAFE_PID};
+ my $blocking= (defined $timeout and $timeout == 0) ? 0 : 1;
my $retpid;
eval
{
# alarm should break the wait
local $SIG{ALRM}= sub { die "waitpid timeout"; };
- my $blocking= (defined $timeout and $timeout == 0) ? 0 : 1;
-
alarm($timeout) if $blocking;
$retpid= waitpid($pid, $blocking ? 0 : &WNOHANG);
alarm(0) if defined $blocking;
-
- if ( $retpid == 0 ) {
- # 0 => still running
- return 1;
- }
-
- if ( not $blocking and $retpid == -1 ) {
- # still running
- return 1;
- }
-
- warn "wait: expected pid $pid but got $retpid"
- unless( $retpid == $pid );
-
- $self->_collect();
- return 0;
-
};
if ($@)
{
die "Got unexpected: $@" if ($@ !~ /waitpid timeout/);
- if (defined $retpid) {
- # Got the pid _and_ alarm
- $self->_collect();
- return 0;
+ if (!defined $retpid) {
+ # Got timeout
+ return 1;
}
+ # Got pid _and_ alarm, continue
+ }
+ if ( $retpid == 0 ) {
+ # 0 => still running
+ return 1;
}
- return 1;
+ if ( not $blocking and $retpid == -1 ) {
+ # still running
+ return 1;
+ }
+
+ warn "wait_one: expected pid $pid but got $retpid"
+ unless( $retpid == $pid );
+
+ $self->_collect();
+ return 0;
}
diff -Nrup a/mysql-test/lib/mtr_process.pl b/mysql-test/lib/mtr_process.pl
--- a/mysql-test/lib/mtr_process.pl 2007-11-05 13:53:43 +01:00
+++ b/mysql-test/lib/mtr_process.pl 2007-11-05 15:09:40 +01:00
@@ -109,7 +109,7 @@ sub sleep_until_file_created ($$$) {
}
# Check if it died after the fork() was successful
- if ( defined $proc and ! $proc->wait(0) )
+ if ( defined $proc and ! $proc->wait_one(0) )
{
mtr_warning("Process $proc died");
return 0;
diff -Nrup a/mysql-test/lib/t/SafeProcessStress.pl b/mysql-test/lib/t/SafeProcessStress.pl
--- a/mysql-test/lib/t/SafeProcessStress.pl 2007-11-05 14:00:06 +01:00
+++ b/mysql-test/lib/t/SafeProcessStress.pl 2007-11-05 15:09:41 +01:00
@@ -11,9 +11,9 @@ use My::SafeProcess;
my $perl_path= $^X;
my $verbose= 0;
-my $loops= 100;
+my $loops= 1000;
-# kill one and wait for one
+print "kill one and wait for one\n";
for (1...$loops){
use File::Temp qw / tempdir /;
my $dir = tempdir( CLEANUP => 1 );
@@ -32,8 +32,7 @@ for (1...$loops){
}
foreach my $proc (@procs) {
- $proc->killit();
- $proc->wait();
+ $proc->kill();
# dummyd will always be kiled and thus
# exit_status should have been set to 1
die "oops, exit_status: ", $proc->exit_status()
@@ -44,7 +43,7 @@ for (1...$loops){
}
-# With 1 second sleep in dummyd
+print "With 1 second sleep in dummyd\n";
for (1...$loops){
use File::Temp qw / tempdir /;
my $dir = tempdir( CLEANUP => 1 );
@@ -65,14 +64,13 @@ for (1...$loops){
}
foreach my $proc (@procs) {
- $proc->killit();
- $proc->wait();
+ $proc->kill();
}
print "=" x 60, "\n";
}
-# kill all and wait for one
+print "kill all and wait for one\n";
for (1...$loops){
use File::Temp qw / tempdir /;
my $dir = tempdir( CLEANUP => 1 );
@@ -91,12 +89,59 @@ for (1...$loops){
}
foreach my $proc (@procs) {
- $proc->killit();
+ $proc->start_kill();
}
foreach my $proc (@procs) {
- $proc->wait();
+ $proc->wait_one();
}
+
+ print "=" x 60, "\n";
+}
+
+print "kill all using shutdown without callback\n";
+for (1...$loops){
+ use File::Temp qw / tempdir /;
+ my $dir = tempdir( CLEANUP => 1 );
+
+ my @procs;
+ for (1..10){
+
+ my $args= [ "$FindBin::Bin/dummyd.pl", "--vardir=$dir" ];
+ my $proc= My::SafeProcess->new
+ (
+ path => $perl_path,
+ args => \$args,
+ verbose => $verbose,
+ );
+ push(@procs, $proc);
+ }
+
+ My::SafeProcess::shutdown(2, @procs);
+
+ print "=" x 60, "\n";
+}
+
+print "kill all using shutdown\n";
+for (1...$loops){
+ use File::Temp qw / tempdir /;
+ my $dir = tempdir( CLEANUP => 1 );
+
+ my @procs;
+ for (1..10){
+
+ my $args= [ "$FindBin::Bin/dummyd.pl", "--vardir=$dir" ];
+ my $proc= My::SafeProcess->new
+ (
+ path => $perl_path,
+ args => \$args,
+ verbose => $verbose,
+ shutdown => sub { }, # Does nothing
+ );
+ push(@procs, $proc);
+ }
+
+ My::SafeProcess::shutdown(2, @procs);
print "=" x 60, "\n";
}
| Thread |
|---|
| • bk commit into 5.0 tree (msvensson:1.2577) | msvensson | 5 Nov |