Merge "Add $maxAge parameter to MapCacheLRU get() and getField() methods"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 18 Jul 2018 18:25:56 +0000 (18:25 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 18 Jul 2018 18:25:56 +0000 (18:25 +0000)
includes/htmlform/fields/HTMLTitleTextField.php
includes/htmlform/fields/HTMLUserTextField.php
includes/libs/objectcache/WANObjectCache.php
includes/libs/rdbms/database/Database.php

index 602ddee..0ad41d4 100644 (file)
@@ -41,6 +41,11 @@ class HTMLTitleTextField extends HTMLTextField {
                        return parent::validate( $value, $alldata );
                }
 
+               // Default value (from getDefault()) is null, which breaks Title::newFromTextThrow() below
+               if ( $value === null ) {
+                       $value = '';
+               }
+
                if ( !$this->mParams['required'] && $value === '' ) {
                        // If this field is not required and the value is empty, that's okay, skip validation
                        return parent::validate( $value, $alldata );
index e193970..d672314 100644 (file)
@@ -34,6 +34,11 @@ class HTMLUserTextField extends HTMLTextField {
        }
 
        public function validate( $value, $alldata ) {
+               // Default value (from getDefault()) is null, User::newFromName() expects a string
+               if ( $value === null ) {
+                       $value = '';
+               }
+
                // check, if a user exists with the given username
                $user = User::newFromName( $value, false );
                $rangeError = null;
@@ -43,7 +48,7 @@ class HTMLUserTextField extends HTMLTextField {
                } elseif (
                        // check, if the user exists, if requested
                        ( $this->mParams['exists'] && $user->getId() === 0 ) &&
-                       // check, if the username is a valid IP address, otherweise save the error message
+                       // check, if the username is a valid IP address, otherwise save the error message
                        !( $this->mParams['ipallowed'] && IP::isValid( $value ) ) &&
                        // check, if the username is a valid IP range, otherwise save the error message
                        !( $this->mParams['iprange'] && ( $rangeError = $this->isValidIPRange( $value ) ) === true )
index e30e061..2989c81 100644 (file)
@@ -87,7 +87,7 @@ use Psr\Log\NullLogger;
 class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        /** @var BagOStuff The local datacenter cache */
        protected $cache;
-       /** @var HashBagOStuff[] Map of group PHP instance caches */
+       /** @var MapCacheLRU[] Map of group PHP instance caches */
        protected $processCaches = [];
        /** @var string Purge channel name */
        protected $purgeChannel;
@@ -1061,7 +1061,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                if ( $pcTTL >= 0 && $this->callbackDepth == 0 ) {
                        $group = $opts['pcGroup'] ?? self::PC_PRIMARY;
                        $procCache = $this->getProcessCache( $group );
-                       $value = $procCache->get( $key );
+                       $value = $procCache->has( $key, $pcTTL ) ? $procCache->get( $key ) : false;
                } else {
                        $procCache = false;
                        $value = false;
@@ -1117,7 +1117,7 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
 
                        // Update the process cache if enabled
                        if ( $procCache && $value !== false ) {
-                               $procCache->set( $key, $value, $pcTTL );
+                               $procCache->set( $key, $value );
                        }
                }
 
@@ -1385,10 +1385,11 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        ) {
                $valueKeys = array_keys( $keyedIds->getArrayCopy() );
                $checkKeys = $opts['checkKeys'] ?? [];
+               $pcTTL = $opts['pcTTL'] ?? self::TTL_UNCACHEABLE;
 
                // Load required keys into process cache in one go
                $this->warmupCache = $this->getRawKeysForWarmup(
-                       $this->getNonProcessCachedKeys( $valueKeys, $opts ),
+                       $this->getNonProcessCachedKeys( $valueKeys, $opts, $pcTTL ),
                        $checkKeys
                );
                $this->warmupKeyMisses = 0;
@@ -1480,11 +1481,12 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
                $idsByValueKey = $keyedIds->getArrayCopy();
                $valueKeys = array_keys( $idsByValueKey );
                $checkKeys = $opts['checkKeys'] ?? [];
+               $pcTTL = $opts['pcTTL'] ?? self::TTL_UNCACHEABLE;
                unset( $opts['lockTSE'] ); // incompatible
                unset( $opts['busyValue'] ); // incompatible
 
                // Load required keys into process cache in one go
-               $keysGet = $this->getNonProcessCachedKeys( $valueKeys, $opts );
+               $keysGet = $this->getNonProcessCachedKeys( $valueKeys, $opts, $pcTTL );
                $this->warmupCache = $this->getRawKeysForWarmup( $keysGet, $checkKeys );
                $this->warmupKeyMisses = 0;
 
@@ -2103,12 +2105,12 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
 
        /**
         * @param string $group
-        * @return HashBagOStuff
+        * @return MapCacheLRU
         */
        protected function getProcessCache( $group ) {
                if ( !isset( $this->processCaches[$group] ) ) {
                        list( , $n ) = explode( ':', $group );
-                       $this->processCaches[$group] = new HashBagOStuff( [ 'maxKeys' => (int)$n ] );
+                       $this->processCaches[$group] = new MapCacheLRU( (int)$n );
                }
 
                return $this->processCaches[$group];
@@ -2117,15 +2119,16 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface {
        /**
         * @param array $keys
         * @param array $opts
+        * @param int $pcTTL
         * @return array List of keys
         */
-       private function getNonProcessCachedKeys( array $keys, array $opts ) {
+       private function getNonProcessCachedKeys( array $keys, array $opts, $pcTTL ) {
                $keysFound = [];
                if ( isset( $opts['pcTTL'] ) && $opts['pcTTL'] > 0 && $this->callbackDepth == 0 ) {
                        $pcGroup = $opts['pcGroup'] ?? self::PC_PRIMARY;
                        $procCache = $this->getProcessCache( $pcGroup );
                        foreach ( $keys as $key ) {
-                               if ( $procCache->get( $key ) !== false ) {
+                               if ( $procCache->has( $key, $pcTTL ) ) {
                                        $keysFound[] = $key;
                                }
                        }
index d11b51b..dc3260d 100644 (file)
@@ -3844,9 +3844,11 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                $this->assertOpen();
 
                $this->runOnTransactionPreCommitCallbacks();
+
                $writeTime = $this->pendingWriteQueryDuration( self::ESTIMATE_DB_APPLY );
                $this->doCommit( $fname );
                $this->trxStatus = self::STATUS_TRX_NONE;
+
                if ( $this->trxDoneWrites ) {
                        $this->lastWriteTime = microtime( true );
                        $this->trxProfiler->transactionWritingOut(
@@ -3894,14 +3896,18 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware
                        // Avoid fatals if close() was called
                        $this->assertOpen();
 
+                       $writeTime = $this->pendingWriteQueryDuration( self::ESTIMATE_DB_APPLY );
                        $this->doRollback( $fname );
                        $this->trxStatus = self::STATUS_TRX_NONE;
                        $this->trxAtomicLevels = [];
+
                        if ( $this->trxDoneWrites ) {
                                $this->trxProfiler->transactionWritingOut(
                                        $this->server,
                                        $this->dbName,
-                                       $this->trxShortId
+                                       $this->trxShortId,
+                                       $writeTime,
+                                       $this->trxWriteAffectedRows
                                );
                        }
                }