Merge lp:~y-trudeau/mysql-mmm/NonBlocking into lp:mysql-mmm

Proposed by Yves Trudeau
Status: Needs review
Proposed branch: lp:~y-trudeau/mysql-mmm/NonBlocking
Merge into: lp:mysql-mmm
Diff against target: 115 lines (+53/-37)
1 file modified
lib/Monitor/Agent.pm (+53/-37)
To merge this branch: bzr merge lp:~y-trudeau/mysql-mmm/NonBlocking
Reviewer Review Type Date Requested Status
mysql-mmm-core Pending
Review via email: mp+40482@code.launchpad.net

Description of the change

This patch prevents MMM from locking when the agent is stuck. Such situations happen when the local disk subsystem is having issues. The new code set an alarm to allow continuous if the remote agent is blocked.

To post a comment you must log in.

Unmerged revisions

149. By Yves Trudeau

tested version, behave as expected

148. By Yves Trudeau

addition of the unblocking code

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/Monitor/Agent.pm'
2--- lib/Monitor/Agent.pm 2009-10-27 12:48:10 +0000
3+++ lib/Monitor/Agent.pm 2010-11-09 21:32:49 +0000
4@@ -5,6 +5,7 @@
5 use Log::Log4perl qw(:easy);
6 use MMM::Common::Socket;
7 use MMM::Monitor::ChecksStatus;
8+use POSIX ':signal_h';
9
10 our $VERSION = '0.01';
11
12@@ -69,7 +70,6 @@
13 my $cmd = shift;
14 my @params = @_;
15
16-
17 my $checks_status = MMM::Monitor::ChecksStatus->instance();
18 unless ($checks_status->ping($self->host)) {
19 return 0;
20@@ -77,43 +77,59 @@
21
22 DEBUG sprintf("Sending command '%s(%s)' to %s (%s:%s)", $cmd, join(', ', @params), $self->host, $self->ip, $self->port);
23
24- my $socket;
25-CONNECT: {
26- $socket = MMM::Common::Socket::create_sender($self->ip, $self->port, 10);
27- unless ($socket && $socket->connected) {
28- redo CONNECT if ($!{EINTR});
29- return 0;
30- }
31-}
32-
33-
34- print $socket join('|', $cmd, main::MMM_PROTOCOL_VERSION, $self->host, @params), "\n";
35-
36- my $res;
37-READ: {
38- $res = <$socket>;
39- redo READ if !$res && $!{EINTR};
40-}
41- close($socket);
42-
43- unless (defined($res)) {
44- WARN sprintf('Received undefined answer from host %s. $!: %s', $self->host, $!);
45- return 0;
46- }
47-
48- DEBUG "Received Answer: $res";
49-
50- if ($res =~ /(.*)\|UP:(.*)/) {
51- $res = $1;
52- my $uptime = $2;
53- $self->uptime($uptime);
54- $self->last_uptime($uptime) if ($self->state eq 'ONLINE');
55- }
56- else {
57- WARN sprintf('Received bad answer \'%s\' from host %s. $!: %s', $res, $self->host, $!);
58- }
59+ my $mask = POSIX::SigSet->new( SIGALRM );
60+ my $action = POSIX::SigAction->new(
61+ sub { DEBUG "Alarm triggered while sending command";
62+ die 'Timeout'; },
63+ $mask,
64+ );
65+ my $oldaction = POSIX::SigAction->new();
66+ sigaction( SIGALRM, $action, $oldaction );
67+
68+ eval {
69+
70+ alarm(15); # Alarm defined at 15s
71+ my $socket;
72
73- return $res;
74+ CONNECT: {
75+ $socket = MMM::Common::Socket::create_sender($self->ip, $self->port, 10);
76+ unless ($socket && $socket->connected) {
77+ redo CONNECT if ($!{EINTR});
78+ alarm(0);
79+ return 0;
80+ }
81+ }
82+
83+ print $socket join('|', $cmd, main::MMM_PROTOCOL_VERSION, $self->host, @params), "\n";
84+
85+ my $res = '';
86+ READ: {
87+ $res = <$socket>;
88+ redo READ if !$res && $!{EINTR};
89+ }
90+
91+ unless (defined($res)) {
92+ WARN sprintf('Received undefined answer from host %s. $!: %s', $self->host, $!);
93+ alarm(0);
94+ return 0;
95+ }
96+ close($socket);
97+ alarm(0);
98+
99+ DEBUG "Received Answer: $res";
100+
101+ if ($res =~ /(.*)\|UP:(.*)/) {
102+ $res = $1;
103+ my $uptime = $2;
104+ $self->uptime($uptime);
105+ $self->last_uptime($uptime) if ($self->state eq 'ONLINE');
106+ }
107+ else {
108+ WARN sprintf('Received bad answer \'%s\' from host %s. $!: %s', $res, $self->host, $!);
109+ }
110+
111+ return $res;
112+ }
113 }
114
115 sub _send_command_retry {

Subscribers

People subscribed via source and target branches