rdbms: add more ScopedCallback::newScopedIgnoreUserAbort() calls
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 30 Aug 2019 04:53:38 +0000 (21:53 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 30 Aug 2019 05:11:38 +0000 (22:11 -0700)
Place more calls in LBFactory and un-owned LoadBalancer instances

Bug: T231443
Change-Id: Id93e70ada114801efe3aa81e865f0a930489bd29

includes/libs/rdbms/lbfactory/LBFactory.php
includes/libs/rdbms/loadbalancer/LoadBalancer.php

index 77467f0..36e961a 100644 (file)
@@ -160,6 +160,9 @@ abstract class LBFactory implements ILBFactory {
        }
 
        public function destroy() {
+               /** @noinspection PhpUnusedLocalVariableInspection */
+               $scope = ScopedCallback::newScopedIgnoreUserAbort();
+
                $this->forEachLBCallMethod( 'disable' );
        }
 
@@ -177,6 +180,9 @@ abstract class LBFactory implements ILBFactory {
                &$cpIndex = null,
                &$cpClientId = null
        ) {
+               /** @noinspection PhpUnusedLocalVariableInspection */
+               $scope = ScopedCallback::newScopedIgnoreUserAbort();
+
                $chronProt = $this->getChronologyProtector();
                if ( $mode === self::SHUTDOWN_CHRONPROT_SYNC ) {
                        $this->shutdownChronologyProtector( $chronProt, $workCallback, 'sync', $cpIndex );
@@ -250,6 +256,9 @@ abstract class LBFactory implements ILBFactory {
 
        final public function beginMasterChanges( $fname = __METHOD__ ) {
                $this->assertTransactionRoundStage( self::ROUND_CURSORY );
+               /** @noinspection PhpUnusedLocalVariableInspection */
+               $scope = ScopedCallback::newScopedIgnoreUserAbort();
+
                $this->trxRoundStage = self::ROUND_BEGINNING;
                if ( $this->trxRoundId !== false ) {
                        throw new DBTransactionError(
@@ -265,6 +274,9 @@ abstract class LBFactory implements ILBFactory {
 
        final public function commitMasterChanges( $fname = __METHOD__, array $options = [] ) {
                $this->assertTransactionRoundStage( self::ROUND_CURSORY );
+               /** @noinspection PhpUnusedLocalVariableInspection */
+               $scope = ScopedCallback::newScopedIgnoreUserAbort();
+
                $this->trxRoundStage = self::ROUND_COMMITTING;
                if ( $this->trxRoundId !== false && $this->trxRoundId !== $fname ) {
                        throw new DBTransactionError(
@@ -272,8 +284,6 @@ abstract class LBFactory implements ILBFactory {
                                "$fname: transaction round '{$this->trxRoundId}' still running"
                        );
                }
-               /** @noinspection PhpUnusedLocalVariableInspection */
-               $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts
                // Run pre-commit callbacks and suppress post-commit callbacks, aborting on failure
                do {
                        $count = 0; // number of callbacks executed this iteration
@@ -299,6 +309,9 @@ abstract class LBFactory implements ILBFactory {
        }
 
        final public function rollbackMasterChanges( $fname = __METHOD__ ) {
+               /** @noinspection PhpUnusedLocalVariableInspection */
+               $scope = ScopedCallback::newScopedIgnoreUserAbort();
+
                $this->trxRoundStage = self::ROUND_ROLLING_BACK;
                $this->trxRoundId = false;
                // Actually perform the rollback on all master DB connections and revert DBO_TRX
@@ -673,6 +686,9 @@ abstract class LBFactory implements ILBFactory {
        }
 
        public function closeAll() {
+               /** @noinspection PhpUnusedLocalVariableInspection */
+               $scope = ScopedCallback::newScopedIgnoreUserAbort();
+
                $this->forEachLBCallMethod( 'closeAll' );
        }
 
index 066d4b4..585a782 100644 (file)
@@ -1498,6 +1498,11 @@ class LoadBalancer implements ILoadBalancer {
        }
 
        public function closeAll() {
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
+
                $fname = __METHOD__;
                $this->forEachOpenConnection( function ( IDatabase $conn ) use ( $fname ) {
                        $host = $conn->getServer();
@@ -1544,6 +1549,10 @@ class LoadBalancer implements ILoadBalancer {
        public function finalizeMasterChanges( $fname = __METHOD__, $owner = null ) {
                $this->assertOwnership( $fname, $owner );
                $this->assertTransactionRoundStage( [ self::ROUND_CURSORY, self::ROUND_FINALIZED ] );
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
 
                $this->trxRoundStage = self::ROUND_ERROR; // "failed" until proven otherwise
                // Loop until callbacks stop adding callbacks on other connections
@@ -1569,6 +1578,10 @@ class LoadBalancer implements ILoadBalancer {
        public function approveMasterChanges( array $options, $fname = __METHOD__, $owner = null ) {
                $this->assertOwnership( $fname, $owner );
                $this->assertTransactionRoundStage( self::ROUND_FINALIZED );
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
 
                $limit = $options['maxWriteDuration'] ?? 0;
 
@@ -1609,6 +1622,10 @@ class LoadBalancer implements ILoadBalancer {
                        );
                }
                $this->assertTransactionRoundStage( self::ROUND_CURSORY );
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
 
                // Clear any empty transactions (no writes/callbacks) from the implicit round
                $this->flushMasterSnapshots( $fname );
@@ -1628,12 +1645,13 @@ class LoadBalancer implements ILoadBalancer {
        public function commitMasterChanges( $fname = __METHOD__, $owner = null ) {
                $this->assertOwnership( $fname, $owner );
                $this->assertTransactionRoundStage( self::ROUND_APPROVED );
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
 
                $failures = [];
 
-               /** @noinspection PhpUnusedLocalVariableInspection */
-               $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts
-
                $restore = ( $this->trxRoundId !== false );
                $this->trxRoundId = false;
                $this->trxRoundStage = self::ROUND_ERROR; // "failed" until proven otherwise
@@ -1676,6 +1694,10 @@ class LoadBalancer implements ILoadBalancer {
                                "Transaction should be in the callback stage (not '{$this->trxRoundStage}')"
                        );
                }
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
 
                $oldStage = $this->trxRoundStage;
                $this->trxRoundStage = self::ROUND_ERROR; // "failed" until proven otherwise
@@ -1746,6 +1768,10 @@ class LoadBalancer implements ILoadBalancer {
                                "Transaction should be in the callback stage (not '{$this->trxRoundStage}')"
                        );
                }
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
 
                $e = null;
 
@@ -1764,6 +1790,10 @@ class LoadBalancer implements ILoadBalancer {
 
        public function rollbackMasterChanges( $fname = __METHOD__, $owner = null ) {
                $this->assertOwnership( $fname, $owner );
+               if ( $this->ownerId === null ) {
+                       /** @noinspection PhpUnusedLocalVariableInspection */
+                       $scope = ScopedCallback::newScopedIgnoreUserAbort();
+               }
 
                $restore = ( $this->trxRoundId !== false );
                $this->trxRoundId = false;