Mailing List Archive

svn commit: r329730 - in /spamassassin/trunk: build/automc/buildbot_ready masses/rule-qa/automc/RUNME.after masses/rule-qa/automc/ruleqa.cgi
Author: jm
Date: Sun Oct 30 20:26:55 2005
New Revision: 329730

URL: http://svn.apache.org/viewcvs?rev=329730&view=rev
Log:
implement a singleton-locking system for singleton actions in buildbot; move corpus-populating script into svn; some minor tweaks and fixes

Modified:
spamassassin/trunk/build/automc/buildbot_ready
spamassassin/trunk/masses/rule-qa/automc/RUNME.after
spamassassin/trunk/masses/rule-qa/automc/ruleqa.cgi

Modified: spamassassin/trunk/build/automc/buildbot_ready
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/build/automc/buildbot_ready?rev=329730&r1=329729&r2=329730&view=diff
==============================================================================
--- spamassassin/trunk/build/automc/buildbot_ready (original)
+++ spamassassin/trunk/build/automc/buildbot_ready Sun Oct 30 20:26:55 2005
@@ -1,6 +1,11 @@
-#!/usr/bin/perl -w
+#!/usr/bin/perl

use strict;
+use warnings;
+sub run;
+
+my $LOCKDIR = "/home/bbmass/mclocks";
+my $got_lock = undef;

my $perl = $^X;
if (!$perl) {
@@ -30,6 +35,38 @@
# --non-interactive not on the zone yet. duh!
# system ("svn info --non-interactive > masses/svninfo.tmp");
system ("svn info > masses/svninfo.tmp < /dev/null");
+
+ perform_singleton_actions();
+}
+
+sub perform_singleton_actions {
+ if (!try_get_exclusive_lock()) {
+ print "cannot get the exclusive lock; some other BB slave is\n".
+ "doing the singleton actions for us.\n";
+ return;
+ }
+
+ $SIG{INT} = $SIG{TERM} = sub {
+ kill_lock(); die "killed!";
+ };
+
+ eval {
+ _perform_singleton_actions_unlocked();
+ };
+ if ($@) {
+ warn $@;
+ kill_lock();
+ die "aargh";
+ }
+
+ kill_lock();
+ $SIG{INT} = $SIG{TERM} = undef;
+}
+
+sub _perform_singleton_actions_unlocked
+{
+ print "got lock: performing singleton actions\n";
+ run "build/automc/populate_cor";
}

# ---------------------------------------------------------------------------
@@ -59,8 +96,6 @@
run ("./rule-qa/corpus-hourly --dir $logdir");
}

-
-
# ---------------------------------------------------------------------------

sub get_current_svn_revision {
@@ -93,5 +128,49 @@
$pwd =~ /\/slaves\/([^\/]+)\// and return $1;
warn "cannot work out slave name from $pwd";
return "unknown";
+}
+
+
+sub try_get_exclusive_lock {
+ return 1 if (!-d $LOCKDIR); # no locking needed
+
+ $got_lock = undef;
+ my $newf = $LOCKDIR."/singleton_lock.active";
+ if (-f $newf) {
+ open (IN, "<$newf");
+ my $pid = <IN> + 0; close IN;
+
+ if ($pid > 0 && kill(0, $pid)) {
+ print "singleton lock: locked by $pid, still active.\n";
+ return 0;
+ }
+ else {
+ print "singleton lock: locked by $pid, no longer active. killing lock\n";
+ # should have to do this too often, which is just as well, as there's
+ # a tiny little racelet here
+ unlink $newf;
+ }
+ }
+
+ my $tmpf = $LOCKDIR."/singleton_lock.new.$$";
+ open (OUT, ">$tmpf") or die "cannot write to $tmpf";
+ print OUT $$;
+ close OUT or die "cannot write to $tmpf";
+
+ if (!-f $newf && rename($tmpf, $newf)) {
+ print "singleton lock: taking\n";
+ $got_lock = $newf;
+ return 1;
+ }
+ else {
+ print "singleton lock: missed the lock\n";
+ unlink $tmpf;
+ return 0;
+ }
+}
+
+sub kill_lock {
+ return unless $got_lock;
+ unlink $got_lock or warn "singleton lock: unlink $got_lock failed: $!";
}


Modified: spamassassin/trunk/masses/rule-qa/automc/RUNME.after
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/masses/rule-qa/automc/RUNME.after?rev=329730&r1=329729&r2=329730&view=diff
==============================================================================
--- spamassassin/trunk/masses/rule-qa/automc/RUNME.after (original)
+++ spamassassin/trunk/masses/rule-qa/automc/RUNME.after Sun Oct 30 20:26:55 2005
@@ -11,8 +11,9 @@
date=date ; [ -x /opt/sfw/bin/gdate ] && date=gdate

# hit-frequencies now requires up-to-date rules to generate valid reports!
-# so we need to do an svn update
-( cd $SADIR ; svn update )
+# so we need to do an svn update, and a make
+# TODO: it'd be nice if hit-frequencies didn't require this.
+( cd $SADIR ; svn update ; perl Makefile.PL ; make ) < /dev/null

# then generate the various forms of 'freqs' files...
$SADIR/masses/rule-qa/corpus-hourly

Modified: spamassassin/trunk/masses/rule-qa/automc/ruleqa.cgi
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/masses/rule-qa/automc/ruleqa.cgi?rev=329730&r1=329729&r2=329730&view=diff
==============================================================================
--- spamassassin/trunk/masses/rule-qa/automc/ruleqa.cgi (original)
+++ spamassassin/trunk/masses/rule-qa/automc/ruleqa.cgi Sun Oct 30 20:26:55 2005
@@ -459,7 +459,7 @@

if ($filename eq 'DETAILS.new') {
# report which sets we used
- summarise_head($freqs_head{$key}, $filename, $strdate, $rule);
+ summarise_head($freqs_head{$filename}, $filename, $strdate, $rule);
}

get_freqs_for_rule($filename, $strdate, $rule);
@@ -469,7 +469,7 @@
my ($head, $filename, $strdate, $rule) = @_;

my @mcfiles = ();
- if ($head =~ / ham results used for \S+ \S+ \S+: (.*)$/) {
+ if ($head =~ /^# ham results used for \S+ \S+ \S+: (.*)$/m) {
@mcfiles = split(' ', $1);
}