Merge "Do not auto-reconnect to DBs if named locks where lost"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 30 Jan 2016 18:07:35 +0000 (18:07 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 30 Jan 2016 18:07:35 +0000 (18:07 +0000)
1  2 
includes/db/Database.php

diff --combined includes/db/Database.php
@@@ -155,6 -155,9 +155,9 @@@ abstract class DatabaseBase implements 
         */
        private $mTrxWriteDuration = 0.0;
  
+       /** @var array Map of (name => 1) for locks obtained via lock() */
+       private $mNamedLocksHeld = array();
        /** @var IDatabase|null Lazy handle to the master DB this server replicates from */
        private $lazyMasterHandle;
  
                                $msg = __METHOD__ . ": lost connection to $server; reconnected";
                                wfDebugLog( 'DBPerformance', "$msg:\n" . wfBacktrace( true ) );
  
-                               if ( $hadTrx ) {
+                               if ( $hadTrx || $this->mNamedLocksHeld ) {
                                        # Leave $ret as false and let an error be reported.
                                        # Callers may catch the exception and continue to use the DB.
                                        $this->reportQueryError( $lastError, $lastErrno, $sql, $fname, $tempIgnore );
        }
  
        public function lock( $lockName, $method, $timeout = 5 ) {
+               $this->mNamedLocksHeld[$lockName] = 1;
                return true;
        }
  
        public function unlock( $lockName, $method ) {
+               unset( $this->mNamedLocksHeld[$lockName] );
                return true;
        }
  
  
                $that = $this;
                $unlocker = new ScopedCallback( function () use ( $that, $lockKey, $fname ) {
 +                      $that->commit( __METHOD__, 'flush' );
                        $that->unlock( $lockKey, $fname );
                } );