From: Aaron Schulz Date: Tue, 23 Sep 2014 16:45:04 +0000 (-0700) Subject: Fixes to prevent duplicate rows in ActiveUser cache X-Git-Tag: 1.31.0-rc.0~13850^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/?a=commitdiff_plain;h=9e2b790fc28d9cb172eb16b6d39eb4739a48a66e;p=lhc%2Fweb%2Fwiklou.git Fixes to prevent duplicate rows in ActiveUser cache * Handle repeatable-read snapshots better for web requests * In CLI mode, handle automatic reconnects better (rolling back). It has to abort since it lost the lock in that case. bug: 71086 Change-Id: I5228889cf05857c87a06f7d073b5aa46f0c240be --- diff --git a/includes/specials/SpecialActiveusers.php b/includes/specials/SpecialActiveusers.php index d17b6714dd..07e1be1933 100644 --- a/includes/specials/SpecialActiveusers.php +++ b/includes/specials/SpecialActiveusers.php @@ -332,6 +332,8 @@ class SpecialActiveUsers extends SpecialPage { * @return int|bool UNIX timestamp the cache is now up-to-date as of (false on error) */ protected static function doQueryCacheUpdate( DatabaseBase $dbw, $days, $window ) { + $dbw->startAtomic( __METHOD__ ); + $lockKey = wfWikiID() . '-activeusers'; if ( !$dbw->lock( $lockKey, __METHOD__, 1 ) ) { return false; // exclusive update (avoids duplicate entries) @@ -343,6 +345,9 @@ class SpecialActiveUsers extends SpecialPage { array( 'qci_type' => 'activeusers' ) ); $cTimeUnix = $cTime ? wfTimestamp( TS_UNIX, $cTime ) : 1; + // If a transaction was already started, it might have an old + // snapshot, so kludge the timestamp range a few seconds back. + $cTimeUnix -= 5; // Pick the date range to fetch from. This is normally from the last // update to till the present time, but has a limited window for sanity. @@ -389,7 +394,10 @@ class SpecialActiveUsers extends SpecialPage { 'qcc_type' => 'activeusers', 'qcc_namespace' => NS_USER, 'qcc_title' => array_keys( $names ) ), - __METHOD__ + __METHOD__, + // See the latest data (ignoring trx snapshot) to avoid + // duplicates if this method was called in a transaction + array( 'LOCK IN SHARE MODE' ) ); foreach ( $res as $row ) { unset( $names[$row->user_name] ); @@ -426,6 +434,7 @@ class SpecialActiveUsers extends SpecialPage { ); $dbw->unlock( $lockKey, __METHOD__ ); + $dbw->endAtomic( __METHOD__ ); return $eTimestamp; }