r108544 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108543‎ | r108544 | r108545 >
Date:20:29, 10 January 2012
Author:raindrift
Status:ok
Tags:
Comment:
removed notes to self, cleaned up comments
actually run expire()
added some TODOs
Modified paths:
  • /branches/concurrency/includes/ConcurrencyCheck.php (modified) (history)

Diff [purge]

Index: branches/concurrency/includes/ConcurrencyCheck.php
@@ -32,6 +32,7 @@
3333 $this->dbw = wfGetDb( DB_MASTER );
3434
3535 $this->user = $user;
 36+ // TODO: create a registry of all valid resourceTypes that client app can add to.
3637 $this->resourceType = $resourceType;
3738 $this->setExpirationTime( $expirationTime );
3839 }
@@ -85,6 +86,7 @@
8687 return true;
8788 }
8889
 90+ // if the insert failed, it's necessary to check the expiration.
8991 $dbw->begin();
9092 $row = $dbw->selectRow(
9193 'concurrencycheck',
@@ -123,24 +125,10 @@
124126 );
125127
126128 // cache the result.
127 - $memc->set( $cacheKey, array( 'userId' => $userId, 'expiration' => $expiration ), $expiration - time() );
 129+ $memc->set( $cacheKey, array( 'userId' => $userId, 'expiration' => $expiration ), $this->expirationTime );
128130
129131 $dbw->commit();
130132 return true;
131 -
132 - // if insert succeeds, delete the cache key. don't make a new one since they have to be created atomically.
133 - //
134 - // if insert fails:
135 - // begin transaction
136 - // select where key=key and expiration > now()
137 - // if row is missing or user matches:
138 - // execute a replace()
139 - // overwrite the cache key (might as well, since this is inside a transaction)
140 - // commit
141 - // if select returned an unexpired row owned by someone else, return failure.
142 -
143 - // optional: check to see if the current user already has the resource checked out, and if so,
144 - // return that checkout information instead. (does anyone want that?)
145133 }
146134
147135 /**
@@ -173,15 +161,7 @@
174162 return true;
175163 }
176164
177 - return false;
178 -
179 - // delete the row, specifying the username in the where clause (keeps users from checking in stuff that's not theirs).
180 - // if a row was deleted:
181 - // remove the record from memcache. (removing cache key doesn't require atomicity)
182 - // return true
183 - // else
184 - // return false
185 -
 165+ return false;
186166 }
187167
188168 /**
@@ -229,19 +209,6 @@
230210
231211 // return the number of rows removed.
232212 return $dbw->affectedRows();
233 -
234 - // grab a unixtime.
235 - // select all rows where expiration < time
236 - // delete all rows where expiration < time
237 - // remove selected rows from memcache
238 - //
239 - // previous idea, probably wrong:
240 - // select all expired rows.
241 - // foreach( expired )
242 - // delete row where id=id and expiration < now() (accounts for updates)
243 - // if delete succeeded, remove cache key (txn not required, since removing cache key doesn't require atomicity)
244 - // (sadly, this must be many deletes to coordinate removal from memcache)
245 - // (is it necessary to remove expired cache entries?)
246213 }
247214
248215 public function status( $keys ) {
@@ -251,9 +218,6 @@
252219
253220 $checkouts = array();
254221 $toSelect = array();
255 -
256 - // maybe run this here?
257 - //$this->expire();
258222
259223 // validate keys, attempt to retrieve from cache.
260224 foreach( $keys as $key ) {
@@ -276,6 +240,9 @@
277241
278242 // if there were cache misses...
279243 if( $toSelect ) {
 244+ // If it's time to go to the database, go ahead and expire old rows.
 245+ $this->expire();
 246+
280247 // the transaction seems incongruous, I know, but it's to keep the cache update atomic.
281248 $dbw->begin();
282249 $res = $dbw->select(
@@ -315,23 +282,10 @@
316283 }
317284
318285 return $checkouts;
319 -
320 - // fetch keys from cache or db (keys are an array)
321 - //
322 - // for all unexpired keys present in cache, store cached return value for returning later.
323 - //
324 - // if some keys remain (missing from cache or expired):
325 - // execute expire() to make sure db records are cleared
326 - // for all remaining keys:
327 - // begin transaction
328 - // select rows where key in (keys) and expiration > now()
329 - // overwrite any memcache entry
330 - // commit
331 - // return values that were added to cache, plus values pulled from cache
332286 }
333287
334288 public function listCheckouts() {
335 - // fill in the function that lets you get the complete set of checkouts for a given application.
 289+ // TODO: fill in the function that lets you get the complete set of checkouts for a given application.
336290 }
337291
338292 public function setUser ( $user ) {
@@ -367,6 +321,8 @@
368322 if( ! preg_match('/^\d+$/', $record) ) {
369323 throw new ConcurrencyCheckBadRecordIdException( 'Record ID ' . $record . ' must be a positive integer' );
370324 }
 325+
 326+ // TODO: add a hook here for client-side validation.
371327 return true;
372328 }
373329 }

Status & tagging log