Commit 28ffd751 authored by myk%mozilla.org's avatar myk%mozilla.org

Fix for bug 156559: Changes to mysqld-watcher.pl to make it kill queries…

Fix for bug 156559: Changes to mysqld-watcher.pl to make it kill queries quicker, kill 'em all at once, give better notifications, and not include globals.pl, which is unnecessary. r=dmose
parent 700f7639
...@@ -26,31 +26,42 @@ ...@@ -26,31 +26,42 @@
use diagnostics; use diagnostics;
use strict; use strict;
require "globals.pl";
# some configurables: # some configurables:
# length of time before a thread is eligible to be killed, in seconds # length of time before a thread is eligible to be killed, in seconds
# #
my $long_query_time = 600; my $long_query_time = 180;
# #
# the From header for any messages sent out # the From header for any messages sent out
# #
my $mail_from = "root\@lounge.mozilla.org"; my $mail_from = "root\@mothra.mozilla.org";
#
# the To header for any messages sent out
#
my $mail_to = "root";
# #
# mail transfer agent. this should probably really be converted to a Param(). # mail transfer agent. this should probably really be converted to a Param().
# #
my $mta_program = "/usr/lib/sendmail -t -ODeliveryMode=deferred"; my $mta_program = "/usr/lib/sendmail -t -ODeliveryMode=deferred";
# and STDIN is where we get the info about running threads # The array of long-running queries
# #
close(STDIN); my $long = {};
open(STDIN, "/usr/bonsaitools/bin/mysqladmin processlist |");
# iterate through the running threads # Run mysqladmin processlist twice, the first time getting complete queries
# # and the second time getting just abbreviated queries. We want complete
my @LONGEST = (0,0,0,0,0,0,0,0,0); # queries so we know which queries are taking too long to run, but complete
while ( <STDIN> ) { # queries with line breaks get missed by this script, so we get abbreviated
# queries as well to make sure we don't miss any.
foreach my $command ("/opt/mysql/bin/mysqladmin --verbose processlist",
"/opt/mysql/bin/mysqladmin processlist")
{
close(STDIN);
open(STDIN, "$command |");
# iterate through the running threads
#
while ( <STDIN> ) {
my @F = split(/\|/); my @F = split(/\|/);
# if this line is not the correct number of fields, or if the thread-id # if this line is not the correct number of fields, or if the thread-id
...@@ -63,8 +74,11 @@ while ( <STDIN> ) { ...@@ -63,8 +74,11 @@ while ( <STDIN> ) {
&& $F[5] =~ /Query/ # this is actually a query && $F[5] =~ /Query/ # this is actually a query
&& $F[6] > $long_query_time # this query has taken too long && $F[6] > $long_query_time # this query has taken too long
&& $F[8] =~ /(select|SELECT)/ # only kill a select && $F[8] =~ /(select|SELECT)/ # only kill a select
&& $F[6] > $LONGEST[6] ) { # the longest running query seen && !defined($long->{$F[1]}) ) # haven't seen this one already
@LONGEST = @F; {
$long->{$F[1]} = \@F;
system("/opt/mysql/bin/mysqladmin", "kill", $F[1]);
}
} }
} }
...@@ -90,13 +104,15 @@ sub sendEmail($$$$) { ...@@ -90,13 +104,15 @@ sub sendEmail($$$$) {
# if we found anything, kill the database thread and send mail about it # if we found anything, kill the database thread and send mail about it
# #
if ($LONGEST[6] != 0) { if (scalar(keys(%$long))) {
my $message = "";
system ("/usr/bonsaitools/bin/mysqladmin", "kill", $LONGEST[1]); foreach my $process_id (keys(%$long)) {
my $qry = $long->{$process_id};
$message .= join(" ", @$qry) . "\n\n";
}
# fire off an email telling the maintainer that we had to kill a thread # fire off an email telling the maintainer that we had to kill some threads
# #
sendEmail($mail_from, Param("maintainer"), sendEmail($mail_from, $mail_to, "long running MySQL thread(s) killed", $message);
"long running MySQL thread killed",
join(" ", @LONGEST) . "\n");
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment