Merge "Avoid master queries on SpecialBlockList"
[lhc/web/wiklou.git] / includes / objectcache / MemcachedPeclBagOStuff.php
index fcc37cb..f2c4928 100644 (file)
@@ -46,6 +46,7 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
         * @throws MWException
         */
        function __construct( $params ) {
+               parent::__construct( $params );
                $params = $this->applyDefaultParams( $params );
 
                if ( $params['persistent'] ) {
@@ -54,7 +55,7 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
                        // We can only reuse a pool ID if we keep the config consistent.
                        $this->client = new Memcached( md5( serialize( $params ) ) );
                        if ( count( $this->client->getServerList() ) ) {
-                               wfDebug( __METHOD__ . ": persistent Memcached object already loaded.\n" );
+                               $this->logger->debug( __METHOD__ . ": persistent Memcached object already loaded." );
                                return; // already initialized; don't add duplicate servers
                        }
                } else {
@@ -120,11 +121,9 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
         * @return mixed
         */
        public function get( $key, &$casToken = null ) {
-               wfProfileIn( __METHOD__ );
                $this->debugLog( "get($key)" );
                $result = $this->client->get( $this->encodeKey( $key ), null, $casToken );
                $result = $this->checkResult( $key, $result );
-               wfProfileOut( __METHOD__ );
                return $result;
        }
 
@@ -146,19 +145,18 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
         * @param int $exptime
         * @return bool
         */
-       public function cas( $casToken, $key, $value, $exptime = 0 ) {
+       protected function cas( $casToken, $key, $value, $exptime = 0 ) {
                $this->debugLog( "cas($key)" );
                return $this->checkResult( $key, parent::cas( $casToken, $key, $value, $exptime ) );
        }
 
        /**
         * @param string $key
-        * @param int $time
         * @return bool
         */
-       public function delete( $key, $time = 0 ) {
+       public function delete( $key ) {
                $this->debugLog( "delete($key)" );
-               $result = parent::delete( $key, $time );
+               $result = parent::delete( $key );
                if ( $result === false && $this->client->getResultCode() === Memcached::RES_NOTFOUND ) {
                        // "Not found" is counted as success in our interface
                        return true;
@@ -225,14 +223,16 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
                                break;
                        default:
                                $msg = $this->client->getResultMessage();
+                               $logCtx = array();
                                if ( $key !== false ) {
                                        $server = $this->client->getServerByKey( $key );
-                                       $serverName = "{$server['host']}:{$server['port']}";
-                                       $msg = "Memcached error for key \"$key\" on server \"$serverName\": $msg";
+                                       $logCtx['memcached-server'] = "{$server['host']}:{$server['port']}";
+                                       $logCtx['memcached-key'] = $key;
+                                       $msg = "Memcached error for key \"{memcached-key}\" on server \"{memcached-server}\": $msg";
                                } else {
                                        $msg = "Memcached error: $msg";
                                }
-                               wfDebugLog( 'memcached-serious', $msg );
+                               $this->logger->error( $msg, $logCtx );
                                $this->setLastError( BagOStuff::ERR_UNEXPECTED );
                }
                return $result;
@@ -243,11 +243,9 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
         * @return array
         */
        public function getMulti( array $keys ) {
-               wfProfileIn( __METHOD__ );
                $this->debugLog( 'getMulti(' . implode( ', ', $keys ) . ')' );
                $callback = array( $this, 'encodeKey' );
                $result = $this->client->getMulti( array_map( $callback, $keys ) );
-               wfProfileOut( __METHOD__ );
                $result = $result ?: array(); // must be an array
                return $this->checkResult( false, $result );
        }
@@ -258,7 +256,6 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
         * @return bool
         */
        public function setMulti( array $data, $exptime = 0 ) {
-               wfProfileIn( __METHOD__ );
                foreach ( $data as $key => $value ) {
                        $encKey = $this->encodeKey( $key );
                        if ( $encKey !== $key ) {
@@ -268,7 +265,6 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
                }
                $this->debugLog( 'setMulti(' . implode( ', ', array_keys( $data ) ) . ')' );
                $result = $this->client->setMulti( $data, $this->fixExpiry( $exptime ) );
-               wfProfileOut( __METHOD__ );
                return $this->checkResult( false, $result );
        }
 }