r93093 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93092‎ | r93093 | r93094 >
Date:19:24, 25 July 2011
Author:aaron
Status:resolved (Comments)
Tags:
Comment:
Follow-up r79518: added getCachedLastEditTime/getCachedLastEditTime methods to WikiPage and check them in loadPageData() to see if we should hit the master. This should lower the risk of stale data (by not just relying on cookie/session master position waiting).
Modified paths:
  • /trunk/phase3/includes/WikiPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/WikiPage.php
@@ -350,19 +350,28 @@
351351 * A DB query result object or...
352352 * "fromdb" to get from a slave DB or...
353353 * "fromdbmaster" to get from the master DB
 354+ * @return void
354355 */
355356 public function loadPageData( $data = 'fromdb' ) {
356 - if ( $data === 'fromdb' || $data === 'fromdbmaster' ) {
357 - $db = ( $data == 'fromdbmaster' )
358 - ? wfGetDB( DB_MASTER )
359 - : wfGetDB( DB_SLAVE );
360 - $data = $this->pageDataFromTitle( $db, $this->mTitle );
 357+ if ( $data === 'fromdbmaster' ) {
 358+ $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle );
 359+ } elseif ( $data === 'fromdb' ) { // slave
 360+ $data = $this->pageDataFromTitle( wfGetDB( DB_SLAVE ), $this->mTitle );
 361+ # Use a "last rev inserted" timestamp key to dimish the issue of slave lag.
 362+ # Note that DB also stores the master position in the session and checks it.
 363+ $touched = $this->getCachedLastEditTime();
 364+ if ( $touched ) { // key set
 365+ if ( !$data || $touched > wfTimestamp( TS_MW, $data->page_touched ) ) {
 366+ $data = $this->pageDataFromTitle( wfGetDB( DB_MASTER ), $this->mTitle );
 367+ }
 368+ }
361369 }
362370
363371 $lc = LinkCache::singleton();
364372
365373 if ( $data ) {
366 - $lc->addGoodLinkObj( $data->page_id, $this->mTitle, $data->page_len, $data->page_is_redirect, $data->page_latest );
 374+ $lc->addGoodLinkObj( $data->page_id, $this->mTitle,
 375+ $data->page_len, $data->page_is_redirect, $data->page_latest );
367376
368377 $this->mTitle->loadFromRow( $data );
369378
@@ -814,10 +823,11 @@
815824 $conditions['page_latest'] = $lastRevision;
816825 }
817826
 827+ $now = wfTimestampNow();
818828 $dbw->update( 'page',
819829 array( /* SET */
820830 'page_latest' => $revision->getId(),
821 - 'page_touched' => $dbw->timestamp(),
 831+ 'page_touched' => $dbw->timestamp( $now ),
822832 'page_is_new' => ( $lastRevision === 0 ) ? 1 : 0,
823833 'page_is_redirect' => $rt !== null ? 1 : 0,
824834 'page_len' => strlen( $text ),
@@ -828,6 +838,7 @@
829839 $result = $dbw->affectedRows() != 0;
830840 if ( $result ) {
831841 $this->updateRedirectOn( $dbw, $rt, $lastRevIsRedirect );
 842+ $this->setCachedLastEditTime( $now );
832843 }
833844
834845 wfProfileOut( __METHOD__ );
@@ -835,6 +846,27 @@
836847 }
837848
838849 /**
 850+ * Get the cached timestamp for the last time the page changed
 851+ * @return string MW timestamp
 852+ */
 853+ protected function getCachedLastEditTime() {
 854+ global $wgMemc;
 855+ $key = wfMemcKey( 'page-lastedit', md5( $this->mTitle->getPrefixedDBkey() ) );
 856+ return $wgMemc->get( $key );
 857+ }
 858+
 859+ /**
 860+ * Set the cached timestamp for the last time the page changed
 861+ * @param $timestamp string
 862+ * @return void
 863+ */
 864+ protected function setCachedLastEditTime( $timestamp ) {
 865+ global $wgMemc;
 866+ $key = wfMemcKey( 'page-lastedit', md5( $this->mTitle->getPrefixedDBkey() ) );
 867+ $wgMemc->set( $key, wfTimestamp( TS_MW, $timestamp ), 60*15 );
 868+ }
 869+
 870+ /**
839871 * Add row to the redirect table if this is a redirect, remove otherwise.
840872 *
841873 * @param $dbw DatabaseBase

Follow-up revisions

RevisionCommit summaryAuthorDate
r93468* Follow-up r93093: set the touch key for page moves too...aaron16:44, 29 July 2011
r964701.17wmf1: MFT r92962, r93062, r93093, r93385, r93468, r93473, r94350, r94502,...catrope19:07, 7 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r79518* Modified Article::loadPageData() to use a slave database connection and pag...ialex19:50, 3 January 2011

Comments

#Comment by Aaron Schulz (talk | contribs)   17:44, 28 July 2011

I wonder if page moves should also touch this timestamp.

Status & tagging log