Merge "Cleaned up $asyncWrites member variable in MultiWriteBagOStuff"
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 21 Sep 2015 18:55:15 +0000 (18:55 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 21 Sep 2015 18:55:15 +0000 (18:55 +0000)
1  2 
includes/objectcache/MultiWriteBagOStuff.php

@@@ -32,9 -32,7 +32,7 @@@ class MultiWriteBagOStuff extends BagOS
        /** @var BagOStuff[] */
        protected $caches;
        /** @var bool Use async secondary writes */
-       protected $asyncReplication = false;
-       /** @var array[] */
-       protected $asyncWrites = array();
+       protected $asyncWrites = false;
  
        /**
         * $params include:
@@@ -61,8 -59,8 +59,8 @@@
        public function __construct( $params ) {
                parent::__construct( $params );
  
 -              if ( !isset( $params['caches'] ) ) {
 -                      throw new InvalidArgumentException( __METHOD__ . ': "caches" parameter required' );
 +              if ( empty( $params['caches'] ) || !is_array( $params['caches'] ) ) {
 +                      throw new InvalidArgumentException( __METHOD__ . ': "caches" parameter must be an array of caches' );
                }
  
                $this->caches = array();
@@@ -72,9 -70,7 +70,7 @@@
                                : ObjectCache::newFromParams( $cacheInfo );
                }
  
-               if ( isset( $params['replication'] ) && $params['replication'] === 'async' ) {
-                       $this->asyncReplication = true;
-               }
+               $this->asyncWrites = isset( $params['replication'] ) && $params['replication'] === 'async';
        }
  
        /**
         */
        public function lock( $key, $timeout = 6, $expiry = 6, $rclass = '' ) {
                // Lock only the first cache, to avoid deadlocks
 -              if ( isset( $this->caches[0] ) ) {
 -                      return $this->caches[0]->lock( $key, $timeout, $expiry, $rclass );
 -              } else {
 -                      return true;
 -              }
 +              return $this->caches[0]->lock( $key, $timeout, $expiry, $rclass );
        }
  
        /**
         * @return bool
         */
        public function unlock( $key ) {
 -              if ( isset( $this->caches[0] ) ) {
 -                      return $this->caches[0]->unlock( $key );
 -              } else {
 -                      return true;
 -              }
 +              return $this->caches[0]->unlock( $key );
        }
  
        /**
        }
  
        public function getLastError() {
 -              return isset( $this->caches[0] ) ? $this->caches[0]->getLastError() : self::ERR_NONE;
 +              return $this->caches[0]->getLastError();
        }
  
        public function clearLastError() {
 -              if ( isset( $this->caches[0] ) ) {
 -                      $this->caches[0]->clearLastError();
 -              }
 +              $this->caches[0]->clearLastError();
        }
  
        /**
                array_shift( $args );
  
                foreach ( $this->caches as $i => $cache ) {
-                       if ( $i == 0 || !$this->asyncReplication ) {
+                       if ( $i == 0 || !$this->asyncWrites ) {
                                // First store or in sync mode: write now and get result
                                if ( !call_user_func_array( array( $cache, $method ), $args ) ) {
                                        $ret = false;
                                // Secondary write in async mode: do not block this HTTP request
                                $logger = $this->logger;
                                DeferredUpdates::addCallableUpdate(
 -                                      function() use ( $cache, $method, $args, $logger ) {
 +                                      function () use ( $cache, $method, $args, $logger ) {
                                                if ( !call_user_func_array( array( $cache, $method ), $args ) ) {
                                                        $logger->warning( "Async $method op failed" );
                                                }