[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Inject "srvCache" and local DB connections into LockManagerDB
jenkins-bot has submitted this change and it was merged. Change subject: Inject "srvCache" and local DB connections into LockManagerDB .. Inject "srvCache" and local DB connections into LockManagerDB * Also simplified the srvCache variable usage to be unconditional. * The wfRandomString() call has also been replaced. Change-Id: I17e83b17ec549906ee200bbe9eb2f0b151423e26 --- M includes/DefaultSettings.php M includes/filebackend/lockmanager/DBLockManager.php M includes/filebackend/lockmanager/LockManagerGroup.php M includes/filebackend/lockmanager/MySqlLockManager.php 4 files changed, 49 insertions(+), 52 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 135c3e5..be858c2 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -644,6 +644,10 @@ * See LockManager::__construct() for more details. * Additional parameters are specific to the lock manager class used. * These settings should be global to all wikis. + * + * When using DBLockManager, the 'dbsByBucket' map can reference 'localDBMaster' as + * a peer database in each bucket. This will result in an extra connection to the domain + * that the LockManager services, which must also be a valid wiki ID. */ $wgLockManagers = []; diff --git a/includes/filebackend/lockmanager/DBLockManager.php b/includes/filebackend/lockmanager/DBLockManager.php index 4667dde..c36ff48 100644 --- a/includes/filebackend/lockmanager/DBLockManager.php +++ b/includes/filebackend/lockmanager/DBLockManager.php @@ -36,7 +36,7 @@ * @since 1.19 */ abstract class DBLockManager extends QuorumLockManager { - /** @var array[] Map of DB names to server config */ + /** @var array[]|IDatabase[] Map of (DB names => server config or IDatabase) */ protected $dbServers; // (DB name => server config array) /** @var BagOStuff */ protected $statusCache; @@ -63,19 +63,15 @@ * - flags : DB flags (see DatabaseBase) * - dbsByBucket : Array of 1-16 consecutive integer keys, starting from 0, * each having an odd-numbered list of DB names (peers) as values. -* Any DB named 'localDBMaster' will automatically use the DB master -* settings for this wiki (without the need for a dbServers entry). -* Only use 'localDBMaster' if the domain is a valid wiki ID. * - lockExpiry : Lock timeout (seconds) for dropped connections. [optional] * This tells the DB server how long to wait before assuming * connection failure and releasing all the locks for a session. +* - srvCache: A BagOStuff instance using APC or the like. */ public function __construct( array $config ) { parent::__construct( $config ); - $this->dbServers = isset( $config['dbServers'] ) - ? $config['dbServers'] - : []; // likely just using 'localDBMaster' + $this->dbServers = $config['dbServers']; // Sanitize srvsByBucket config to prevent PHP errors $this->srvsByBucket = array_filter( $config['dbsByBucket'], 'is_array' ); $this->srvsByBucket = array_values( $this->srvsByBucket ); // consecutive @@ -90,19 +86,25 @@ ? 60 // pick a safe-ish number to match DB timeout default : $this->lockExpiry; // cover worst case - foreach ( $this->srvsByBucket as $bucket ) { - if ( count( $bucket ) > 1 ) { // multiple peers - // Tracks peers that couldn't be queried recently to avoid lengthy - // connection timeouts. This is useless if each bucket has one peer. - $this->statusCache = ObjectCache::getLocalServerInstance(); - break; - } - } + // Tracks peers that couldn't be queried recently to avoid lengthy + // connection timeouts. This is useless if each bucket has one peer. + $this->statusCache = isset( $config['srvCache'] ) + ? $config['srvCache'] + : new HashBagOStuff(); - $this->session = wfRandomString( 31 ); + $random = []; + for ( $i = 1; $i <= 5; ++$i ) { + $random[] = mt_rand( 0, 0xFFF ); + } + $this->session = substr( md5( implode( '-', $random ) ), 0, 31 ); } - // @todo change this code to work in one batch + /** +* @TODO change this code to work in one
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Inject "srvCache" and local DB connections into LockManagerDB
Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/311321 Change subject: Inject "srvCache" and local DB connections into LockManagerDB .. Inject "srvCache" and local DB connections into LockManagerDB * Also simplified the srvCache variable usage to be unconditional. * The wfRandomString() call has also been replaced. Change-Id: I17e83b17ec549906ee200bbe9eb2f0b151423e26 --- M includes/DefaultSettings.php M includes/filebackend/lockmanager/DBLockManager.php M includes/filebackend/lockmanager/LockManagerGroup.php 3 files changed, 50 insertions(+), 47 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/21/311321/1 diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 135c3e5..be858c2 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -644,6 +644,10 @@ * See LockManager::__construct() for more details. * Additional parameters are specific to the lock manager class used. * These settings should be global to all wikis. + * + * When using DBLockManager, the 'dbsByBucket' map can reference 'localDBMaster' as + * a peer database in each bucket. This will result in an extra connection to the domain + * that the LockManager services, which must also be a valid wiki ID. */ $wgLockManagers = []; diff --git a/includes/filebackend/lockmanager/DBLockManager.php b/includes/filebackend/lockmanager/DBLockManager.php index 4667dde..c36ff48 100644 --- a/includes/filebackend/lockmanager/DBLockManager.php +++ b/includes/filebackend/lockmanager/DBLockManager.php @@ -36,7 +36,7 @@ * @since 1.19 */ abstract class DBLockManager extends QuorumLockManager { - /** @var array[] Map of DB names to server config */ + /** @var array[]|IDatabase[] Map of (DB names => server config or IDatabase) */ protected $dbServers; // (DB name => server config array) /** @var BagOStuff */ protected $statusCache; @@ -63,19 +63,15 @@ * - flags : DB flags (see DatabaseBase) * - dbsByBucket : Array of 1-16 consecutive integer keys, starting from 0, * each having an odd-numbered list of DB names (peers) as values. -* Any DB named 'localDBMaster' will automatically use the DB master -* settings for this wiki (without the need for a dbServers entry). -* Only use 'localDBMaster' if the domain is a valid wiki ID. * - lockExpiry : Lock timeout (seconds) for dropped connections. [optional] * This tells the DB server how long to wait before assuming * connection failure and releasing all the locks for a session. +* - srvCache: A BagOStuff instance using APC or the like. */ public function __construct( array $config ) { parent::__construct( $config ); - $this->dbServers = isset( $config['dbServers'] ) - ? $config['dbServers'] - : []; // likely just using 'localDBMaster' + $this->dbServers = $config['dbServers']; // Sanitize srvsByBucket config to prevent PHP errors $this->srvsByBucket = array_filter( $config['dbsByBucket'], 'is_array' ); $this->srvsByBucket = array_values( $this->srvsByBucket ); // consecutive @@ -90,19 +86,25 @@ ? 60 // pick a safe-ish number to match DB timeout default : $this->lockExpiry; // cover worst case - foreach ( $this->srvsByBucket as $bucket ) { - if ( count( $bucket ) > 1 ) { // multiple peers - // Tracks peers that couldn't be queried recently to avoid lengthy - // connection timeouts. This is useless if each bucket has one peer. - $this->statusCache = ObjectCache::getLocalServerInstance(); - break; - } - } + // Tracks peers that couldn't be queried recently to avoid lengthy + // connection timeouts. This is useless if each bucket has one peer. + $this->statusCache = isset( $config['srvCache'] ) + ? $config['srvCache'] + : new HashBagOStuff(); - $this->session = wfRandomString( 31 ); + $random = []; + for ( $i = 1; $i <= 5; ++$i ) { + $random[] = mt_rand( 0, 0xFFF ); + } + $this->session = substr( md5( implode( '-', $random ) ), 0, 31 ); } - // @todo change this code to work in one batch + /** +* @TODO change this code to work in one batch +