From 02a5f968dfbdd744c2d53bc82a4ed3c87dc5a1e2 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 2 Apr 2015 12:33:30 -0700 Subject: [PATCH] Made rollbackMasterChanges catch exceptions, throwing the last one Change-Id: Ida36a302b35434d1af464cb77a0084ec441d038a --- includes/db/LoadBalancer.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index 48c636e484..d9584e147b 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -978,7 +978,6 @@ class LoadBalancer { * Issue COMMIT only on master, only if queries were done on connection */ public function commitMasterChanges() { - // Always 0, but who knows.. :) $masterIndex = $this->getWriterIndex(); foreach ( $this->mConns as $conns2 ) { if ( empty( $conns2[$masterIndex] ) ) { @@ -998,7 +997,8 @@ class LoadBalancer { * @since 1.23 */ public function rollbackMasterChanges() { - // Always 0, but who knows.. :) + $failedServers = array(); + $masterIndex = $this->getWriterIndex(); foreach ( $this->mConns as $conns2 ) { if ( empty( $conns2[$masterIndex] ) ) { @@ -1007,10 +1007,20 @@ class LoadBalancer { /** @var DatabaseBase $conn */ foreach ( $conns2[$masterIndex] as $conn ) { if ( $conn->trxLevel() && $conn->writesOrCallbacksPending() ) { - $conn->rollback( __METHOD__, 'flush' ); + try { + $conn->rollback( __METHOD__, 'flush' ); + } catch ( DBError $e ) { + MWExceptionHandler::logException( $e ); + $failedServers[] = $conn->getServer(); + } } } } + + if ( $failedServers ) { + throw new DBExpectedError( null, "Rollback failed on server(s) " . + implode( ', ', array_unique( $failedServers ) ) ); + } } /** @@ -1027,7 +1037,6 @@ class LoadBalancer { * @return bool */ public function hasMasterChanges() { - // Always 0, but who knows.. :) $masterIndex = $this->getWriterIndex(); foreach ( $this->mConns as $conns2 ) { if ( empty( $conns2[$masterIndex] ) ) { @@ -1050,7 +1059,6 @@ class LoadBalancer { */ public function lastMasterChangeTimestamp() { $lastTime = false; - // Always 0, but who knows.. :) $masterIndex = $this->getWriterIndex(); foreach ( $this->mConns as $conns2 ) { if ( empty( $conns2[$masterIndex] ) ) { -- 2.20.1