]> sipb.mit.edu Git - ikiwiki.git/commitdiff
* Change the aggregate plugin's locking strategy. Now it defers loading state
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Mon, 21 May 2007 02:52:51 +0000 (02:52 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Mon, 21 May 2007 02:52:51 +0000 (02:52 +0000)
  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
IkiWiki/Plugin/aggregate.pm
debian/changelog
po/ikiwiki.pot

index a0b9027941fd1d7c18ea7d4e50c16f4763532862..31e175d2ac7195ac7f49f80d50f49c0a67dba7e3 100644 (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 () { #{{{
index 78f8b409c1fb01960ba1b66c03989fafd346e08c..082290114fa8a382a133f6cfbcb2d8065c40eaca 100644 (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;
        }
 } #}}}
 
index 10f5ef33f00ac457844daf0e7f9940256c217ab2..87cf87087ac3492a0b5387a3d7d769678177271b 100644 (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 ]
index d1431a9108e14dd7a8d535219f704e9c1f64a811..d23c9d0bdb27681c5e2b1fe84d33f95846bf49a9 100644 (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 ""