From 82ac63d798cc7f45a42e14bc2ad05a9388e25a04 Mon Sep 17 00:00:00 2001 From: joey Date: Mon, 21 May 2007 02:52:51 +0000 Subject: [PATCH] * Change the aggregate plugin's locking strategy. Now it defers loading state until the wiki is building and already locked, unless it's aggregating. When aggregating, it does not wait for the lock if it cannot get it, and instead exits, to prevent aggregating processes from piling up. --- IkiWiki.pm | 24 ++++++++++++++++-------- IkiWiki/Plugin/aggregate.pm | 18 +++++++++++++----- debian/changelog | 9 +++++++++ po/ikiwiki.pot | 28 ++++++++++++++-------------- 4 files changed, 52 insertions(+), 27 deletions(-) diff --git a/IkiWiki.pm b/IkiWiki.pm index a0b902794..31e175d2a 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -668,7 +668,8 @@ sub indexlink () { #{{{ return "$config{wikiname}"; } #}}} -sub lockwiki () { #{{{ +sub lockwiki (;$) { #{{{ + my $wait=@_ ? shift : 1; # Take an exclusive lock on the wiki to prevent multiple concurrent # run issues. The lock will be dropped on program exit. if (! -d $config{wikistatedir}) { @@ -677,15 +678,22 @@ sub lockwiki () { #{{{ open(WIKILOCK, ">$config{wikistatedir}/lockfile") || error ("cannot write to $config{wikistatedir}/lockfile: $!"); if (! flock(WIKILOCK, 2 | 4)) { # LOCK_EX | LOCK_NB - debug("wiki seems to be locked, waiting for lock"); - my $wait=600; # arbitrary, but don't hang forever to - # prevent process pileup - for (1..$wait) { - return if flock(WIKILOCK, 2 | 4); - sleep 1; + if ($wait) { + debug("wiki seems to be locked, waiting for lock"); + my $wait=600; # arbitrary, but don't hang forever to + # prevent process pileup + for (1..$wait) { + return if flock(WIKILOCK, 2 | 4); + sleep 1; + } + error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)"); + } + else { + debug("wiki is locked"); + return 0; } - error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)"); } + return 1; } #}}} sub unlockwiki () { #{{{ diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm index 78f8b409c..082290114 100644 --- a/IkiWiki/Plugin/aggregate.pm +++ b/IkiWiki/Plugin/aggregate.pm @@ -31,22 +31,26 @@ sub getopt () { #{{{ } #}}} sub checkconfig () { #{{{ - my $nolock=($config{post_commit} && ! IkiWiki::commit_hook_enabled()); - IkiWiki::lockwiki() unless $nolock; - loadstate(); - if ($config{aggregate} && ! $nolock) { + if ($config{aggregate} && ! ($config{post_commit} && + IkiWiki::commit_hook_enabled())) { + # don't wait for the lock + IkiWiki::lockwiki(0) || exit 1; + + loadstate(); IkiWiki::loadindex(); aggregate(); expire(); savestate(); + + IkiWiki::unlockwiki(); } - IkiWiki::unlockwiki() unless $nolock; } #}}} sub filter (@) { #{{{ my %params=@_; my $page=$params{page}; + loadstate(); # if not already loaded # Mark all feeds originating on this page as removable; # preprocess will unmark those that still exist. remove_feeds($page); @@ -117,7 +121,9 @@ sub delete (@) { #{{{ } } #}}} +my $state_loaded=0; sub loadstate () { #{{{ + return if $state_loaded; if (-e "$config{wikistatedir}/aggregate") { open (IN, "$config{wikistatedir}/aggregate" || die "$config{wikistatedir}/aggregate: $!"); @@ -148,6 +154,8 @@ sub loadstate () { #{{{ } close IN; + + $state_loaded=1; } } #}}} diff --git a/debian/changelog b/debian/changelog index 10f5ef33f..87cf87087 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +ikiwiki (2.2) UNRELEASED; urgency=low + + * Change the aggregate plugin's locking strategy. Now it defers loading state + until the wiki is building and already locked, unless it's aggregating. + When aggregating, it does not wait for the lock if it cannot get it, and + instead exits, to prevent aggregating processes from piling up. + + -- Joey Hess Sun, 20 May 2007 22:23:09 -0400 + ikiwiki (2.1) unstable; urgency=low [ Joey Hess ] diff --git a/po/ikiwiki.pot b/po/ikiwiki.pot index d1431a910..d23c9d0bd 100644 --- a/po/ikiwiki.pot +++ b/po/ikiwiki.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2007-05-19 19:33-0400\n" +"POT-Creation-Date: 2007-05-20 22:48-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -67,62 +67,62 @@ msgstr "" msgid "login failed, perhaps you need to turn on cookies?" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:62 +#: ../IkiWiki/Plugin/aggregate.pm:66 #, perl-format msgid "missing %s parameter" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:90 +#: ../IkiWiki/Plugin/aggregate.pm:94 msgid "new feed" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:104 +#: ../IkiWiki/Plugin/aggregate.pm:108 msgid "posts" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:106 +#: ../IkiWiki/Plugin/aggregate.pm:110 msgid "new" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:212 +#: ../IkiWiki/Plugin/aggregate.pm:220 #, perl-format msgid "expiring %s (%s days old)" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:219 +#: ../IkiWiki/Plugin/aggregate.pm:227 #, perl-format msgid "expiring %s" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:242 +#: ../IkiWiki/Plugin/aggregate.pm:250 #, perl-format msgid "processed ok at %s" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:247 +#: ../IkiWiki/Plugin/aggregate.pm:255 #, perl-format msgid "checking feed %s ..." msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:252 +#: ../IkiWiki/Plugin/aggregate.pm:260 #, perl-format msgid "could not find feed at %s" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:267 +#: ../IkiWiki/Plugin/aggregate.pm:275 msgid "feed not found" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:278 +#: ../IkiWiki/Plugin/aggregate.pm:286 #, perl-format msgid "(invalid UTF-8 stripped from feed)" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:283 +#: ../IkiWiki/Plugin/aggregate.pm:291 msgid "feed crashed XML::Feed!" msgstr "" -#: ../IkiWiki/Plugin/aggregate.pm:356 +#: ../IkiWiki/Plugin/aggregate.pm:364 #, perl-format msgid "creating new page %s" msgstr "" -- 2.32.0.93.g670b81a890