RPC/ToWorker.pm

filter: Statementstmt 29.4% 98 / 333 Branchbran 0.0% 0 / 114 Conditioncond 0.0% 0 / 49 MC/DCmcdc 0.0% 0 / 28 Subroutinesub 41.2% 26 / 63 Podpod 0.0% 0 / 5 totaltotal 20.9% 124 / 592 CC 83 SCAR 52.5
CC
83
Cov
20%
do_remote_job
812.0
ie_input
208.9
__ANON__
72.0
CRAP 190.9
↑ Summary Proc/Parallel/Unreliable.pm »
1  
2 package RPC::ToWorker;
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 require Exporter;
7 1 ▶use File::Slurp::Remote::BrokenDNS qw($myfqdn %fqdnify);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Tie::Function::Examples qw(%q_perl);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use IO::Event;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use IO::Event::Callback;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Eval::LineNumbers qw(eval_line_numbers);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use IO::Event::Callback;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Proc::Parallel::RemoteKiller;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Scalar::Util qw(refaddr weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 require POSIX;
20  
21 1 our $VERSION = 0.601;
22  
23 1 our @EXPORT = qw(do_remote_job);
24 1 our @ISA = qw(Exporter);
25  
26 1 our $command = 'perl';
27  
28 1 our $max_retry = 10;
29  
30 1 my $timer_interval = 5;
31 1 my $reconnect_timeout = 7200;
32 1 my $listen_port = 28328;
33 1 my $listener;
34 1 my $poll_interval = 15;
35  
36 1 our $remote_killer;
37  
38 1 my %waiting;
39  
40 1 our $debug = 0;
41 1 our $debug_create = 0;
42  
43 1 my %forced_polling;
44 1 my $last_poll = 0;
45 1 our $doing_force_poll = 1;
46  
47 sub force_poll
48 0 ▶{
Subroutine force_poll: not called CC=4 SCAR=30.0
Pod undocumented
49 # work around a bug in IO::Event or maybe Event
50 0 ▶ return if $doing_force_poll;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::doing_force_poll 0 0 0
51 0 return $last_poll + $poll_interval < time;
52 0 local $doing_force_poll = 1;
53 0 $last_poll = time;
54  
55 0 print STDERR "--------------------------------- forced poll start ----------------------------\n";
56  
57 0 for my $a (keys %forced_polling) {
58 0 my $ioe = $forced_polling{$a};
59 0 ▶ if ($ioe) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ioe) { } 0 0 0
60 0 $ioe->ie_input();
61 } else {
62 0 delete $forced_polling{$a};
63 }
64 }
65  
66 0 print STDERR "--------------------------------- forced poll end ------------------------------\n";
67 }
68  
69 sub do_remote_job
70 0 ▶{
Subroutine do_remote_job: not called CC=28 SCAR=67.0
Pod undocumented
71 0 my (%params) = @_;
72  
73 0 ▶ $params{can_retry} = 1 unless defined $params{can_retry};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $params{"can_retry"} 0 0 0
74 0 my $can_retry = $params{can_retry};
75 0 my $host = $params{host};
76 0 ▶ my $when_done = $params{when_done} || confess "when_done is a required parameter";
Condition0%0/2
$params{'when_done'} || confess('when_done is a required parameter')
l!l
00
MC/DC0%0/1
$params{'when_done'} || confess('when_done is a required parameter')
$params{'when_done'}
Truth table0%0/2
A
A= $params{'when_done'}
Aresult
11
00
77 0 my $data = $params{data};
78 0 ▶ my $chdir = $params{chdir} ||= '.';
Condition0%0/2
$params{"chdir"} ||= "."
l!l
00
MC/DC0%0/1
$params{"chdir"} ||= "."
$params{"chdir"}
Truth table0%0/2
A
A= $params{"chdir"}
Aresult
11
00
79 0 my $eval = $params{eval};
80 0 ▶ my $desc = $params{desc} ||= "job on $host";
Condition0%0/2
$params{"desc"} ||= "job on $host"
l!l
00
MC/DC0%0/1
$params{"desc"} ||= "job on $host"
$params{"desc"}
Truth table0%0/2
A
A= $params{"desc"}
Aresult
11
00
81 0 ▶ my $prefix = $params{prefix} ||= "$host:";
Condition0%0/2
$params{"prefix"} ||= "${host}:"
l!l
00
MC/DC0%0/1
$params{"prefix"} ||= "${host}:"
$params{"prefix"}
Truth table0%0/2
A
A= $params{"prefix"}
Aresult
11
00
82 0 ▶ my $preload = $params{preload} ||= [];
Condition0%0/2
$params{"preload"} ||= []
l!l
00
MC/DC0%0/1
$params{"preload"} ||= []
$params{"preload"}
Truth table0%0/2
A
A= $params{"preload"}
Aresult
11
00
83 0 ▶ my $prequel = $params{prequel} ||= '';
Condition0%0/2
$params{"prequel"} ||= ""
l!l
00
MC/DC0%0/1
$params{"prequel"} ||= ""
$params{"prequel"}
Truth table0%0/2
A
A= $params{"prequel"}
Aresult
11
00
84 0 my $alldone = bless { %params }, 'RPC::ToWorker::AllDone';
85 0 ▶ my $status = $params{status} ||= sub { 0; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$params{"status"} ||= sub { 0; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$params{"status"} ||= sub { 0; }
$params{"status"} sub { 0; }
Truth table0%0/3
A ||= B
A= $params{"status"}B= sub { 0; }
ABresult
1X1
011
000
86 0 ▶ $params{failure} ||= sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
87 0 print STDERR "DIE DIE DIE DIE DIE: $desc: @_";
88 # exit 1; hangs!
89 0 POSIX::_exit(1);
90 0 ▶ };
Condition0%0/3
$params{"failure"} ||= sub { print STDERR "DIE DIE DIE DIE DIE: ${desc}: @_"; POSIX::_exit(1); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$params{"failure"} ||= sub { print STDERR "DIE DIE DIE DIE DIE: ${desc}: @_"; POSIX::_exit(1); }
$params{"failure"} sub { print STDERR "DIE DIE DIE DIE DIE: ${desc}: @_"; POSIX::_exit(1); }
Truth table0%0/3
A ||= B
A= $params{"failure"}B= sub { print STDERR "DIE DIE DIE DIE DIE: ${desc}: @_"; POSIX::_exit(1); }
ABresult
1X1
011
000
91 0 ▶ my $died_at = $params{died_at} ||= $params{failure};
Condition0%0/3
$params{"died_at"} ||= $params{"failure"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params{"died_at"} ||= $params{"failure"}
$params{"died_at"} $params{"failure"}
Truth table0%0/3
A ||= B
A= $params{"died_at"}B= $params{"failure"}
ABresult
1X1
011
000
92  
93 0 $params{alldone} = $alldone;
94  
95 0 ▶ $preload = [ split(' ', $preload) ] unless ref $preload;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $preload 0 0 0
96  
97 0 ▶ while(! $listener) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($listener) 0 0 0
98 0 $listener = IO::Event::Socket::INET->new(
99 Listen => 100,
100 Proto => 'tcp',
101 LocalPort => ++$listen_port,
102 );
103 0 ▶ unless ($listener) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($listener) 0 0 0
104 0 warn "# Cannot listen on port $listen_port: $!";
105 0 redo;
106 }
107 my $timer = IO::Event->timer(
108 interval => $timer_interval,
109 0 ▶ cb => sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
110 0 for my $e (keys %waiting) {
111 0 my $r = $waiting{$e};
112 0 ▶ next if time < $r->{start_time} + $reconnect_timeout;
Branch: 1 branch
BranchTrueFalseTotal
if &RPC::ToWorker::time() < $r->{"start_time"} + $reconnect_timeout 0 0 0
113 0 ▶ next if $r->{alldone}{failed};
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"alldone"}{"failed"} 0 0 0
114 0 ▶ if ($r->{alldone}{compile_finished} && $can_retry && ! $r->{alldone}{master_go} && $can_retry < $max_retry) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{'alldone'}{'compile_finished'} and $can_retry and not $r->{'alldone'}{'master_go'} and $can_retry < $RPC::ToWorker::max_retry) { } 0 0 0
Condition0%0/9
$r->{"alldone"}{"compile_finished"} and $can_retry and not $r->{"alldone"}{"master_go"} and $can_retry < $RPC::ToWorker::max_retry
!ll&&!rl&&r
000
$r->{"alldone"}{"compile_finished"} and $can_retry and not $r->{"alldone"}{"master_go"}
!ll&&!rl&&r
000
$r->{"alldone"}{"compile_finished"} and $can_retry
!ll&&!rl&&r
000
MC/DC0%0/4
$r->{"alldone"}{"compile_finished"} and $can_retry and not $r->{"alldone"}{"master_go"} and $can_retry < $RPC::ToWorker::max_retry
$r->{"alldone"}{"compile_finished"} $can_retry not $r->{"alldone"}{"master_go"} $can_retry < $RPC::ToWorker::max_retry
Truth table0%0/5
A and B and not(C) and D
A= $r->{"alldone"}{"compile_finished"}B= $can_retryC= not $r->{"alldone"}{"master_go"}D= $can_retry < $RPC::ToWorker::max_retry
ABCDresult
0XXX0
10XX0
110X0
11100
11111
115 0 $r->{alldone}->{retrying} = 1;
116 0 $r->{alldone}{failed} = "Timed out, retrying";
117 0 my %new = %$r;
118 0 delete $new{alldone};
119 0 $new{can_retry}++;
120 0 $new{desc} = "RETRY$new{can_retry} $new{desc}";
121 0 do_remote_job(%new);
122 0 print STDERR "RETRYING REMOTE JOB $desc\n";
123 } else {
124 0 $r->{failure}->("Timed out waiting for job $desc on $host to connect to $listen_port for cookie $e");
125 }
126 }
127 0 RPC::ToWorker::force_poll();
128 },
129 0 );
130  
131 # $listener->event->prio(1);
132  
133 0 $remote_killer = Proc::Parallel::RemoteKiller->new();
134 }
135  
136 0 my $slavefh = new IO::Handle;
137 0 my $parentfh = new IO::Handle;
138  
139 0 ▶ socketpair($slavefh, $parentfh, AF_UNIX, SOCK_STREAM, PF_UNSPEC)
Branch: 1 branch
BranchTrueFalseTotal
socketpair $slavefh, $parentfh, 1, 1, 0 or die "socketpair: $!" 0 0 0
140 or die "socketpair: $!";
141 0 my $pid = fork();
142 0 my $slave;
143 0 ▶ if ($pid) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pid) { } 0 0 0
elsif (defined $pid) { } 0 0 0
144 # parent
145 0 $parentfh->close();
146 0 $slavefh->blocking(0);
147 0 $slavefh->autoflush(1);
148 $slave = IO::Event::Callback->new($slavefh,
149 0 ▶ werror => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
150 0 $params{failure}->("Could not write to stdin for $desc: $!");
151 0 $alldone->{failed}->("Could not write to stdin for $desc: $!");
152 },
153 0 ▶ input => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
154 0 my ($self, $ioe) = @_;
155 0 ▶ while (<$ioe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $ioe)) 0 0 0
156 0 ▶ if (/^SLAVE PID=(\d+)\n/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^SLAVE PID=(\d+)\n/) { } 0 0 0
elsif (/^compile finished\./) { } 0 0 0
157 0 $remote_killer->note($host, $1);
158 0 $params{pid} = $1;
159 0 $alldone->{slavepid} = $1;
160 0 next;
161 } elsif (/^compile finished\./) {
162 0 $alldone->{compile_finished} = 1;
163 0 next;
164 }
165 0 ▶ if ($params{output_handler}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{'output_handler'}) { } 0 0 0
166 0 $params{output_handler}->($_);
167 } else {
168 0 print STDERR "$prefix SSH/ERROR: $_";
169 }
170 }
171 0 RPC::ToWorker::force_poll();
172 },
173 0 ▶ eof => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
174 0 my ($self, $ioe) = @_;
175 0 $ioe->close();
176 0 ▶ $params{output_handler}->("EOF on ssh ($desc)\n") if $debug_create;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug_create 0 0 0
177 },
178 0 );
179 0 ▶ $params{output_handler}->("startup ($desc)\n") if $debug_create;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug_create 0 0 0
180 } elsif (defined $pid) {
181 # child
182 0 $slavefh->close();
183 0 $parentfh->autoflush(1);
184 0 $parentfh->blocking(0);
185 0 ▶ print $parentfh "Foo!\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug 0 0 0
186 0 ▶ open STDIN, "<&", \$parentfh or die "dup onto STDIN: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDIN, "<&", \$parentfh or die "dup onto STDIN: $!" 0 0 0
187 0 ▶ open STDOUT, ">&", \$parentfh or die "dup onto STDOUT: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">&", \$parentfh or die "dup onto STDOUT: $!" 0 0 0
188 0 ▶ open STDERR, ">&", \$parentfh or die "dup onto STDERR: $!";
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&", \$parentfh or die "dup onto STDERR: $!" 0 0 0
189 0 if (0 && $fqdnify{$host} eq $myfqdn) { # XXX why is this not reliable?
190 exec $command
191 or die "exec $command: $!";
192 } else {
193 exec 'ssh', $host, '-o', 'StrictHostKeyChecking=no', '-o', 'BatchMode=yes', $command,
194 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
exec "ssh", $host, "-o", "StrictHostKeyChecking=no", "-o", "BatchMode=yes", $RPC::ToWorker::command or do { $params{"failure"}->("exec ssh $host $RPC::ToWorker::command: $!"); return } 0 0 0
195 0 $params{failure}->("exec ssh $host $command: $!");
196 0 return;
197 };
198 }
199 } else {
200 0 die "cannot fork: $!";
201 }
202  
203 0 my $cookie;
204 do {
205 0 $cookie = "C".rand(100000000);
206 0 ▶ } while defined $waiting{"$cookie MASTER"};
Branch: 1 branch
BranchTrueFalseTotal
defined $waiting{"$cookie MASTER"} and do { do { $cookie = 'C' . rand(100000000) } } 0 0 0
207  
208 0 $waiting{"$cookie MASTER"} = bless {
209 slave => $slave,
210 start_time => time,
211 %params,
212 }, 'RPC::ToWorker::Master';
213  
214 0 $waiting{"$cookie OUTPUT"} = bless {
215 slave => $slave,
216 start_time => time,
217 %params,
218 }, 'RPC::ToWorker::Output';
219  
220 0 my $stream = '';
221  
222 0 ▶ if ($params{stream_in} || $params{stream_out}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"stream_in"} or $params{"stream_out"}) 0 0 0
Condition0%0/3
$params{"stream_in"} or $params{"stream_out"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params{"stream_in"} or $params{"stream_out"}
$params{"stream_in"} $params{"stream_out"}
Truth table0%0/3
A or B
A= $params{"stream_in"}B= $params{"stream_out"}
ABresult
1X1
011
000
223 0 $stream = eval_line_numbers(<<END_STREAM);
224 my \$stream = new IO::Socket::INET (
225 PeerAddr => '$myfqdn:$listen_port',
226 Proto => 'tcp',
227 );
228 die "Could not connect to master at $myfqdn:$listen_port: \$!" unless \$stream;
229 \$stream->autoflush(1);
230 print \$stream "$cookie STREAM\\n"
231 or die;
232 END_STREAM
233  
234 0 $waiting{"$cookie STREAM"} = bless {
235 slave => $slave,
236 start_time => time,
237 %params,
238 }, 'RPC::ToWorker::Stream';
239 }
240  
241 0 my $pre = '';
242 0 $pre .= "use $_; " for @$preload;
243  
244 0 ▶ my $p5lib = $ENV{PERL5LIB} || '';
Condition0%0/2
$ENV{'PERL5LIB'} || ''
l!l
00
MC/DC0%0/1
$ENV{'PERL5LIB'} || ''
$ENV{'PERL5LIB'}
Truth table0%0/2
A
A= $ENV{'PERL5LIB'}
Aresult
11
00
245  
246 0 my $av0 = "slave for $myfqdn:$$ - $desc: ";
247  
248 0 print $slave eval_line_numbers(<<END_SLAVE0);
249 \$0 = $q_perl{$av0} . 'starting';
250 use strict;
251 use warnings;
252 BEGIN {
253 print "SLAVE PID=\$\$\\n";
254 chdir($q_perl{$chdir}) or die "cannot chdir to $chdir on $host: \$!";
255 unshift(\@INC, split(':', $q_perl{$p5lib}));
256 }
257 END_SLAVE0
258  
259 0 print $slave $prequel;
260 0 print $slave "\n";
261 0 print $slave eval_line_numbers(<<END_SLAVE1);
262 use IO::Socket::INET;
263 use Storable qw(freeze thaw);
264 $pre
265 END_SLAVE1
266 0 print $slave eval_line_numbers(<<END_SLAVE2);
267  
268 if ($debug) {
269 open(DEBUG, ">&STDERR") or die "dup STDERR: $!";
270 print STDERR "Dup to DEBUG should have worked\\n";
271 select(DEBUG);
272 \$| = 1;
273 select(STDOUT);
274 printf DEBUG "debug test %d\\n", __LINE__;
275 }
276  
277 \$0 = $q_perl{$av0} . 'redirecting STDOUT';
278  
279 my \$output = new IO::Socket::INET (
280 PeerAddr => '$myfqdn:$listen_port',
281 Proto => 'tcp',
282 );
283 die "Could not connect to master at $myfqdn:$listen_port: \$!" unless \$output;
284 \$output->autoflush(1);
285 print \$output "$cookie OUTPUT\\n";
286  
287 if ($debug) {
288 printf DEBUG "debug test %d\\n", __LINE__;
289 print STDERR "Connected for Output\\n";
290 printf DEBUG "debug test %d\\n", __LINE__;
291 print "Output connected\\n";
292 printf DEBUG "debug test %d\\n", __LINE__;
293 print \$output "test foo\\n";
294 printf DEBUG "debug test %d\\n", __LINE__;
295 }
296  
297 open STDOUT, ">&", \$output or die "dup to STDOUT: \$!";
298 select STDOUT;
299 \$| = 1;
300  
301 if ($debug) {
302 print STDERR "stderr test\\n";
303 printf DEBUG "debug test %d\\n", __LINE__;
304 }
305  
306 \$0 = $q_perl{$av0} . 'connecting STREAM';
307  
308 $stream
309  
310 \$0 = $q_perl{$av0} . 'setting up MASTER';
311  
312 my \$master = new IO::Socket::INET (
313 PeerAddr => '$myfqdn:$listen_port',
314 Proto => 'tcp',
315 );
316 die "Could not connect to master at $myfqdn:$listen_port: \$!" unless \$master;
317 \$master->autoflush(1);
318 printf DEBUG "debug test %d\\n", __LINE__ if $debug;
319 print \$master "$cookie MASTER\\n"
320 or die;
321 printf DEBUG "debug test %d\\n", __LINE__ if $debug;
322  
323 \$0 = $q_perl{$av0} . 'looking for "go" from master';
324  
325 my \$go = <\$master>;
326  
327 chomp(\$go);
328 exit 1 if \$go eq 'suicide';
329  
330 \$go =~ /go (\\d+)/;
331 my \$amt = \$1;
332 die unless \$amt;
333  
334 \$0 = $q_perl{$av0} . 'downloading initial data';
335  
336 my \$buf = '';
337  
338 while (length(\$buf) < \$amt) {
339 read(\$master, \$buf, \$amt - length(\$buf), length(\$buf)) or die;
340 }
341  
342 printf DEBUG "debug test %d\\n", __LINE__ if $debug;
343  
344 \$0 = $q_perl{$av0} . 'reconstituting initial data';
345  
346 my \$data = \${thaw(\$buf)};
347  
348 \$RPC::ToWorker::Callback::master = # suppress used-once warning
349 \$RPC::ToWorker::Callback::master = \$master;
350  
351 printf DEBUG "debug test %d\\n", __LINE__ if $debug;
352 END_SLAVE2
353 0 print $slave eval_line_numbers(<<END_SLAVE3);
354  
355 \$0 = $q_perl{$av0} . 'RUNNING';
356 my \@r;
357  
358 printf DEBUG "debug test %d\\n", __LINE__ if $debug;
359 eval {
360 sub slave_eval {
361 $eval
362 }
363 \@r = slave_eval(\$data);
364 };
365 printf DEBUG "debug test %d\\n", __LINE__ if $debug;
366  
367 if (\$\@) {
368 \$0 = $q_perl{$av0} . 'returning failure';
369 print STDERR \$\@;
370 my \$err = freeze(\\\$\@);
371 printf \$master "DATA %d RETURN_ERROR\\n%s", length(\$err), \$err;
372 # exit 1; hangs
373 POSIX::_exit(1);
374 }
375  
376 \$0 = $q_perl{$av0} . 'returning results';
377  
378 my \$ret = freeze(\\\@r);
379 printf \$master "DATA %d RETURN_VALUES\\n%s", length(\$ret), \$ret;
380  
381 \$0 = $q_perl{$av0} . 'exiting';
382  
383 exit;
384  
385 BEGIN { print STDERR "compile finished.\\n" }
386 END_SLAVE3
387 0 shutdown($slavefh, 1); # done writing
388 }
389  
390 sub ie_connection
391 0 ▶{
Subroutine ie_connection: not called CC=2 SCAR=17.9
Pod undocumented
392 0 my ($pkg, $ioe) = @_;
393 0 ▶ print STDERR "# GOT CONNECTION\n" if $RPC::ToWorker::debug;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug 0 0 0
394 0 my $newfh = $ioe->accept();
395 # $newfh->event->prio(1);
396 0 $forced_polling{refaddr($newfh)} = $newfh;
397 0 weaken($forced_polling{refaddr($newfh)});
398 0 RPC::ToWorker::force_poll();
399 }
400  
401 sub ie_input
402 0 ▶{
Subroutine ie_input: not called CC=5 SCAR=34.0
Pod undocumented
403 0 my ($self, $ioe) = @_;
404 0 my $cookie = <$ioe>;
405 0 ▶ return unless $cookie;
Branch: 1 branch
BranchTrueFalseTotal
unless $cookie 0 0 0
406 0 chomp($cookie);
407 0 ▶ print STDERR "# GOT COOKIE $cookie\n" if $debug;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug 0 0 0
408 0 ▶ unless ($waiting{$cookie}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($waiting{$cookie}) 0 0 0
409 0 warn "Unknown cookie '$cookie'";
410 0 next;
411 }
412 0 $ioe->handler($waiting{$cookie});
413 # $ioe->event->prio(4);
414 0 my $o = $waiting{$cookie};
415 0 ▶ $o->{output_handler}->(sprintf("using fd %d for $cookie (%s)\n", $ioe->fileno, $o->{desc})) if $RPC::ToWorker::debug_create;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug_create 0 0 0
416 0 $waiting{$cookie}->send_initial_data($ioe);
417 0 delete $waiting{$cookie};
418 0 RPC::ToWorker::force_poll();
419 }
420  
421 sub ie_eof
422 0 ▶{
Subroutine ie_eof: not called CC=1 SCAR=6.9
Pod undocumented
423 0 my ($self, $ioe) = @_;
424 0 $ioe->close();
425 }
426  
427  
428 package RPC::ToWorker::Master;
429  
430 #
431 # This is on the master
432 #
433  
434 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
435 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
436 1 ▶use Storable qw(freeze thaw);
Subroutine BEGIN: called CC=1 SCAR=0.0
437 1 ▶use Module::Load qw(load);
Subroutine BEGIN: called CC=1 SCAR=0.0
438  
439 sub send_initial_data
440 0 ▶{
Subroutine send_initial_data: not called CC=4 SCAR=30.0
441 0 my ($self, $ioe) = @_;
442  
443 0 ▶ if ($self->{alldone}{retrying}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'alldone'}{'retrying'}) { } 0 0 0
444 0 print $ioe "suicide\n";
445 } else {
446 0 $self->{alldone}{master_go} = 1;
447  
448 0 ▶ my $id = freeze(\($self->{data} || undef));
Condition0%0/2
$self->{'data'} || undef
l!l
00
MC/DC0%0/1
$self->{'data'} || undef
$self->{'data'}
Truth table0%0/2
A
A= $self->{'data'}
Aresult
11
00
449  
450 0 printf $ioe "go %d\n", length($id); # don't suicide
451  
452 0 print $ioe $id;
453 0 ▶ print STDERR "# DATA SENT\n" if $RPC::ToWorker::debug;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug 0 0 0
454 }
455 }
456  
457 sub ie_input
458 0 ▶{
Subroutine ie_input: not called CC=15 SCAR=53.4
459 0 my ($self, $ioe, $ibr) = @_;
460 0 ▶ $self->{output_handler}->("control socket input ready ($self->{desc})\n") if $RPC::ToWorker::debug_create;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug_create 0 0 0
461 0 ▶ while ($$ibr =~ /\A(DATA (\d+) ([^\n]+)\n)/ && length($$ibr) - length($1) >= $2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$ibr =~ /\A(DATA (\d+) ([^\n]+)\n)/ and length($$ibr) - length($1) >= $2) 0 0 0
Condition0%0/3
$$ibr =~ /\A(DATA (\d+) ([^\n]+)\n)/ and length($$ibr) - length($1) >= $2
!ll&&!rl&&r
000
MC/DC0%0/2
$$ibr =~ /\A(DATA (\d+) ([^\n]+)\n)/ and length($$ibr) - length($1) >= $2
$$ibr =~ /\A(DATA (\d+) ([^\n]+)\n)/ length($$ibr) - length($1) >= $2
Truth table0%0/3
A and B
A= $$ibr =~ /\A(DATA (\d+) ([^\n]+)\n)/B= length($$ibr) - length($1) >= $2
ABresult
0X0
100
111
462 0 my ($header, $dsize, $control) = ($1, $2, $3);
463 0 my $data = thaw(substr($$ibr, length($header), $dsize));
464 0 substr($$ibr, 0, length($header) + $dsize, '');
465 0 ▶ if ($control =~ /^RETURN_VALUES$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($control =~ /^RETURN_VALUES$/) { } 0 0 0
elsif ($control =~ /^RETURN_ERROR$/) { } 0 0 0
elsif ($control =~ /^CALL (\S+) with (.*?) after loading (.*)/) { } 0 0 0
466 0 ▶ $self->{output_handler}->("return values sent - $dsize ($self->{desc})\n") if $RPC::ToWorker::debug_create;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug_create 0 0 0
467 0 eval {
468 0 $self->{when_done}->(@$data);
469 };
470 0 ▶ $self->{failure}->("when done for $self->{desc}: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
471 0 $self->{return_values_sent} = 1;
472 0 $ioe->close();
473 } elsif ($control =~ /^RETURN_ERROR$/) {
474 0 my $error = $$data;
475 0 $self->{failure}->("SLAVE FAILURE: $error");
476 0 $self->{alldone}{failured} = "SLAVE FAILURE: $error";
477 0 ▶ $self->{output_handler}->("return error ($self->{desc})\n") if $RPC::ToWorker::debug_create;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug_create 0 0 0
478 } elsif ($control =~ /^CALL (\S+) with (.*?) after loading (.*)/) {
479 0 my ($func, $with, $mods) = ($1, $2, $3);
480 0 for my $mod (split(' ', $mods)) {
481 0 load $mod;
482 }
483 0 for my $item (split(' ',$with)) {
484 0 push(@$data, $item);
485 0 push(@$data, $self->{local_data}{$item});
486 }
487 0 my @ret;
488 0 eval {
489 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
490 0 @ret = &{$func}(@$data);
491 };
492 0 ▶ $self->{failure}->("call to $func on behalf of $self->{desc}: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
493 0 my $ret = freeze(\@ret);
494 0 ▶ printf $ioe "DATA %d DONE_RESPONSE\n%s", length($ret), $ret or die;
Branch: 1 branch
BranchTrueFalseTotal
printf $ioe "DATA %d DONE_RESPONSE\n%s", length $ret, $ret or die 0 0 0
495 } else {
496 0 $self->{failure}->("SLAVE FAILURE: could not parse input from slave");
497 0 $self->{alldone}{failured} = "SLAVE FAILURE: could not parse input from slave";
498 0 ▶ $self->{output_handler}->("return parse error ($self->{desc})\n") if $RPC::ToWorker::debug_create;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug_create 0 0 0
499 }
500 }
501 0 RPC::ToWorker::force_poll();
502 }
503  
504 sub ie_werror
505 0 ▶{
Subroutine ie_werror: not called CC=3 SCAR=24.8
506 0 my ($self, $ioe) = @_;
507 0 ▶ return if $self->{alldone}{retrying};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"alldone"}{"retrying"} 0 0 0
508 IO::Event->timer(
509 after => 5,
510 0 ▶ cb => sub { $self->{failure}->("Could not write to control socket for: $self->{desc}") },
Subroutine __ANON__: not called CC=1 SCAR=6.9
511 0 );
512 0 print STDERR "Failed: Could not write to control socket for job: $self->{desc}, will suicide soon, after queued output has chance to print\n";
513 0 $self->{alldone}{failured} = "Could not write to control socket for job: $self->{desc}";
514 0 ▶ $self->{output_handler}->("Write error on control socket ($self->{desc})\n") if $RPC::ToWorker::debug_create;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug_create 0 0 0
515 }
516  
517 sub ie_eof
518 0 ▶{
Subroutine ie_eof: not called CC=4 SCAR=30.0
519 0 my ($self, $ioe) = @_;
520  
521 0 ▶ $self->{output_handler}->("EOF on control socket ($self->{desc})\n") if $RPC::ToWorker::debug_create;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug_create 0 0 0
522 0 $ioe->close();
523  
524 0 ▶ return if $self->{return_values_sent};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"return_values_sent"} 0 0 0
525 0 ▶ return if $self->{alldone}{retrying};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"alldone"}{"retrying"} 0 0 0
526  
527 IO::Event->timer(
528 after => 5,
529 0 ▶ cb => sub { $self->{failure}->("No return values from remote job: $self->{desc}") },
Subroutine __ANON__: not called CC=1 SCAR=6.9
530 0 );
531 0 print STDERR "Failed: no return values from remote job: $self->{desc}, will suicide soon, after queued output has chance to print\n";
532 0 $self->{alldone}{failured} = "No return values from remote job: $self->{desc}";
533 }
534  
535 package RPC::ToWorker::Output;
536  
537 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
538 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
539  
540 sub send_initial_data
541 0 ▶{
Subroutine send_initial_data: not called CC=1 SCAR=6.9
542 0 my ($self, $ioe) = @_;
543 0 shutdown($ioe->filehandle(), 1); # we don't write to this one
544 # $ioe->event->prio(6);
545 }
546  
547 sub ie_input
548 0 ▶{
Subroutine ie_input: not called CC=4 SCAR=30.0
549 0 my ($self, $ioe) = @_;
550 0 ▶ while (<$ioe>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $ioe)) 0 0 0
551 0 ▶ next if /ssh_exchange_identification: Connection closed by remote host/;
Branch: 1 branch
BranchTrueFalseTotal
if /ssh_exchange_identification: Connection closed by remote host/ 0 0 0
552 0 ▶ if ($self->{output_handler}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'output_handler'}) { } 0 0 0
553 0 $self->{output_handler}->($_)
554 } else {
555 0 print STDERR "$self->{prefix} OUTPUT: $_";
556 }
557 }
558 0 RPC::ToWorker::force_poll();
559 }
560  
561 sub ie_eof
562 0 ▶{
Subroutine ie_eof: not called CC=2 SCAR=17.9
563 0 my ($self, $ioe) = @_;
564 0 $ioe->close();
565 0 ▶ $self->{output_handler}->("EOF on output socket ($self->{desc})\n") if $RPC::ToWorker::debug_create;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug_create 0 0 0
566 }
567  
568 package RPC::ToWorker::Stream;
569  
570 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
571 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
572 1 ▶use Storable qw(freeze thaw);
Subroutine BEGIN: called CC=1 SCAR=0.0
573  
574 sub send_initial_data
575 0 ▶{
Subroutine send_initial_data: not called CC=4 SCAR=30.0
576 0 my ($self, $ioe) = @_;
577 0 ▶ $self->{stream_werror} ||= sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
578 0 my ($self, $ioe) = @_;
579 0 IO::Event::unloop_all();
580 0 die "Write error sending data to $self->{desc}: $!";
581 0 ▶ };
Condition0%0/3
$self->{"stream_werror"} ||= sub { my($self, $ioe) = @_; IO::Event::unloop_all(); die qq[Write error sending data to $self->{"desc"}: $!]; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"stream_werror"} ||= sub { my($self, $ioe) = @_; IO::Event::unloop_all(); die qq[Write error sending data to $self->{"desc"}: $!]; }
$self->{"stream_werror"} sub { my($self, $ioe) = @_; IO::Event::unloop_all(); die qq[Write error sending data to $self->{"desc"}: $!]; }
Truth table0%0/3
A ||= B
A= $self->{"stream_werror"}B= sub { my($self, $ioe) = @_; IO::Event::unloop_all(); die qq[Write error sending data to $self->{"desc"}: $!]; }
ABresult
1X1
011
000
582 0 for my $h (@IO::Event::Callback::handlers, 'setup') {
583 0 ▶ $self->{"stream_$h"} ||= sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$$self{"stream_$h"} ||= sub { }
l!l&&r!l&&!r
000
MC/DC0%0/2
$$self{"stream_$h"} ||= sub { }
$$self{"stream_$h"} sub { }
Truth table0%0/3
A ||= B
A= $$self{"stream_$h"}B= sub { }
ABresult
1X1
011
000
584 }
585 0 $self->{'stream_setup'}->($self, $ioe);
586 # $ioe->event->prio(5);
587 }
588  
589 0 ▶sub ie_input { $_[0]->{'stream_input'}->(@_) };
Subroutine ie_input: not called CC=1 SCAR=6.9
590 0 ▶sub ie_connection { $_[0]->{'stream_connection'}->(@_) };
Subroutine ie_connection: not called CC=1 SCAR=6.9
591 0 ▶sub ie_read_ready { $_[0]->{'stream_read_ready'}->(@_) };
Subroutine ie_read_ready: not called CC=1 SCAR=6.9
592 0 ▶sub ie_werror { $_[0]->{'stream_werror'}->(@_) };
Subroutine ie_werror: not called CC=1 SCAR=6.9
593 0 ▶sub ie_eof { $_[0]->{'stream_eof'}->(@_) };
Subroutine ie_eof: not called CC=1 SCAR=6.9
594 0 ▶sub ie_output { $_[0]->{'stream_output'}->(@_) };
Subroutine ie_output: not called CC=1 SCAR=6.9
595 0 ▶sub ie_outputdone { $_[0]->{'stream_outputdone'}->(@_) };
Subroutine ie_outputdone: not called CC=1 SCAR=6.9
596 0 ▶sub ie_connected { $_[0]->{'stream_connected'}->(@_) };
Subroutine ie_connected: not called CC=1 SCAR=6.9
597 0 ▶sub ie_connect_failed { $_[0]->{'stream_connect_failed'}->(@_)};
Subroutine ie_connect_failed: not called CC=1 SCAR=6.9
598 0 ▶sub ie_died { $_[0]->{'stream_died'}->(@_) };
Subroutine ie_died: not called CC=1 SCAR=6.9
599 0 ▶sub ie_timer { $_[0]->{'stream_timer'}->(@_) };
Subroutine ie_timer: not called CC=1 SCAR=6.9
600 0 ▶sub ie_exception { $_[0]->{'stream_exception'}->(@_) };
Subroutine ie_exception: not called CC=1 SCAR=6.9
601 0 ▶sub ie_outputoverflow { $_[0]->{'stream_outputoverflow'}->(@_)};
Subroutine ie_outputoverflow: not called CC=1 SCAR=6.9
602  
603 package RPC::ToWorker::AllDone;
604  
605 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
606 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
607  
608 sub DESTROY
609 0 ▶{
Subroutine DESTROY: not called CC=7 SCAR=40.3
610 0 my ($self) = @_;
611 0 ▶ $self->{failure}->($self->{failed}) if $self->{failed} && ! $self->{retrying};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} and not $self->{"retrying"} 0 0 0
Condition0%0/3
$self->{"failed"} and not $self->{"retrying"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"failed"} and not $self->{"retrying"}
$self->{"failed"} not $self->{"retrying"}
Truth table0%0/3
A and not(B)
A= $self->{"failed"}B= not $self->{"retrying"}
ABresult
0X0
100
111
612 $RPC::ToWorker::remote_killer->forget($self->{host}, $self->{slavepid})
613 0 ▶ if $self->{slavepid};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"slavepid"} 0 0 0
614 0 ▶ $self->{all_done}->() if $self->{all_done};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"all_done"} 0 0 0
615 $RPC::ToWorker::remote_killer->forget($self->{host}, $self->{pid})
616 0 ▶ if $self->{pid};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pid"} 0 0 0
617 0 RPC::ToWorker::force_poll();
618 0 ▶ $self->{output_handler}->("Alldone on ($self->{desc})\n") if $RPC::ToWorker::debug_create;
Branch: 1 branch
BranchTrueFalseTotal
if $RPC::ToWorker::debug_create 0 0 0
619 }
620  
621 1 1;
622  
623 __END__
↑ Summary Proc/Parallel/Unreliable.pm »