Use new ScopedCallback::newScopedIgnoreUserAbort helper function
authorstibba <stevenvandenwildenberg@gmail.com>
Mon, 29 Oct 2018 21:18:29 +0000 (22:18 +0100)
committerKunal Mehta <legoktm@member.fsf.org>
Fri, 2 Nov 2018 00:18:01 +0000 (17:18 -0700)
Introduced in Ib6e307d76f93.

This patch updates FileBackend, LoadBalancer and LBFactory to use a public
function newScopedIgnoreUserAbort in ScopedCallback instead of all using
the exact same function but duplicated.

Bug: T184044
Change-Id: I27d7dc16abfe4b9447d7f3d8bd89f0de3ddeb662

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

index 2852265..27e6924 100644 (file)
@@ -427,7 +427,7 @@ abstract class FileBackend implements LoggerAwareInterface {
                }
 
                /** @noinspection PhpUnusedLocalVariableInspection */
-               $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts
+               $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts
 
                return $this->doOperationsInternal( $ops, $opts );
        }
@@ -665,7 +665,7 @@ abstract class FileBackend implements LoggerAwareInterface {
                }
 
                /** @noinspection PhpUnusedLocalVariableInspection */
-               $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts
+               $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts
 
                return $this->doQuickOperationsInternal( $ops );
        }
@@ -812,7 +812,7 @@ abstract class FileBackend implements LoggerAwareInterface {
                        return $this->newStatus( 'backend-fail-readonly', $this->name, $this->readOnly );
                }
                /** @noinspection PhpUnusedLocalVariableInspection */
-               $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts
+               $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts
                return $this->doPrepare( $params );
        }
 
@@ -843,7 +843,7 @@ abstract class FileBackend implements LoggerAwareInterface {
                        return $this->newStatus( 'backend-fail-readonly', $this->name, $this->readOnly );
                }
                /** @noinspection PhpUnusedLocalVariableInspection */
-               $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts
+               $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts
                return $this->doSecure( $params );
        }
 
@@ -876,7 +876,7 @@ abstract class FileBackend implements LoggerAwareInterface {
                        return $this->newStatus( 'backend-fail-readonly', $this->name, $this->readOnly );
                }
                /** @noinspection PhpUnusedLocalVariableInspection */
-               $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts
+               $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts
                return $this->doPublish( $params );
        }
 
@@ -902,7 +902,7 @@ abstract class FileBackend implements LoggerAwareInterface {
                        return $this->newStatus( 'backend-fail-readonly', $this->name, $this->readOnly );
                }
                /** @noinspection PhpUnusedLocalVariableInspection */
-               $scope = $this->getScopedPHPBehaviorForOps(); // try to ignore client aborts
+               $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts
                return $this->doClean( $params );
        }
 
@@ -912,24 +912,6 @@ abstract class FileBackend implements LoggerAwareInterface {
         */
        abstract protected function doClean( array $params );
 
-       /**
-        * Enter file operation scope.
-        * This just makes PHP ignore user aborts/disconnects until the return
-        * value leaves scope. This returns null and does nothing in CLI mode.
-        *
-        * @return ScopedCallback|null
-        */
-       final protected function getScopedPHPBehaviorForOps() {
-               if ( PHP_SAPI != 'cli' ) { // https://bugs.php.net/bug.php?id=47540
-                       $old = ignore_user_abort( true ); // avoid half-finished operations
-                       return new ScopedCallback( function () use ( $old ) {
-                               ignore_user_abort( $old );
-                       } );
-               }
-
-               return null;
-       }
-
        /**
         * Check if a file exists at a storage path in the backend.
         * This returns false if only a directory exists at the path.
index 1612f41..d213dc9 100644 (file)
@@ -257,7 +257,7 @@ abstract class LBFactory implements ILBFactory {
                        );
                }
                /** @noinspection PhpUnusedLocalVariableInspection */
-               $scope = $this->getScopedPHPBehaviorForCommit(); // try to ignore client aborts
+               $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
@@ -707,23 +707,6 @@ abstract class LBFactory implements ILBFactory {
                }
        }
 
-       /**
-        * Make PHP ignore user aborts/disconnects until the returned
-        * value leaves scope. This returns null and does nothing in CLI mode.
-        *
-        * @return ScopedCallback|null
-        */
-       final protected function getScopedPHPBehaviorForCommit() {
-               if ( PHP_SAPI != 'cli' ) { // https://bugs.php.net/bug.php?id=47540
-                       $old = ignore_user_abort( true ); // avoid half-finished operations
-                       return new ScopedCallback( function () use ( $old ) {
-                               ignore_user_abort( $old );
-                       } );
-               }
-
-               return null;
-       }
-
        function __destruct() {
                $this->destroy();
        }
index b2b2391..7721707 100644 (file)
@@ -1395,7 +1395,7 @@ class LoadBalancer implements ILoadBalancer {
                $failures = [];
 
                /** @noinspection PhpUnusedLocalVariableInspection */
-               $scope = $this->getScopedPHPBehaviorForCommit(); // try to ignore client aborts
+               $scope = ScopedCallback::newScopedIgnoreUserAbort(); // try to ignore client aborts
 
                $restore = ( $this->trxRoundId !== false );
                $this->trxRoundId = false;
@@ -1960,23 +1960,6 @@ class LoadBalancer implements ILoadBalancer {
                }
        }
 
-       /**
-        * Make PHP ignore user aborts/disconnects until the returned
-        * value leaves scope. This returns null and does nothing in CLI mode.
-        *
-        * @return ScopedCallback|null
-        */
-       final protected function getScopedPHPBehaviorForCommit() {
-               if ( PHP_SAPI != 'cli' ) { // https://bugs.php.net/bug.php?id=47540
-                       $old = ignore_user_abort( true ); // avoid half-finished operations
-                       return new ScopedCallback( function () use ( $old ) {
-                               ignore_user_abort( $old );
-                       } );
-               }
-
-               return null;
-       }
-
        function __destruct() {
                // Avoid connection leaks for sanity
                $this->disable();