r85862 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85861‎ | r85862 | r85863 >
Date:03:59, 12 April 2011
Author:tstarling
Status:ok
Tags:
Comment:
In SQLBagOStuff: make it possible to change the purge period, or disable purging altogether. At Domas's suggestion, for deployment to Wikimedia very soon.
Modified paths:
  • /trunk/phase3/includes/objectcache/SqlBagOStuff.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/objectcache/SqlBagOStuff.php
@@ -18,17 +18,28 @@
1919 var $db;
2020 var $serverInfo;
2121 var $lastExpireAll = 0;
 22+ var $purgePeriod = 100;
2223
2324 /**
2425 * Constructor. Parameters are:
2526 * - server: A server info structure in the format required by each
2627 * element in $wgDBServers.
 28+ *
 29+ * - purgePeriod: The average number of object cache requests in between
 30+ * garbage collection operations, where expired entries
 31+ * are removed from the database. Or in other words, the
 32+ * reciprocal of the probability of purging on any given
 33+ * request. If this is set to zero, purging will never be
 34+ * done.
2735 */
2836 public function __construct( $params ) {
2937 if ( isset( $params['server'] ) ) {
3038 $this->serverInfo = $params['server'];
3139 $this->serverInfo['load'] = 1;
3240 }
 41+ if ( isset( $params['purgePeriod'] ) ) {
 42+ $this->purgePeriod = intval( $params['purgePeriod'] );
 43+ }
3344 }
3445
3546 /**
@@ -213,15 +224,20 @@
214225 }
215226
216227 protected function garbageCollect() {
217 - /* Ignore 99% of requests */
218 - if ( !mt_rand( 0, 100 ) ) {
219 - $now = time();
220 - /* Avoid repeating the delete within a few seconds */
221 - if ( $now > ( $this->lastExpireAll + 1 ) ) {
222 - $this->lastExpireAll = $now;
223 - $this->expireAll();
224 - }
 228+ if ( !$this->purgePeriod ) {
 229+ // Disabled
 230+ return;
225231 }
 232+ // Only purge on one in every $this->purgePeriod requests.
 233+ if ( $this->purgePeriod !== 1 && mt_rand( 0, $this->purgePeriod - 1 ) ) {
 234+ return;
 235+ }
 236+ $now = time();
 237+ // Avoid repeating the delete within a few seconds
 238+ if ( $now > ( $this->lastExpireAll + 1 ) ) {
 239+ $this->lastExpireAll = $now;
 240+ $this->expireAll();
 241+ }
226242 }
227243
228244 public function expireAll() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r90942MFT r85862: configurable purging for MySQL cachetstarling06:30, 28 June 2011

Status & tagging log