* 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>";
} #}}}
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 () { #{{{

View File

@ -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;
}
} #}}}

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
[ Joey Hess ]

View File

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 ""