Index: trunk/phase3/maintenance/updateSearchIndex.inc |
— | — | @@ -75,7 +75,7 @@ |
76 | 76 | # Unlock searchindex |
77 | 77 | if ( $maxLockTime ) { |
78 | 78 | output( " --- Unlocking --" ); |
79 | | - unlockSearchindex( $dbw ); |
| 79 | + $dbw->unlockTables( 'updateSearchIndex.inc ' . __METHOD__ ); |
80 | 80 | output( "\n" ); |
81 | 81 | } |
82 | 82 | output( "Done\n" ); |
— | — | @@ -84,27 +84,14 @@ |
85 | 85 | function lockSearchindex( &$db ) { |
86 | 86 | $write = array( 'searchindex' ); |
87 | 87 | $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__ ); |
98 | 89 | } |
99 | 90 | |
100 | | -function unlockSearchindex( &$db ) { |
101 | | - $db->query( "UNLOCK TABLES", 'updateSearchIndex.inc ' . __METHOD__ ); |
102 | | -} |
103 | | - |
104 | 91 | # Unlock and lock again |
105 | 92 | # Since the lock is low-priority, queued reads will be able to complete |
106 | 93 | function relockSearchindex( &$db ) { |
107 | 94 | unlockSearchindex( $db ); |
108 | | - lockSearchindex( $db ); |
| 95 | + $db->unlockTables( 'updateSearchIndex.inc ' . __METHOD__ ); |
109 | 96 | } |
110 | 97 | |
111 | 98 | function output( $text ) { |
Index: trunk/phase3/includes/db/DatabaseMysql.php |
— | — | @@ -293,6 +293,44 @@ |
294 | 294 | $this->query( "SET net_read_timeout=$timeout" ); |
295 | 295 | $this->query( "SET net_write_timeout=$timeout" ); |
296 | 296 | } |
| 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 | + } |
297 | 335 | } |
298 | 336 | |
299 | 337 | /** |
Index: trunk/phase3/includes/db/Database.php |
— | — | @@ -2176,7 +2176,7 @@ |
2177 | 2177 | } |
2178 | 2178 | |
2179 | 2179 | /** |
2180 | | - * Acquire a lock |
| 2180 | + * Acquire a named lock |
2181 | 2181 | * |
2182 | 2182 | * Abstracted from Filestore::lock() so child classes can implement for |
2183 | 2183 | * their own needs. |
— | — | @@ -2185,35 +2185,38 @@ |
2186 | 2186 | * @param $method String: Name of method calling us |
2187 | 2187 | * @return bool |
2188 | 2188 | */ |
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 ); |
2194 | 2190 | |
2195 | | - if( $row->lockstatus == 1 ) { |
2196 | | - return true; |
2197 | | - } else { |
2198 | | - wfDebug( __METHOD__." failed to acquire lock\n" ); |
2199 | | - return false; |
2200 | | - } |
2201 | | - } |
2202 | 2191 | /** |
2203 | 2192 | * Release a lock. |
2204 | 2193 | * |
2205 | | - * @todo fixme - Figure out a way to return a bool |
2206 | | - * based on successful lock release. |
2207 | | - * |
2208 | 2194 | * @param $lockName String: Name of lock to release |
2209 | 2195 | * @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 |
2210 | 2201 | */ |
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 ); |
2216 | 2212 | |
2217 | 2213 | /** |
| 2214 | + * Unlock specific tables |
| 2215 | + * |
| 2216 | + * @param $method String the caller |
| 2217 | + */ |
| 2218 | + abstract public function unlockTables( $method ); |
| 2219 | + |
| 2220 | + /** |
2218 | 2221 | * Get search engine class. All subclasses of this |
2219 | 2222 | * need to implement this if they wish to use searching. |
2220 | 2223 | * |