Documentation
authorSam Reed <reedy@users.mediawiki.org>
Wed, 25 May 2011 18:41:31 +0000 (18:41 +0000)
committerSam Reed <reedy@users.mediawiki.org>
Wed, 25 May 2011 18:41:31 +0000 (18:41 +0000)
includes/db/DatabaseError.php
includes/db/LBFactory_Multi.php
includes/db/LBFactory_Single.php
includes/db/LoadBalancer.php
includes/db/LoadMonitor.php

index 430b2ca..c1c1dde 100644 (file)
@@ -1,18 +1,19 @@
 <?php
-/******************************************************************************
- * Error classes
- *****************************************************************************/
 
 /**
  * Database error base class
  * @ingroup Database
  */
 class DBError extends MWException {
+
+       /**
+        * @var DatabaseBase
+        */
        public $db;
 
        /**
         * Construct a database error
-        * @param $db Database object which threw the error
+        * @param $db DatabaseBase object which threw the error
         * @param $error String A simple error message to be used for debugging
         */
        function __construct( DatabaseBase &$db, $error ) {
index 0d411ec..33c02b5 100644 (file)
@@ -98,6 +98,10 @@ class LBFactory_Multi extends LBFactory {
                return $section;
        }
 
+       /**
+        * @param $wiki
+        * @return LoadBalancer
+        */
        function newMainLB( $wiki = false ) {
                list( $dbName, ) = $this->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;
index a0089d5..17b348d 100644 (file)
@@ -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;
        }
index a25aec4..bfbc9d8 100644 (file)
@@ -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() {
index 36e9fce..f8bf3af 100644 (file)
@@ -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;