From: jenkins-bot Date: Thu, 12 Apr 2018 20:38:58 +0000 (+0000) Subject: Merge "rdbms: rename CONN_TRX_AUTO constant to CONN_TRX_AUTOCOMMIT" X-Git-Tag: 1.31.0-rc.0~95 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=6a3aadf097511eab605701d8d0adfe2a1d476f9d;hp=-c Merge "rdbms: rename CONN_TRX_AUTO constant to CONN_TRX_AUTOCOMMIT" --- 6a3aadf097511eab605701d8d0adfe2a1d476f9d diff --combined includes/libs/rdbms/loadbalancer/ILoadBalancer.php index 715f4e4d29,3c07d0f9f1..ae4362d9bb --- a/includes/libs/rdbms/loadbalancer/ILoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/ILoadBalancer.php @@@ -85,6 -85,8 +85,8 @@@ interface ILoadBalancer const DOMAIN_ANY = ''; /** @var int DB handle should have DBO_TRX disabled and the caller will leave it as such */ + const CONN_TRX_AUTOCOMMIT = 1; + /** @var int Alias for CONN_TRX_AUTOCOMMIT for b/c; deprecated since 1.31 */ const CONN_TRX_AUTO = 1; /** @@@ -109,7 -111,6 +111,7 @@@ * - queryLogger: PSR-3 logger instance. [optional] * - perfLogger: PSR-3 logger instance. [optional] * - errorLogger : Callback that takes an Exception and logs it. [optional] + * - deprecationLogger: Callback to log a deprecation warning. [optional] * @throws InvalidArgumentException */ public function __construct( array $params ); @@@ -173,11 -174,11 +175,11 @@@ /** * Get a connection handle by server index * - * The CONN_TRX_AUTO flag is ignored for databases with ATTR_DB_LEVEL_LOCKING + * The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING * (e.g. sqlite) in order to avoid deadlocks. ILoadBalancer::getServerAttributes() * can be used to check such flags beforehand. * - * If the caller uses $domain or sets CONN_TRX_AUTO in $flags, then it must also + * If the caller uses $domain or sets CONN_TRX_AUTOCOMMIT in $flags, then it must also * call ILoadBalancer::reuseConnection() on the handle when finished using it. * In all other cases, this is not necessary, though not harmful either. * @@@ -209,7 -210,7 +211,7 @@@ * * The handle's methods simply wrap those of a Database handle * - * The CONN_TRX_AUTO flag is ignored for databases with ATTR_DB_LEVEL_LOCKING + * The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING * (e.g. sqlite) in order to avoid deadlocks. ILoadBalancer::getServerAttributes() * can be used to check such flags beforehand. * @@@ -218,7 -219,7 +220,7 @@@ * @param int $i Server index or DB_MASTER/DB_REPLICA * @param array|string|bool $groups Query group(s), or false for the generic reader * @param string|bool $domain Domain ID, or false for the current domain - * @param int $flags Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTO) + * @param int $flags Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT) * @return DBConnRef */ public function getConnectionRef( $i, $groups = [], $domain = false, $flags = 0 ); @@@ -228,7 -229,7 +230,7 @@@ * * The handle's methods simply wrap those of a Database handle * - * The CONN_TRX_AUTO flag is ignored for databases with ATTR_DB_LEVEL_LOCKING + * The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING * (e.g. sqlite) in order to avoid deadlocks. ILoadBalancer::getServerAttributes() * can be used to check such flags beforehand. * @@@ -237,7 -238,7 +239,7 @@@ * @param int $i Server index or DB_MASTER/DB_REPLICA * @param array|string|bool $groups Query group(s), or false for the generic reader * @param string|bool $domain Domain ID, or false for the current domain - * @param int $flags Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTO) + * @param int $flags Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT) * @return DBConnRef */ public function getLazyConnectionRef( $i, $groups = [], $domain = false, $flags = 0 ); @@@ -247,7 -248,7 +249,7 @@@ * * The handle's methods simply wrap those of a Database handle * - * The CONN_TRX_AUTO flag is ignored for databases with ATTR_DB_LEVEL_LOCKING + * The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING * (e.g. sqlite) in order to avoid deadlocks. ILoadBalancer::getServerAttributes() * can be used to check such flags beforehand. * @@@ -256,7 -257,7 +258,7 @@@ * @param int $db Server index or DB_MASTER/DB_REPLICA * @param array|string|bool $groups Query group(s), or false for the generic reader * @param string|bool $domain Domain ID, or false for the current domain - * @param int $flags Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTO) + * @param int $flags Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT) * @return MaintainableDBConnRef */ public function getMaintenanceConnectionRef( $db, $groups = [], $domain = false, $flags = 0 ); @@@ -267,11 -268,11 +269,11 @@@ * The index must be an actual index into the array. If a connection to the server is * already open and not considered an "in use" foreign connection, this simply returns it. * - * Avoid using CONN_TRX_AUTO for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in + * Avoid using CONN_TRX_AUTOCOMMIT for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in * order to avoid deadlocks. ILoadBalancer::getServerAttributes() can be used to check * such flags beforehand. * - * If the caller uses $domain or sets CONN_TRX_AUTO in $flags, then it must also + * If the caller uses $domain or sets CONN_TRX_AUTOCOMMIT in $flags, then it must also * call ILoadBalancer::reuseConnection() on the handle when finished using it. * In all other cases, this is not necessary, though not harmful either. * @@@ -279,7 -280,7 +281,7 @@@ * * @param int $i Server index (does not support DB_MASTER/DB_REPLICA) * @param string|bool $domain Domain ID, or false for the current domain - * @param int $flags Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTO) + * @param int $flags Bitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT) * @return Database|bool Returns false on errors * @throws DBAccessError */ diff --combined includes/libs/rdbms/loadbalancer/LoadBalancer.php index 94acc1ef05,e28e222b75..c587b4214f --- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php +++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php @@@ -111,8 -111,6 +111,8 @@@ class LoadBalancer implements ILoadBala /** @var callable Exception logger */ private $errorLogger; + /** @var callable Deprecation logger */ + private $deprecationLogger; /** @var bool */ private $disabled = false; @@@ -225,11 -223,6 +225,11 @@@ : function ( Exception $e ) { trigger_error( get_class( $e ) . ': ' . $e->getMessage(), E_USER_WARNING ); }; + $this->deprecationLogger = isset( $params['deprecationLogger'] ) + ? $params['deprecationLogger'] + : function ( $msg ) { + trigger_error( $msg, E_USER_DEPRECATED ); + }; foreach ( [ 'replLogger', 'connLogger', 'queryLogger', 'perfLogger' ] as $key ) { $this->$key = isset( $params[$key] ) ? $params[$key] : new NullLogger(); @@@ -539,7 -532,7 +539,7 @@@ if ( $this->loads[$i] > 0 ) { $start = microtime( true ); $ok = $this->doWait( $i, true, $timeout ) && $ok; - $timeout -= ( microtime( true ) - $start ); + $timeout -= intval( microtime( true ) - $start ); if ( $timeout <= 0 ) { break; // timeout reached } @@@ -575,7 -568,6 +575,6 @@@ if ( !empty( $connsByServer[$i] ) ) { /** @var IDatabase[] $serverConns */ $serverConns = $connsByServer[$i]; - return reset( $serverConns ); } } @@@ -689,7 -681,7 +688,7 @@@ $domain = false; // local connection requested } - if ( ( $flags & self::CONN_TRX_AUTO ) === self::CONN_TRX_AUTO ) { + if ( ( $flags & self::CONN_TRX_AUTOCOMMIT ) === self::CONN_TRX_AUTOCOMMIT ) { // Assuming all servers are of the same type (or similar), which is overwhelmingly // the case, use the master server information to get the attributes. The information // for $i cannot be used since it might be DB_REPLICA, which might require connection @@@ -700,8 -692,9 +699,9 @@@ // rows (e.g. FOR UPDATE) or (b) make small commits during a larger transactions // to reduce lock contention. None of these apply for sqlite and using separate // connections just causes self-deadlocks. - $flags &= ~self::CONN_TRX_AUTO; - $this->connLogger->info( __METHOD__ . ': ignoring CONN_TRX_AUTO to avoid deadlocks.' ); + $flags &= ~self::CONN_TRX_AUTOCOMMIT; + $this->connLogger->info( __METHOD__ . + ': ignoring CONN_TRX_AUTOCOMMIT to avoid deadlocks.' ); } } @@@ -859,7 -852,7 +859,7 @@@ // main set of DB connections but rather its own pool since: // a) those are usually set to implicitly use transaction rounds via DBO_TRX // b) those must support the use of explicit transaction rounds via beginMasterChanges() - $autoCommit = ( ( $flags & self::CONN_TRX_AUTO ) == self::CONN_TRX_AUTO ); + $autoCommit = ( ( $flags & self::CONN_TRX_AUTOCOMMIT ) == self::CONN_TRX_AUTOCOMMIT ); if ( $domain !== false ) { // Connection is to a foreign domain @@@ -937,7 -930,7 +937,7 @@@ $domainInstance = DatabaseDomain::newFromId( $domain ); $dbName = $domainInstance->getDatabase(); $prefix = $domainInstance->getTablePrefix(); - $autoCommit = ( ( $flags & self::CONN_TRX_AUTO ) == self::CONN_TRX_AUTO ); + $autoCommit = ( ( $flags & self::CONN_TRX_AUTOCOMMIT ) == self::CONN_TRX_AUTOCOMMIT ); if ( $autoCommit ) { $connFreeKey = self::KEY_FOREIGN_FREE_NOROUND; @@@ -1074,7 -1067,6 +1074,7 @@@ $server['connLogger'] = $this->connLogger; $server['queryLogger'] = $this->queryLogger; $server['errorLogger'] = $this->errorLogger; + $server['deprecationLogger'] = $this->deprecationLogger; $server['profiler'] = $this->profiler; $server['trxProfiler'] = $this->trxProfiler; // Use the same agent and PHP mode for all DB handles @@@ -1220,7 -1212,7 +1220,7 @@@ } public function closeConnection( IDatabase $conn ) { - $serverIndex = $conn->getLBInfo( 'serverIndex' ); // second index level of mConns + $serverIndex = $conn->getLBInfo( 'serverIndex' ); foreach ( $this->conns as $type => $connsByServer ) { if ( !isset( $connsByServer[$serverIndex] ) ) { continue; diff --combined tests/phpunit/includes/libs/rdbms/database/DBConnRefTest.php index bc9d9ea4fc,b370508811..c3cddc61dc --- a/tests/phpunit/includes/libs/rdbms/database/DBConnRefTest.php +++ b/tests/phpunit/includes/libs/rdbms/database/DBConnRefTest.php @@@ -12,8 -12,6 +12,8 @@@ use Wikimedia\Rdbms\ResultWrapper */ class DBConnRefTest extends PHPUnit\Framework\TestCase { + use PHPUnit4And6Compat; + /** * @return ILoadBalancer */ @@@ -69,7 -67,7 +69,7 @@@ $lb->expects( $this->once() ) ->method( 'getConnection' ) - ->with( DB_MASTER, [ 'test' ], 'dummy', ILoadBalancer::CONN_TRX_AUTO ) + ->with( DB_MASTER, [ 'test' ], 'dummy', ILoadBalancer::CONN_TRX_AUTOCOMMIT ) ->willReturnCallback( function () { return $this->getDatabaseMock(); @@@ -78,7 -76,7 +78,7 @@@ $ref = new DBConnRef( $lb, - [ DB_MASTER, [ 'test' ], 'dummy', ILoadBalancer::CONN_TRX_AUTO ] + [ DB_MASTER, [ 'test' ], 'dummy', ILoadBalancer::CONN_TRX_AUTOCOMMIT ] ); $this->assertInstanceOf( ResultWrapper::class, $ref->select( 'whatever', '*' ) );