line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MogileFS::Connection::Worker; |
2
|
|
|
|
|
|
|
# This class maintains a connection to one of the various classes of |
3
|
|
|
|
|
|
|
# workers. |
4
|
|
|
|
|
|
|
|
5
|
7
|
|
|
7
|
|
44
|
use strict; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
427
|
|
6
|
7
|
|
|
7
|
|
38
|
use Danga::Socket (); |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
147
|
|
7
|
7
|
|
|
7
|
|
36
|
use base qw{Danga::Socket}; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
1699
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use fields ( |
10
|
7
|
|
|
|
|
49
|
'read_buf', |
11
|
|
|
|
|
|
|
'job', |
12
|
|
|
|
|
|
|
'pid', |
13
|
|
|
|
|
|
|
'reqid', |
14
|
|
|
|
|
|
|
'last_alive', # unixtime |
15
|
|
|
|
|
|
|
'known_state', # hashref of { "$what-$whatid" => $state } |
16
|
7
|
|
|
7
|
|
47
|
); |
|
7
|
|
|
|
|
22
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
0
|
|
|
0
|
1
|
|
my MogileFS::Connection::Worker $self = shift; |
20
|
0
|
0
|
|
|
|
|
$self = fields::new($self) unless ref $self; |
21
|
0
|
|
|
|
|
|
$self->SUPER::new( @_ ); |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
$self->{pid} = 0; |
24
|
0
|
|
|
|
|
|
$self->{reqid} = 0; |
25
|
0
|
|
|
|
|
|
$self->{job} = undef; |
26
|
0
|
|
|
|
|
|
$self->{last_alive} = time(); |
27
|
0
|
|
|
|
|
|
$self->{known_state} = {}; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub note_alive { |
33
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
34
|
0
|
|
|
|
|
|
$self->{last_alive} = time(); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub watchdog_check { |
38
|
0
|
|
|
0
|
0
|
|
my MogileFS::Connection::Worker $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $timeout = $self->worker_class->watchdog_timeout; |
41
|
0
|
|
|
|
|
|
my $time_since_last_alive = time() - $self->{last_alive}; |
42
|
0
|
|
|
|
|
|
return $time_since_last_alive < $timeout; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub event_read { |
46
|
0
|
|
|
0
|
1
|
|
my MogileFS::Connection::Worker $self = shift; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# if we read data from it, it's not blocked on something else. |
49
|
0
|
|
|
|
|
|
$self->note_alive; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $bref = $self->read(1024); |
52
|
0
|
0
|
|
|
|
|
return $self->close() unless defined $bref; |
53
|
0
|
|
|
|
|
|
$self->{read_buf} .= $$bref; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
while ($self->{read_buf} =~ s/^(.+?)\r?\n//) { |
56
|
0
|
|
|
|
|
|
my $line = $1; |
57
|
0
|
0
|
0
|
|
|
|
if ($self->job eq 'queryworker' && $line !~ /^(?:\:|error|debug)/) { |
58
|
0
|
|
|
|
|
|
MogileFS::ProcManager->HandleQueryWorkerResponse($self, $line); |
59
|
|
|
|
|
|
|
} else { |
60
|
0
|
|
|
|
|
|
MogileFS::ProcManager->HandleChildRequest($self, $line); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub event_write { |
66
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
67
|
0
|
|
|
|
|
|
my $done = $self->write(undef); |
68
|
0
|
0
|
|
|
|
|
$self->watch_write(0) if $done; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub job { |
72
|
0
|
|
|
0
|
0
|
|
my MogileFS::Connection::Worker $self = shift; |
73
|
0
|
0
|
|
|
|
|
return $self->{job} unless @_; |
74
|
0
|
|
|
|
|
|
return $self->{job} = shift; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub worker_class { |
78
|
0
|
|
|
0
|
0
|
|
my MogileFS::Connection::Worker $self = shift; |
79
|
0
|
|
|
|
|
|
return MogileFS::ProcManager->job_to_class($self->{job}); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub pid { |
83
|
0
|
|
|
0
|
0
|
|
my MogileFS::Connection::Worker $self = shift; |
84
|
0
|
0
|
|
|
|
|
return $self->{pid} unless @_; |
85
|
0
|
|
|
|
|
|
return $self->{pid} = shift; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
0
|
1
|
|
sub event_hup { my $self = shift; $self->close; } |
|
0
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
1
|
|
sub event_err { my $self = shift; $self->close; } |
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub close { |
92
|
|
|
|
|
|
|
# mark us as being dead |
93
|
0
|
|
|
0
|
1
|
|
my MogileFS::Connection::Worker $self = shift; |
94
|
0
|
|
|
|
|
|
MogileFS::ProcManager->NoteDeadWorkerConn($self); |
95
|
0
|
|
|
|
|
|
$self->SUPER::close(@_); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Local Variables: |
101
|
|
|
|
|
|
|
# mode: perl |
102
|
|
|
|
|
|
|
# c-basic-indent: 4 |
103
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
104
|
|
|
|
|
|
|
# End: |