r106695 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106694‎ | r106695 | r106696 >
Date:20:46, 19 December 2011
Author:aaron
Status:deferred
Tags:
Comment:
* Made DBLockManager allow 'localDBMaster' as a DB name, which will automatically use the local master without the need for extra config.
* Comment style tweaks.
Modified paths:
  • /branches/FileBackend/phase3/includes/filerepo/backend/lockmanager/DBLockManager.php (modified) (history)
  • /branches/FileBackend/phase3/includes/filerepo/backend/lockmanager/LSLockManager.php (modified) (history)

Diff [purge]

Index: branches/FileBackend/phase3/includes/filerepo/backend/lockmanager/LSLockManager.php
@@ -139,7 +139,7 @@
140140 }
141141
142142 /**
143 - * Get a connection to a lock server and acquire locks on $keys.
 143+ * Get a connection to a lock server and acquire locks on $keys
144144 *
145145 * @param $lockSrv string
146146 * @param $keys Array
@@ -192,7 +192,7 @@
193193 }
194194
195195 /**
196 - * Attempt to acquire locks with the peers for a bucket.
 196+ * Attempt to acquire locks with the peers for a bucket
197197 *
198198 * @param $bucket integer
199199 * @param $keys Array List of resource keys to lock
@@ -249,7 +249,7 @@
250250 }
251251
252252 /**
253 - * Release all locks that this session is holding.
 253+ * Release all locks that this session is holding
254254 *
255255 * @return Status
256256 */
@@ -265,7 +265,7 @@
266266 }
267267
268268 /**
269 - * Get the bucket for lock key.
 269+ * Get the bucket for lock key
270270 *
271271 * @param $key string (40 char hex key)
272272 * @return integer
Index: branches/FileBackend/phase3/includes/filerepo/backend/lockmanager/DBLockManager.php
@@ -46,6 +46,8 @@
4747 * 'flags' - DB flags (see DatabaseBase)
4848 * 'dbsByBucket' : Array of 1-16 consecutive integer keys, starting from 0,
4949 * each having an odd-numbered list of DB names (peers) as values.
 50+ * Any DB named 'localDBMaster' will automatically use the DB master
 51+ * settings for this wiki (without the need for a dbServers entry).
5052 * 'lockExpiry' : Lock timeout (seconds) for dropped connections. [optional]
5153 * This tells the DB server how long to wait before assuming
5254 * connection failure and releasing all the locks for a session.
@@ -232,11 +234,19 @@
233235 */
234236 protected function getConnection( $lockDb ) {
235237 if ( !isset( $this->conns[$lockDb] ) ) {
236 - $config = $this->dbServers[$lockDb];
237 - $this->conns[$lockDb] = DatabaseBase::factory( $config['type'], $config );
238 - if ( !$this->conns[$lockDb] ) {
 238+ $db = null;
 239+ if ( $lockDb === 'localDBMaster' ) {
 240+ $lb = wfGetLBFactory()->newMainLB();
 241+ $db = $lb->getConnection( DB_MASTER );
 242+ } elseif ( isset( $this->dbServers[$lockDb] ) ) {
 243+ $config = $this->dbServers[$lockDb];
 244+ $db = DatabaseBase::factory( $config['type'], $config );
 245+ }
 246+ if ( !$db ) {
239247 return null; // config error?
240248 }
 249+ $this->conns[$lockDb] = $db;
 250+ $this->conns[$lockDb]->clearFlag( DBO_TRX );
241251 # If the connection drops, try to avoid letting the DB rollback
242252 # and release the locks before the file operations are finished.
243253 # This won't handle the case of DB server restarts however.

Status & tagging log