From 6fac268c191ca7aa54d1a2bc1c15d238db692563 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Wed, 25 May 2011 18:41:31 +0000 Subject: [PATCH] Documentation --- includes/db/DatabaseError.php | 9 +++---- includes/db/LBFactory_Multi.php | 20 ++++++++++++++++ includes/db/LBFactory_Single.php | 15 ++++++++++++ includes/db/LoadBalancer.php | 40 ++++++++++++++++++++++++++------ includes/db/LoadMonitor.php | 10 ++++++++ 5 files changed, 83 insertions(+), 11 deletions(-) diff --git a/includes/db/DatabaseError.php b/includes/db/DatabaseError.php index 430b2cacc6..c1c1dde62b 100644 --- a/includes/db/DatabaseError.php +++ b/includes/db/DatabaseError.php @@ -1,18 +1,19 @@ getDBNameAndPrefix( $wiki ); $section = $this->getSectionForWiki( $wiki ); @@ -111,6 +115,10 @@ class LBFactory_Multi extends LBFactory { return $this->newLoadBalancer( $this->serverTemplate, $this->sectionLoads[$section], $groupLoads ); } + /** + * @param $wiki + * @return LoadBalancer + */ function getMainLB( $wiki = false ) { $section = $this->getSectionForWiki( $wiki ); if ( !isset( $this->mainLBs[$section] ) ) { @@ -122,6 +130,11 @@ class LBFactory_Multi extends LBFactory { return $this->mainLBs[$section]; } + /** + * @param $cluster + * @param $wiki + * @return LoadBalancer + */ function newExternalLB( $cluster, $wiki = false ) { if ( !isset( $this->externalLoads[$cluster] ) ) { throw new MWException( __METHOD__.": Unknown cluster \"$cluster\"" ); @@ -136,6 +149,11 @@ class LBFactory_Multi extends LBFactory { return $this->newLoadBalancer( $template, $this->externalLoads[$cluster], array() ); } + /** + * @param $cluster + * @param $wiki + * @return LoadBalancer + */ function &getExternalLB( $cluster, $wiki = false ) { if ( !isset( $this->extLBs[$cluster] ) ) { $this->extLBs[$cluster] = $this->newExternalLB( $cluster, $wiki ); @@ -146,6 +164,8 @@ class LBFactory_Multi extends LBFactory { /** * Make a new load balancer object based on template and load array + * + * @return LoadBalancer */ function newLoadBalancer( $template, $loads, $groupLoads ) { global $wgMasterWaitTimeout; diff --git a/includes/db/LBFactory_Single.php b/includes/db/LBFactory_Single.php index a0089d51f8..17b348d801 100644 --- a/includes/db/LBFactory_Single.php +++ b/includes/db/LBFactory_Single.php @@ -14,18 +14,30 @@ class LBFactory_Single extends LBFactory { $this->lb = new LoadBalancer_Single( $conf ); } + /** + * @return LoadBalancer_Single + */ function newMainLB( $wiki = false ) { return $this->lb; } + /** + * @return LoadBalancer_Single + */ function getMainLB( $wiki = false ) { return $this->lb; } + /** + * @return LoadBalancer_Single + */ function newExternalLB( $cluster, $wiki = false ) { return $this->lb; } + /** + * @return LoadBalancer_Single + */ function &getExternalLB( $cluster, $wiki = false ) { return $this->lb; } @@ -55,6 +67,9 @@ class LoadBalancer_Single extends LoadBalancer { ) ) ) ); } + /** + * @return DatabaseBase + */ function reallyOpenConnection( $server, $dbNameOverride = false ) { return $this->db; } diff --git a/includes/db/LoadBalancer.php b/includes/db/LoadBalancer.php index a25aec4dc5..bfbc9d8c26 100644 --- a/includes/db/LoadBalancer.php +++ b/includes/db/LoadBalancer.php @@ -89,6 +89,10 @@ class LoadBalancer { /** * Given an array of non-normalised probabilities, this function will select * an element and return the appropriate key + * + * @param $weights + * + * @return int */ function pickRandom( $weights ) { if ( !is_array( $weights ) || count( $weights ) == 0 ) { @@ -116,6 +120,11 @@ class LoadBalancer { return $i; } + /** + * @param $loads + * @param $wiki bool + * @return bool|int|string + */ function getRandomNonLagged( $loads, $wiki = false ) { # Unset excessively lagged servers $lags = $this->getLagTimes( $wiki ); @@ -160,6 +169,9 @@ class LoadBalancer { * always return a consistent index during a given invocation * * Side effect: opens connections to databases + * @param $group bool + * @param $wiki bool + * @return bool|int|string */ function getReaderIndex( $group = false, $wiki = false ) { global $wgReadOnly, $wgDBClusterTimeout, $wgDBAvgStatusPoll, $wgDBtype; @@ -517,8 +529,8 @@ class LoadBalancer { * On error, returns false, and the connection which caused the * error will be available via $this->mErrorConnection. * - * @param $i Integer: server index - * @param $wiki String: wiki ID to open + * @param $i Integer server index + * @param $wiki String wiki ID to open * @return DatabaseBase * * @access private @@ -626,6 +638,7 @@ class LoadBalancer { * * @param $index Integer: server index * @access private + * @return bool */ function isOpen( $index ) { if( !is_integer( $index ) ) { @@ -638,6 +651,8 @@ class LoadBalancer { * Really opens a connection. Uncached. * Returns a Database object whether or not the connection was successful. * @access private + * + * @return DatabaseBase */ function reallyOpenConnection( $server, $dbNameOverride = false ) { if( !is_array( $server ) ) { @@ -693,6 +708,8 @@ class LoadBalancer { /** * Returns true if the specified index is a valid server index + * + * @return bool */ function haveIndex( $i ) { return array_key_exists( $i, $this->mServers ); @@ -700,6 +717,8 @@ class LoadBalancer { /** * Returns true if the specified index is valid and has non-zero load + * + * @return bool */ function isNonZeroLoad( $i ) { return array_key_exists( $i, $this->mServers ) && $this->mLoads[$i] != 0; @@ -707,6 +726,8 @@ class LoadBalancer { /** * Get the number of defined servers (not the number of open connections) + * + * @return int */ function getServerCount() { return count( $this->mServers ); @@ -787,6 +808,8 @@ class LoadBalancer { /** * Deprecated function, typo in function name + * + * @deprecated in 1.18 */ function closeConnecton( $conn ) { $this->closeConnection( $conn ); @@ -796,7 +819,7 @@ class LoadBalancer { * Close a connection * Using this function makes sure the LoadBalancer knows the connection is closed. * If you use $conn->close() directly, the load balancer won't update its state. - * @param $conn + * @param $conn * @return void */ function closeConnection( $conn ) { @@ -831,7 +854,9 @@ class LoadBalancer { } } - /* Issue COMMIT only on master, only if queries were done on connection */ + /** + * Issue COMMIT only on master, only if queries were done on connection + */ function commitMasterChanges() { // Always 0, but who knows.. :) $masterIndex = $this->getWriterIndex(); @@ -856,10 +881,11 @@ class LoadBalancer { } /* Disables/enables lag checks */ - function allowLagged($mode=null) { - if ($mode===null) + function allowLagged( $mode = null ) { + if ( $mode === null) { return $this->mAllowLagged; - $this->mAllowLagged=$mode; + } + $this->mAllowLagged = $mode; } function pingAll() { diff --git a/includes/db/LoadMonitor.php b/includes/db/LoadMonitor.php index 36e9fce886..f8bf3af1d3 100644 --- a/includes/db/LoadMonitor.php +++ b/includes/db/LoadMonitor.php @@ -72,9 +72,19 @@ class LoadMonitor_MySQL implements LoadMonitor { $this->parent = $parent; } + /** + * @param $loads + * @param $group bool + * @param $wiki bool + */ function scaleLoads( &$loads, $group = false, $wiki = false ) { } + /** + * @param $serverIndexes + * @param $wiki + * @return array + */ function getLagTimes( $serverIndexes, $wiki ) { wfProfileIn( __METHOD__ ); $expiry = 5; -- 2.20.1