Merge "objectcache: rename getDB() to getConnection() in SqlBagOStuff"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 24 Aug 2019 20:57:17 +0000 (20:57 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 24 Aug 2019 20:57:17 +0000 (20:57 +0000)
1  2 
includes/objectcache/SqlBagOStuff.php

@@@ -22,7 -22,6 +22,7 @@@
   */
  
  use MediaWiki\MediaWikiServices;
 +use Wikimedia\AtEase\AtEase;
  use Wikimedia\Rdbms\Database;
  use Wikimedia\Rdbms\IDatabase;
  use Wikimedia\Rdbms\DBError;
@@@ -170,7 -169,7 +170,7 @@@ class SqlBagOStuff extends MediumSpecif
         * @return IMaintainableDatabase
         * @throws MWException
         */
-       private function getDB( $shardIndex ) {
+       private function getConnection( $shardIndex ) {
                if ( $shardIndex >= $this->numServerShards ) {
                        throw new MWException( __METHOD__ . ": Invalid server index \"$shardIndex\"" );
                }
                $dataRows = [];
                foreach ( $keysByTable as $shardIndex => $serverKeys ) {
                        try {
-                               $db = $this->getDB( $shardIndex );
+                               $db = $this->getConnection( $shardIndex );
                                foreach ( $serverKeys as $tableName => $tableKeys ) {
                                        $res = $db->select( $tableName,
                                                [ 'keyname', 'value', 'exptime' ],
                                $this->debug( "get: retrieved data; expiry time is " . $row->exptime );
                                $db = null; // in case of connection failure
                                try {
-                                       $db = $this->getDB( $row->shardIndex );
+                                       $db = $this->getConnection( $row->shardIndex );
                                        if ( $this->isExpired( $db, $row->exptime ) ) { // MISS
                                                $this->debug( "get: key has expired" );
                                        } else { // HIT
                foreach ( $keysByTable as $shardIndex => $serverKeys ) {
                        $db = null; // in case of connection failure
                        try {
-                               $db = $this->getDB( $shardIndex );
+                               $db = $this->getConnection( $shardIndex );
                                $this->occasionallyGarbageCollect( $db ); // expire old entries if any
                                $dbExpiry = $exptime ? $db->timestamp( $exptime ) : $this->getMaxDateTime( $db );
                        } catch ( DBError $e ) {
                $silenceScope = $this->silenceTransactionProfiler();
                $db = null; // in case of connection failure
                try {
-                       $db = $this->getDB( $shardIndex );
+                       $db = $this->getConnection( $shardIndex );
                        // (T26425) use a replace if the db supports it instead of
                        // delete/insert to avoid clashes with conflicting keynames
                        $db->update(
                return $this->modifyMulti( [ $key => null ], 0, $flags, self::$OP_DELETE );
        }
  
 -      public function incr( $key, $step = 1 ) {
 +      public function incr( $key, $step = 1, $flags = 0 ) {
                list( $shardIndex, $tableName ) = $this->getTableByKey( $key );
  
                $newCount = false;
                $silenceScope = $this->silenceTransactionProfiler();
                $db = null; // in case of connection failure
                try {
-                       $db = $this->getDB( $shardIndex );
+                       $db = $this->getConnection( $shardIndex );
                        $encTimestamp = $db->addQuotes( $db->timestamp() );
                        $db->update(
                                $tableName,
                return $newCount;
        }
  
 +      public function decr( $key, $value = 1, $flags = 0 ) {
 +              return $this->incr( $key, -$value, $flags );
 +      }
 +
        public function changeTTLMulti( array $keys, $exptime, $flags = 0 ) {
                return $this->modifyMulti(
                        array_fill_keys( $keys, null ),
                foreach ( $shardIndexes as $numServersDone => $shardIndex ) {
                        $db = null; // in case of connection failure
                        try {
-                               $db = $this->getDB( $shardIndex );
+                               $db = $this->getConnection( $shardIndex );
                                $this->deleteServerObjectsExpiringBefore(
                                        $db,
                                        $timestamp,
                for ( $shardIndex = 0; $shardIndex < $this->numServerShards; $shardIndex++ ) {
                        $db = null; // in case of connection failure
                        try {
-                               $db = $this->getDB( $shardIndex );
+                               $db = $this->getConnection( $shardIndex );
                                for ( $i = 0; $i < $this->numTableShards; $i++ ) {
                                        $db->delete( $this->getTableNameByShard( $i ), '*', __METHOD__ );
                                }
  
                $db = null; // in case of connection failure
                try {
-                       $db = $this->getDB( $shardIndex );
+                       $db = $this->getConnection( $shardIndex );
                        $ok = $db->lock( $key, __METHOD__, $timeout );
                        if ( $ok ) {
                                $this->locks[$key] = [ 'class' => $rclass, 'depth' => 1 ];
  
                        $db = null; // in case of connection failure
                        try {
-                               $db = $this->getDB( $shardIndex );
+                               $db = $this->getConnection( $shardIndex );
                                $ok = $db->unlock( $key, __METHOD__ );
                                if ( !$ok ) {
                                        $this->logger->warning(
                }
  
                if ( function_exists( 'gzinflate' ) ) {
 -                      Wikimedia\suppressWarnings();
 +                      AtEase::suppressWarnings();
                        $decomp = gzinflate( $serial );
 -                      Wikimedia\restoreWarnings();
 +                      AtEase::restoreWarnings();
  
                        if ( $decomp !== false ) {
                                $serial = $decomp;
         */
        public function createTables() {
                for ( $shardIndex = 0; $shardIndex < $this->numServerShards; $shardIndex++ ) {
-                       $db = $this->getDB( $shardIndex );
+                       $db = $this->getConnection( $shardIndex );
                        if ( $db->getType() !== 'mysql' ) {
                                throw new MWException( __METHOD__ . ' is not supported on this DB server' );
                        }