* 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.
master
joey 2007-05-21 02:52:51 +00:00
parent 07a1796d3b
commit 82ac63d798
4 changed files with 52 additions and 27 deletions

View File

@ -668,7 +668,8 @@ sub indexlink () { #{{{
return "<a href=\"$config{url}\">$config{wikiname}</a>"; return "<a href=\"$config{url}\">$config{wikiname}</a>";
} #}}} } #}}}
sub lockwiki () { #{{{ sub lockwiki (;$) { #{{{
my $wait=@_ ? shift : 1;
# Take an exclusive lock on the wiki to prevent multiple concurrent # Take an exclusive lock on the wiki to prevent multiple concurrent
# run issues. The lock will be dropped on program exit. # run issues. The lock will be dropped on program exit.
if (! -d $config{wikistatedir}) { if (! -d $config{wikistatedir}) {
@ -677,6 +678,7 @@ sub lockwiki () { #{{{
open(WIKILOCK, ">$config{wikistatedir}/lockfile") || open(WIKILOCK, ">$config{wikistatedir}/lockfile") ||
error ("cannot write to $config{wikistatedir}/lockfile: $!"); error ("cannot write to $config{wikistatedir}/lockfile: $!");
if (! flock(WIKILOCK, 2 | 4)) { # LOCK_EX | LOCK_NB if (! flock(WIKILOCK, 2 | 4)) { # LOCK_EX | LOCK_NB
if ($wait) {
debug("wiki seems to be locked, waiting for lock"); debug("wiki seems to be locked, waiting for lock");
my $wait=600; # arbitrary, but don't hang forever to my $wait=600; # arbitrary, but don't hang forever to
# prevent process pileup # prevent process pileup
@ -686,6 +688,12 @@ sub lockwiki () { #{{{
} }
error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)"); error("wiki is locked; waited $wait seconds without lock being freed (possible stuck process or stale lock?)");
} }
else {
debug("wiki is locked");
return 0;
}
}
return 1;
} #}}} } #}}}
sub unlockwiki () { #{{{ sub unlockwiki () { #{{{

View File

@ -31,22 +31,26 @@ sub getopt () { #{{{
} #}}} } #}}}
sub checkconfig () { #{{{ sub checkconfig () { #{{{
my $nolock=($config{post_commit} && ! IkiWiki::commit_hook_enabled()); if ($config{aggregate} && ! ($config{post_commit} &&
IkiWiki::lockwiki() unless $nolock; IkiWiki::commit_hook_enabled())) {
# don't wait for the lock
IkiWiki::lockwiki(0) || exit 1;
loadstate(); loadstate();
if ($config{aggregate} && ! $nolock) {
IkiWiki::loadindex(); IkiWiki::loadindex();
aggregate(); aggregate();
expire(); expire();
savestate(); savestate();
IkiWiki::unlockwiki();
} }
IkiWiki::unlockwiki() unless $nolock;
} #}}} } #}}}
sub filter (@) { #{{{ sub filter (@) { #{{{
my %params=@_; my %params=@_;
my $page=$params{page}; my $page=$params{page};
loadstate(); # if not already loaded
# Mark all feeds originating on this page as removable; # Mark all feeds originating on this page as removable;
# preprocess will unmark those that still exist. # preprocess will unmark those that still exist.
remove_feeds($page); remove_feeds($page);
@ -117,7 +121,9 @@ sub delete (@) { #{{{
} }
} #}}} } #}}}
my $state_loaded=0;
sub loadstate () { #{{{ sub loadstate () { #{{{
return if $state_loaded;
if (-e "$config{wikistatedir}/aggregate") { if (-e "$config{wikistatedir}/aggregate") {
open (IN, "$config{wikistatedir}/aggregate" || open (IN, "$config{wikistatedir}/aggregate" ||
die "$config{wikistatedir}/aggregate: $!"); die "$config{wikistatedir}/aggregate: $!");
@ -148,6 +154,8 @@ sub loadstate () { #{{{
} }
close IN; close IN;
$state_loaded=1;
} }
} #}}} } #}}}

9
debian/changelog vendored
View File

@ -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 <joeyh@debian.org> Sun, 20 May 2007 22:23:09 -0400
ikiwiki (2.1) unstable; urgency=low ikiwiki (2.1) unstable; urgency=low
[ Joey Hess ] [ Joey Hess ]

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -67,62 +67,62 @@ msgstr ""
msgid "login failed, perhaps you need to turn on cookies?" msgid "login failed, perhaps you need to turn on cookies?"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:62 #: ../IkiWiki/Plugin/aggregate.pm:66
#, perl-format #, perl-format
msgid "missing %s parameter" msgid "missing %s parameter"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:90 #: ../IkiWiki/Plugin/aggregate.pm:94
msgid "new feed" msgid "new feed"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:104 #: ../IkiWiki/Plugin/aggregate.pm:108
msgid "posts" msgid "posts"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:106 #: ../IkiWiki/Plugin/aggregate.pm:110
msgid "new" msgid "new"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:212 #: ../IkiWiki/Plugin/aggregate.pm:220
#, perl-format #, perl-format
msgid "expiring %s (%s days old)" msgid "expiring %s (%s days old)"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:219 #: ../IkiWiki/Plugin/aggregate.pm:227
#, perl-format #, perl-format
msgid "expiring %s" msgid "expiring %s"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:242 #: ../IkiWiki/Plugin/aggregate.pm:250
#, perl-format #, perl-format
msgid "processed ok at %s" msgid "processed ok at %s"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:247 #: ../IkiWiki/Plugin/aggregate.pm:255
#, perl-format #, perl-format
msgid "checking feed %s ..." msgid "checking feed %s ..."
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:252 #: ../IkiWiki/Plugin/aggregate.pm:260
#, perl-format #, perl-format
msgid "could not find feed at %s" msgid "could not find feed at %s"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:267 #: ../IkiWiki/Plugin/aggregate.pm:275
msgid "feed not found" msgid "feed not found"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:278 #: ../IkiWiki/Plugin/aggregate.pm:286
#, perl-format #, perl-format
msgid "(invalid UTF-8 stripped from feed)" msgid "(invalid UTF-8 stripped from feed)"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:283 #: ../IkiWiki/Plugin/aggregate.pm:291
msgid "feed crashed XML::Feed!" msgid "feed crashed XML::Feed!"
msgstr "" msgstr ""
#: ../IkiWiki/Plugin/aggregate.pm:356 #: ../IkiWiki/Plugin/aggregate.pm:364
#, perl-format #, perl-format
msgid "creating new page %s" msgid "creating new page %s"
msgstr "" msgstr ""