r108585 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108584‎ | r108585 | r108586 >
Date:01:27, 11 January 2012
Author:raindrift
Status:reverted
Tags:
Comment:
sqlite doesn't actually support read locks. added a workaround until i can do the correct implementation.
followup to r108559
Modified paths:
  • /trunk/phase3/includes/ConcurrencyCheck.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ConcurrencyCheck.php
@@ -212,7 +212,7 @@
213213 }
214214
215215 public function status( $keys ) {
216 - global $wgMemc;
 216+ global $wgMemc, $wgDBtype;
217217 $dbw = $this->dbw;
218218 $now = time();
219219
@@ -243,8 +243,6 @@
244244 // If it's time to go to the database, go ahead and expire old rows.
245245 $this->expire();
246246
247 - // the transaction seems incongruous, I know, but it's to keep the cache update atomic.
248 - $dbw->begin();
249247
250248 // Why LOCK IN SHARE MODE, you might ask? To avoid a race condition: Otherwise, it's possible for
251249 // a checkin and/or checkout to occur between this select and the value being stored in cache, which
@@ -258,6 +256,14 @@
259257 //
260258 // It appears all the DBMSes we use support LOCK IN SHARE MODE, but if that's not the case, the second
261259 // solution above could be implemented instead.
 260+ $queryParams = array();
 261+ if( $wgDBtype === 'mysql' ) {
 262+ $queryParamsp[] = 'LOCK IN SHARE MODE';
 263+
 264+ // the transaction seems incongruous, I know, but it's to keep the cache update atomic.
 265+ $dbw->begin();
 266+ }
 267+
262268 $res = $dbw->select(
263269 'concurrencycheck',
264270 array( '*' ),
@@ -267,23 +273,29 @@
268274 'cc_expiration > ' . $dbw->addQuotes( wfTimestamp( TS_MW ) ),
269275 ),
270276 __METHOD__,
271 - array('LOCK IN SHARE MODE')
 277+ $queryParams
272278 );
273279
274280 while( $res && $record = $res->fetchRow() ) {
275281 $record['status'] = 'valid';
276282 $checkouts[ $record['cc_record'] ] = $record;
277283
278 - // safe to store values since this is inside the transaction
279 - $wgMemc->set(
280 - wfMemcKey( 'concurrencycheck', $this->resourceType, $record['cc_record'] ),
281 - array( 'userId' => $record['cc_user'], 'expiration' => $record['cc_expiration'] ),
282 - $record['cc_expiration'] - time()
283 - );
 284+ // TODO: implement strategy #2 above, determine which DBMSes need which method.
 285+ // for now, disable adding to cache here for databases that don't support read locking
 286+ if( $wgDBtype !== 'mysql' ) {
 287+ // safe to store values since this is inside the transaction
 288+ $wgMemc->set(
 289+ wfMemcKey( 'concurrencycheck', $this->resourceType, $record['cc_record'] ),
 290+ array( 'userId' => $record['cc_user'], 'expiration' => $record['cc_expiration'] ),
 291+ $record['cc_expiration'] - time()
 292+ );
 293+ }
284294 }
285295
286 - // end the transaction.
287 - $dbw->rollback();
 296+ if( $wgDBtype === 'mysql' ) {
 297+ // end the transaction.
 298+ $dbw->rollback();
 299+ }
288300 }
289301
290302 // if a key was passed in but has no (unexpired) checkout, include it in the

Follow-up revisions

RevisionCommit summaryAuthorDate
r108601reverts Concurrency works...hashar09:05, 11 January 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r108559MERGE branches/concurrency 108301:108557 into trunkraindrift23:03, 10 January 2012

Status & tagging log