From c312218534e7d4065a2b474b084f6c5727275707 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 21 Aug 2013 13:20:40 -0700 Subject: [PATCH] Move slow deletion purges out of complex DB transactions * This should help reduce deletion related deadlock errors Change-Id: Ie7cafbf87ab0c71cc6c4c4fe1e53af364974a745 --- includes/filerepo/file/LocalFile.php | 32 +++++++++++++++++----------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 678a6ad27a..39ef62c6e3 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1527,7 +1527,6 @@ class LocalFile extends File { * @return FileRepoStatus object. */ function delete( $reason, $suppress = false ) { - global $wgUseSquid; if ( $this->getRepo()->getReadOnlyReason() !== false ) { return $this->readOnlyFatalStatus(); } @@ -1545,19 +1544,28 @@ class LocalFile extends File { DeferredUpdates::addUpdate( SiteStatsUpdate::factory( array( 'images' => -1 ) ) ); } - $this->purgeEverything(); - foreach ( $archiveNames as $archiveName ) { - $this->purgeOldThumbnails( $archiveName ); - } + // 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. + $file = $this; + $this->getRepo()->getMasterDB()->onTransactionIdle( + function() use ( $file, $archiveNames ) { + global $wgUseSquid; - if ( $wgUseSquid ) { - // Purge the squid - $purgeUrls = array(); - foreach ($archiveNames as $archiveName ) { - $purgeUrls[] = $this->getArchiveUrl( $archiveName ); + $file->purgeEverything(); + foreach ( $archiveNames as $archiveName ) { + $file->purgeOldThumbnails( $archiveName ); + } + + if ( $wgUseSquid ) { + // Purge the squid + $purgeUrls = array(); + foreach ( $archiveNames as $archiveName ) { + $purgeUrls[] = $file->getArchiveUrl( $archiveName ); + } + SquidUpdate::purge( $purgeUrls ); + } } - SquidUpdate::purge( $purgeUrls ); - } + ); return $status; } -- 2.20.1