Reduce excess lock contention and chance for failure on rename
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 17 Oct 2013 18:35:00 +0000 (11:35 -0700)
committerBryanDavis <bdavis@wikimedia.org>
Fri, 18 Oct 2013 20:16:21 +0000 (20:16 +0000)
* DB locks and transactions were getting held up by sometimes slow purges (10+ seconds)

Change-Id: I0eead60e8faf5aee6b2ddf59cfdd928f9c8083ff

includes/filerepo/file/LocalFile.php

index 0c34f3e..fe769be 100644 (file)
@@ -1507,18 +1507,27 @@ class LocalFile extends File {
 
                wfDebugLog( 'imagemove', "Finished moving {$this->name}" );
 
-               $this->purgeEverything();
-               foreach ( $archiveNames as $archiveName ) {
-                       $this->purgeOldThumbnails( $archiveName );
-               }
+               // Purge the source and target files...
+               $oldTitleFile = wfLocalFile( $this->title );
+               $newTitleFile = wfLocalFile( $target );
+               // Hack: the lock()/unlock() pair is nested in a transaction so the locking is not
+               // tied to BEGIN/COMMIT. To avoid slow purges in the transaction, move them outside.
+               $this->getRepo()->getMasterDB()->onTransactionIdle(
+                       function() use ( $oldTitleFile, $newTitleFile, $archiveNames ) {
+                               $oldTitleFile->purgeEverything();
+                               foreach ( $archiveNames as $archiveName ) {
+                                       $oldTitleFile->purgeOldThumbnails( $archiveName );
+                               }
+                               $newTitleFile->purgeEverything();
+                       }
+               );
+
                if ( $status->isOK() ) {
                        // Now switch the object
                        $this->title = $target;
                        // Force regeneration of the name and hashpath
                        unset( $this->name );
                        unset( $this->hashPath );
-                       // Purge the new image
-                       $this->purgeEverything();
                }
 
                return $status;