1
0
mirror of https://github.com/MariaDB/server.git synced 2025-06-16 11:21:15 +03:00

Bug #42804 --parallel option does not work for MTR under ActiveState

perl 

The problem here was the method how MTR gets its unique thread ids.
Prior to this patch, the method to do it was to maintain a global 
table of pid,mtr_unique_id) pairs. The table was backed by a text 
file. The table was cleaned up one in a while and dead processes leaking
unique_ids were determined with with kill(0) or with scripting tasklist
on Windows.

This method is flawed specifically on native Windows Perl. fork() is 
implemented with starting a new thread, give it a syntetic negative PID
(threadID*(-1)), until this thread creates a new process with exec()
However,  neither tasklist nor any other native Windows tool can cope with
negative perl PIDs. This lead to incorrect determination of dead process 
and reusing already used mtr_unique_id.

The patch introduces alternative portable  method of solving unique-id 
problem. When a process needs a unique id in range [min...max], it just 
starts  to open files named min, min+1,...max in a loop . After file is 
opened, we do non-blocking flock(). When flock() succeeds, process has 
allocated the ID. When process dies, file is unlocked . Checks for zombies 
are not necessary.

Since the change would create a co-existence problems with older version
of MTR, because of different way to calculate IDs, the default ID range
is changed from 250-299 to 300-349.

Another fix that was necessary enable --parallel option was to serialize 
spawn() calls on Windows. specifically, IO redirects needed to be protected.

This patch also fixes hanging CRTL-C (as described in Bug #38629) for the
"new"  MTR. The fix was already in 6.0 and is now downported.
This commit is contained in:
Vladislav Vaintroub
2009-04-23 13:35:02 +02:00
parent 1151d8625f
commit 361fa97258
4 changed files with 85 additions and 132 deletions

View File

@ -83,6 +83,13 @@ sub exit_status {
};
}
# threads.pm may not exist everywhere, so use only on Windows.
use if $^O eq "MSWin32", "threads";
use if $^O eq "MSWin32", "threads::shared";
my $win32_spawn_lock :shared;
#
# Create a new process
@ -104,6 +111,8 @@ sub create_process {
if ($^O eq "MSWin32"){
lock($win32_spawn_lock);
#printf STDERR "stdin %d, stdout %d, stderr %d\n",
# fileno STDIN, fileno STDOUT, fileno STDERR;