X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/rappel_supprimer.php?a=blobdiff_plain;f=includes%2Fdb%2Floadbalancer%2FLBFactory.php;h=efc6148fee73108f97db0823ac9582142062e0a0;hb=2e7f4e48735b0e916336d9166cb1ab1756e0fa9f;hp=4078a3926e1ce04cb685f4a82251cefe4f58c588;hpb=501d34c5995b67111d527828946f2a6ed7709849;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/db/loadbalancer/LBFactory.php b/includes/db/loadbalancer/LBFactory.php index 4078a3926e..efc6148fee 100644 --- a/includes/db/loadbalancer/LBFactory.php +++ b/includes/db/loadbalancer/LBFactory.php @@ -42,6 +42,8 @@ abstract class LBFactory implements DestructibleService { /** @var WANObjectCache */ protected $wanCache; + /** @var mixed */ + protected $ticket; /** @var string|bool Reason all LBs are read-only or false if not */ protected $readOnlyReason = false; @@ -72,6 +74,7 @@ abstract class LBFactory implements DestructibleService { $this->wanCache = WANObjectCache::newEmpty(); } $this->trxLogger = LoggerFactory::getInstance( 'DBTransaction' ); + $this->ticket = mt_rand(); } /** @@ -404,6 +407,44 @@ abstract class LBFactory implements DestructibleService { } } + /** + * Get a token asserting that no transaction writes are active + * + * @param string $fname Caller name (e.g. __METHOD__) + * @return mixed A value to pass to commitAndWaitForReplication() + * @since 1.28 + */ + public function getEmptyTransactionTicket( $fname ) { + if ( $this->hasMasterChanges() ) { + $this->trxLogger->error( __METHOD__ . ": $fname does not have outer scope." ); + return null; + } + + return $this->ticket; + } + + /** + * Convenience method for safely running commitMasterChanges()/waitForReplication() + * + * This will commit and wait unless $ticket indicates it is unsafe to do so + * + * @param string $fname Caller name (e.g. __METHOD__) + * @param mixed $ticket Result of getOuterTransactionScopeTicket() + * @param array $opts Options to waitForReplication() + * @throws DBReplicationWaitError + * @since 1.28 + */ + public function commitAndWaitForReplication( $fname, $ticket, array $opts = [] ) { + if ( $ticket !== $this->ticket ) { + $logger = LoggerFactory::getInstance( 'DBPerformance' ); + $logger->error( __METHOD__ . ": cannot commit; $fname does not have outer scope." ); + return; + } + + $this->commitMasterChanges( $fname ); + $this->waitForReplication( $opts ); + } + /** * Disable the ChronologyProtector for all load balancers *