From 4c26684de5b7952317b40bf34df182c2dec6ea2a Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 20 Feb 2013 11:28:27 -0800 Subject: [PATCH] [FileRepo] Changed LocalFile locking to avoid breaking transactions. * Only BEGIN on lock() if no trx was in progress. Likewise, only COMMIT in unlock() if the lock() call started a trx. * This can avoid problems with commiting page update transactions prematurely, which could leave broken page stub rows. (bug 40178) Change-Id: I9a0adb25ee107df9a6bf70c6103ddfb7f034be25 --- includes/filerepo/file/LocalFile.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index ee4944860b..27386b4af6 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -71,6 +71,7 @@ class LocalFile extends File { $extraDataLoaded, # Whether or not lazy-loaded data has been loaded from the database $upgraded, # Whether the row was upgraded on load $locked, # True if the image row is locked + $lockedOwnTrx, # True if the image row is locked with a lock initiated transaction $missing, # True if file is not present in file system. Not to be cached in memcached $deleted; # Bitfield akin to rev_deleted @@ -1669,7 +1670,10 @@ class LocalFile extends File { $dbw = $this->repo->getMasterDB(); if ( !$this->locked ) { - $dbw->begin( __METHOD__ ); + if ( !$dbw->trxLevel() ) { + $dbw->begin( __METHOD__ ); + $this->lockedOwnTrx = true; + } $this->locked++; } @@ -1684,9 +1688,10 @@ class LocalFile extends File { function unlock() { if ( $this->locked ) { --$this->locked; - if ( !$this->locked ) { + if ( !$this->locked && $this->lockedOwnTrx ) { $dbw = $this->repo->getMasterDB(); $dbw->commit( __METHOD__ ); + $this->lockedOwnTrx = false; } } } @@ -1698,6 +1703,7 @@ class LocalFile extends File { $this->locked = false; $dbw = $this->repo->getMasterDB(); $dbw->rollback( __METHOD__ ); + $this->lockedOwnTrx = false; } /** -- 2.20.1