Avoid contention in updateLinksTimestamp()
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 7 Jun 2016 12:15:42 +0000 (05:15 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Tue, 7 Jun 2016 12:15:42 +0000 (05:15 -0700)
Since LinksUpdate::doUpdate() already flushes the transaction,
go ahead and flush before other DataUpdates might run (e.g.
from RefreshLinksJob). Also release the lock before running
the LinksUpdateComplete handlers, as the lock is just to keep
LinksUpdate instances from racing with each other.

Change-Id: Ied97fa36fbca0203123e9fc966d2e23bfd621c0e

includes/deferred/LinksUpdate.php

index 07b5614..d4a61fa 100644 (file)
@@ -155,10 +155,11 @@ class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate {
                Hooks::run( 'LinksUpdate', [ &$this ] );
                $this->doIncrementalUpdate();
 
-               $this->mDb->onTransactionIdle( function() use ( &$scopedLock ) {
+               // Commit and release the lock
+               ScopedCallback::consume( $scopedLock );
+               // Run post-commit hooks without DBO_TRX
+               $this->mDb->onTransactionIdle( function() {
                        Hooks::run( 'LinksUpdateComplete', [ &$this ] );
-                       // Release the lock *after* the final COMMIT for correctness
-                       ScopedCallback::consume( $scopedLock );
                } );
        }
 
@@ -243,15 +244,14 @@ class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate {
                $changed = $propertiesDeletes + array_diff_assoc( $this->mProperties, $existing );
                $this->invalidateProperties( $changed );
 
-               # Update the links table freshness for this title
-               $this->updateLinksTimestamp();
-
                # Refresh links of all pages including this page
                # This will be in a separate transaction
                if ( $this->mRecursive ) {
                        $this->queueRecursiveJobs();
                }
 
+               # Update the links table freshness for this title
+               $this->updateLinksTimestamp();
        }
 
        /**