r52382 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52381‎ | r52382 | r52383 >
Date:00:40, 25 June 2009
Author:demon
Status:resolved
Tags:
Comment:
* Move lock()/unlock() to DatabaseMysql, declare abstract
* Introduce lockTables() and unlockTables(), define in DatabaseMysql
* (bug 19372) updateSearchIndex has MySQLisms.
Modified paths:
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseMysql.php (modified) (history)
  • /trunk/phase3/maintenance/updateSearchIndex.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/updateSearchIndex.inc
@@ -75,7 +75,7 @@
7676 # Unlock searchindex
7777 if ( $maxLockTime ) {
7878 output( " --- Unlocking --" );
79 - unlockSearchindex( $dbw );
 79+ $dbw->unlockTables( 'updateSearchIndex.inc ' . __METHOD__ );
8080 output( "\n" );
8181 }
8282 output( "Done\n" );
@@ -84,27 +84,14 @@
8585 function lockSearchindex( &$db ) {
8686 $write = array( 'searchindex' );
8787 $read = array( 'page', 'revision', 'text', 'interwiki' );
88 - $items = array();
89 -
90 - foreach( $write as $table ) {
91 - $items[] = $db->tableName( $table ) . ' LOW_PRIORITY WRITE';
92 - }
93 - foreach( $read as $table ) {
94 - $items[] = $db->tableName( $table ) . ' READ';
95 - }
96 - $sql = "LOCK TABLES " . implode( ',', $items );
97 - $db->query( $sql, 'updateSearchIndex.inc ' . __METHOD__ );
 88+ $db->lockTables( $read, $write, 'updateSearchIndex.inc ' . __METHOD__ );
9889 }
9990
100 -function unlockSearchindex( &$db ) {
101 - $db->query( "UNLOCK TABLES", 'updateSearchIndex.inc ' . __METHOD__ );
102 -}
103 -
10491 # Unlock and lock again
10592 # Since the lock is low-priority, queued reads will be able to complete
10693 function relockSearchindex( &$db ) {
10794 unlockSearchindex( $db );
108 - lockSearchindex( $db );
 95+ $db->unlockTables( 'updateSearchIndex.inc ' . __METHOD__ );
10996 }
11097
11198 function output( $text ) {
Index: trunk/phase3/includes/db/DatabaseMysql.php
@@ -293,6 +293,44 @@
294294 $this->query( "SET net_read_timeout=$timeout" );
295295 $this->query( "SET net_write_timeout=$timeout" );
296296 }
 297+
 298+ public function lock( $lockName, $method, $timeout = 5 ) {
 299+ $lockName = $this->addQuotes( $lockName );
 300+ $result = $this->query( "SELECT GET_LOCK($lockName, $timeout) AS lockstatus", $method );
 301+ $row = $this->fetchObject( $result );
 302+ $this->freeResult( $result );
 303+
 304+ if( $row->lockstatus == 1 ) {
 305+ return true;
 306+ } else {
 307+ wfDebug( __METHOD__." failed to acquire lock\n" );
 308+ return false;
 309+ }
 310+ }
 311+
 312+ public function unlock( $lockName, $method ) {
 313+ $lockName = $this->addQuotes( $lockName );
 314+ $result = $this->query( "SELECT RELEASE_LOCK($lockName) as lockstatus", $method );
 315+ $row = $this->fetchObject( $result );
 316+ return $row->lockstatus;
 317+ }
 318+
 319+ public function lockTables( $read, $write, $method ) {
 320+ $items = array();
 321+
 322+ foreach( $write as $table ) {
 323+ $items[] = $this->tableName( $table ) . ' LOW_PRIORITY WRITE';
 324+ }
 325+ foreach( $read as $table ) {
 326+ $items[] = $this->tableName( $table ) . ' READ';
 327+ }
 328+ $sql = "LOCK TABLES " . implode( ',', $items );
 329+ $db->query( $sql, $method );
 330+ }
 331+
 332+ public function unlockTables( $method ) {
 333+ $this->query( "UNLOCK TABLES", $method );
 334+ }
297335 }
298336
299337 /**
Index: trunk/phase3/includes/db/Database.php
@@ -2176,7 +2176,7 @@
21772177 }
21782178
21792179 /**
2180 - * Acquire a lock
 2180+ * Acquire a named lock
21812181 *
21822182 * Abstracted from Filestore::lock() so child classes can implement for
21832183 * their own needs.
@@ -2185,35 +2185,38 @@
21862186 * @param $method String: Name of method calling us
21872187 * @return bool
21882188 */
2189 - public function lock( $lockName, $method ) {
2190 - $lockName = $this->addQuotes( $lockName );
2191 - $result = $this->query( "SELECT GET_LOCK($lockName, 5) AS lockstatus", $method );
2192 - $row = $this->fetchObject( $result );
2193 - $this->freeResult( $result );
 2189+ abstract public function lock( $lockName, $method, $timeout = 5 );
21942190
2195 - if( $row->lockstatus == 1 ) {
2196 - return true;
2197 - } else {
2198 - wfDebug( __METHOD__." failed to acquire lock\n" );
2199 - return false;
2200 - }
2201 - }
22022191 /**
22032192 * Release a lock.
22042193 *
2205 - * @todo fixme - Figure out a way to return a bool
2206 - * based on successful lock release.
2207 - *
22082194 * @param $lockName String: Name of lock to release
22092195 * @param $method String: Name of method calling us
 2196+ *
 2197+ * FROM MYSQL DOCS: http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_release-lock
 2198+ * @return Returns 1 if the lock was released, 0 if the lock was not established
 2199+ * by this thread (in which case the lock is not released), and NULL if the named
 2200+ * lock did not exist
22102201 */
2211 - public function unlock( $lockName, $method ) {
2212 - $lockName = $this->addQuotes( $lockName );
2213 - $result = $this->query( "SELECT RELEASE_LOCK($lockName)", $method );
2214 - $this->freeResult( $result );
2215 - }
 2202+ abstract public function unlock( $lockName, $method );
 2203+
 2204+ /**
 2205+ * Lock specific tables
 2206+ *
 2207+ * @param $read Array of tables to lock for read access
 2208+ * @param $write Array of tables to lock for write access
 2209+ * @param $method String name of caller
 2210+ */
 2211+ abstract public function lockTables( $read, $write, $method );
22162212
22172213 /**
 2214+ * Unlock specific tables
 2215+ *
 2216+ * @param $method String the caller
 2217+ */
 2218+ abstract public function unlockTables( $method );
 2219+
 2220+ /**
22182221 * Get search engine class. All subclasses of this
22192222 * need to implement this if they wish to use searching.
22202223 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r52457quick fix for r52382: fix errors in DatabasePostgres, lock() has incompatible...ialex13:25, 26 June 2009
r52477Cleanup for r52382: Call correct function and use tmestamp()demon22:09, 26 June 2009

Status & tagging log