X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/rappels.php?a=blobdiff_plain;f=includes%2Fobjectcache%2FSqlBagOStuff.php;h=2866a6c9cf680f75187b1c9a504395d60364c6c0;hb=bd7886961820d5f369029a007c6a75866fde5f19;hp=076f208bf02fc40b221e7cf9402c67a3c320241b;hpb=21fb9bb32b82f13a436238a7dca9bac1464baf80;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/objectcache/SqlBagOStuff.php b/includes/objectcache/SqlBagOStuff.php index 076f208bf0..2866a6c9cf 100644 --- a/includes/objectcache/SqlBagOStuff.php +++ b/includes/objectcache/SqlBagOStuff.php @@ -28,7 +28,7 @@ use Wikimedia\Rdbms\DBError; use Wikimedia\Rdbms\DBQueryError; use Wikimedia\Rdbms\DBConnectionError; use Wikimedia\Rdbms\LoadBalancer; -use Wikimedia\Rdbms\TransactionProfiler; +use Wikimedia\ScopedCallback; use Wikimedia\WaitConditionLoop; /** @@ -92,7 +92,9 @@ class SqlBagOStuff extends BagOStuff { * shards-1. The number of digits will be the minimum number * required to hold the largest shard index. Data will be * distributed across all tables by key hash. This is for - * MySQL bugs 61735 and 61736. + * MySQL bugs 61735 + * and 61736 . + * * - slaveOnly: Whether to only use replica DBs and avoid triggering * garbage collection logic of expired items. This only * makes sense if the primary DB is used and only if get() @@ -171,8 +173,6 @@ class SqlBagOStuff extends BagOStuff { $type = $info['type'] ?? 'mysql'; $host = $info['host'] ?? '[unknown]'; $this->logger->debug( __CLASS__ . ": connecting to $host" ); - // Use a blank trx profiler to ignore expections as this is a cache - $info['trxProfiler'] = new TransactionProfiler(); $db = Database::factory( $type, $info ); $db->clearFlag( DBO_TRX ); // auto-commit mode } else { @@ -182,7 +182,6 @@ class SqlBagOStuff extends BagOStuff { if ( $lb->getServerType( $lb->getWriterIndex() ) !== 'sqlite' ) { // Keep a separate connection to avoid contention and deadlocks $db = $lb->getConnection( $index, [], false, $lb::CONN_TRX_AUTOCOMMIT ); - // @TODO: Use a blank trx profiler to ignore expections as this is a cache } else { // However, SQLite has the opposite behavior due to DB-level locking. // Stock sqlite MediaWiki installs use a separate sqlite cache DB instead. @@ -323,6 +322,7 @@ class SqlBagOStuff extends BagOStuff { $result = true; $exptime = (int)$expiry; + $silenceScope = $this->silenceTransactionProfiler(); foreach ( $keysByTable as $serverIndex => $serverKeys ) { $db = null; try { @@ -384,6 +384,7 @@ class SqlBagOStuff extends BagOStuff { protected function cas( $casToken, $key, $value, $exptime = 0 ) { list( $serverIndex, $tableName ) = $this->getTableByKey( $key ); $db = null; + $silenceScope = $this->silenceTransactionProfiler(); try { $db = $this->getDB( $serverIndex ); $exptime = intval( $exptime ); @@ -425,6 +426,7 @@ class SqlBagOStuff extends BagOStuff { public function delete( $key ) { list( $serverIndex, $tableName ) = $this->getTableByKey( $key ); $db = null; + $silenceScope = $this->silenceTransactionProfiler(); try { $db = $this->getDB( $serverIndex ); $db->delete( @@ -442,6 +444,7 @@ class SqlBagOStuff extends BagOStuff { public function incr( $key, $step = 1 ) { list( $serverIndex, $tableName ) = $this->getTableByKey( $key ); $db = null; + $silenceScope = $this->silenceTransactionProfiler(); try { $db = $this->getDB( $serverIndex ); $step = intval( $step ); @@ -496,6 +499,7 @@ class SqlBagOStuff extends BagOStuff { public function changeTTL( $key, $expiry = 0 ) { list( $serverIndex, $tableName ) = $this->getTableByKey( $key ); $db = null; + $silenceScope = $this->silenceTransactionProfiler(); try { $db = $this->getDB( $serverIndex ); $db->update( @@ -564,6 +568,7 @@ class SqlBagOStuff extends BagOStuff { * @return bool */ public function deleteObjectsExpiringBefore( $timestamp, $progressCallback = false ) { + $silenceScope = $this->silenceTransactionProfiler(); for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) { $db = null; try { @@ -641,6 +646,7 @@ class SqlBagOStuff extends BagOStuff { * @return bool */ public function deleteAll() { + $silenceScope = $this->silenceTransactionProfiler(); for ( $serverIndex = 0; $serverIndex < $this->numServers; $serverIndex++ ) { $db = null; try { @@ -685,7 +691,7 @@ class SqlBagOStuff extends BagOStuff { $decomp = gzinflate( $serial ); Wikimedia\restoreWarnings(); - if ( false !== $decomp ) { + if ( $decomp !== false ) { $serial = $decomp; } } @@ -822,4 +828,18 @@ class SqlBagOStuff extends BagOStuff { return ( $loop->invoke() === $loop::CONDITION_REACHED ); } + + /** + * Returns a ScopedCallback which resets the silence flag in the transaction profiler when it is + * destroyed on the end of a scope, for example on return or throw + * @return ScopedCallback + * @since 1.32 + */ + protected function silenceTransactionProfiler() { + $trxProfiler = Profiler::instance()->getTransactionProfiler(); + $oldSilenced = $trxProfiler->setSilenced( true ); + return new ScopedCallback( function () use ( $trxProfiler, $oldSilenced ) { + $trxProfiler->setSilenced( $oldSilenced ); + } ); + } }