Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/50037


Change subject: [FileRepo] Changed LocalFile locking to avoid breaking 
transactions.
......................................................................

[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.

Change-Id: I9a0adb25ee107df9a6bf70c6103ddfb7f034be25
---
M includes/filerepo/file/LocalFile.php
1 file changed, 8 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/37/50037/1

diff --git a/includes/filerepo/file/LocalFile.php 
b/includes/filerepo/file/LocalFile.php
index ee49448..27386b4 100644
--- a/includes/filerepo/file/LocalFile.php
+++ b/includes/filerepo/file/LocalFile.php
@@ -71,6 +71,7 @@
                $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 @@
                $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 @@
        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 @@
                $this->locked = false;
                $dbw = $this->repo->getMasterDB();
                $dbw->rollback( __METHOD__ );
+               $this->lockedOwnTrx = false;
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/50037
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9a0adb25ee107df9a6bf70c6103ddfb7f034be25
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to