LoadBalancer Class Reference
[Database]

Database load balancing object. More...

List of all members.

Public Member Functions

 __construct ($params)
 getLoadMonitor ()
 Get a LoadMonitor instance.
 parentInfo ($x=null)
 Get or set arbitrary data used by the parent object, usually an LBFactory.
 pickRandom ($weights)
 Given an array of non-normalised probabilities, this function will select an element and return the appropriate key.
 getRandomNonLagged ($loads, $wiki=false)
 getReaderIndex ($group=false, $wiki=false)
 Get the index of the reader connection, which may be a slave This takes into account load ratios and lag times.
 sleep ($t)
 Wait for a specified number of microseconds, and return the period waited.
 getGroupIndex ($group)
 Get a random server to use in a query group.
 waitFor ($pos)
 Set the master wait position If a DB_SLAVE connection has been opened already, waits Otherwise sets a variable telling it to wait if such a connection is opened.
 getAnyOpenConnection ($i)
 Get any open connection to a given server index, local or foreign Returns false if there is no connection open.
 doWait ($index)
 Wait for a given slave to catch up to the master pos stored in $this.
getConnection ($i, $groups=array(), $wiki=false)
 Get a connection by index This is the main entry point for this class.
 reuseConnection ($conn)
 Mark a foreign connection as being available for reuse under a different DB name or prefix.
 openConnection ($i, $wiki=false)
 Open a connection to the server given by the specified index Index must be an actual index into the array.
 openForeignConnection ($i, $wiki)
 Open a connection to a foreign DB, or return one if it is already open.
 isOpen ($index)
 Test if the specified index represents an open connection private.
 reallyOpenConnection ($server, $dbNameOverride=false)
 Really opens a connection.
 reportConnectionError (&$conn)
 getWriterIndex ()
 haveIndex ($i)
 Returns true if the specified index is a valid server index.
 isNonZeroLoad ($i)
 Returns true if the specified index is valid and has non-zero load.
 getServerCount ()
 Get the number of defined servers (not the number of open connections).
 getServerName ($i)
 Get the host name or IP address of the server with the specified index Prefer a readable name if available.
 getServerInfo ($i)
 Return the server info structure for a given index, or false if the index is invalid.
 getMasterPos ()
 Get the current master position for chronology control purposes.
 closeAll ()
 Close all open connections.
 closeConnecton ($conn)
 Close a connection Using this function makes sure the LoadBalancer knows the connection is closed.
 commitAll ()
 Commit transactions on all open connections.
 commitMasterChanges ()
 waitTimeout ($value=NULL)
 getLaggedSlaveMode ()
 allowLagged ($mode=null)
 pingAll ()
 forEachOpenConnection ($callback, $params=array())
 Call a function with each open connection object.
 getMaxLag ()
 Get the hostname and lag time of the most-lagged slave.
 getLagTimes ($wiki=false)
 Get lag time for each server Results are cached for a short time in memcached, and indefinitely in the process cache.

Static Public Member Functions

static newFromParams ($servers, $failFunction=false, $waitTimeout=10)

Public Attributes

 $mServers
 $mConns
 $mLoads
 $mGroupLoads
 $mFailFunction
 $mErrorConnection
 $mReadIndex
 $mAllowLagged
 $mWaitForPos
 $mWaitTimeout
 $mLaggedSlaveMode
 $mLastError = 'Unknown error'
 $mParentInfo
 $mLagTimes
 $mLoadMonitorClass
 $mLoadMonitor


Detailed Description

Database load balancing object.

Todo:
document

Definition at line 13 of file LoadBalancer.php.


Constructor & Destructor Documentation

LoadBalancer::__construct ( params  ) 

Parameters:
array $params Array with keys: servers Required. Array of server info structures. failFunction Deprecated, use exceptions instead. masterWaitTimeout Replication lag wait timeout loadMonitor Name of a class used to fetch server lag and load.

Definition at line 29 of file LoadBalancer.php.

References $i.


Member Function Documentation

LoadBalancer::allowLagged ( mode = null  ) 

Definition at line 843 of file LoadBalancer.php.

References $mode.

LoadBalancer::closeAll (  ) 

Close all open connections.

Definition at line 766 of file LoadBalancer.php.

LoadBalancer::closeConnecton ( conn  ) 

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.

Definition at line 786 of file LoadBalancer.php.

LoadBalancer::commitAll (  ) 

Commit transactions on all open connections.

Definition at line 808 of file LoadBalancer.php.

LoadBalancer::commitMasterChanges (  ) 

Definition at line 819 of file LoadBalancer.php.

References $type, and getWriterIndex().

LoadBalancer::doWait ( index  ) 

Wait for a given slave to catch up to the master pos stored in $this.

Definition at line 377 of file LoadBalancer.php.

References $result, getAnyOpenConnection(), and wfDebug().

Referenced by getReaderIndex(), and waitFor().

LoadBalancer::forEachOpenConnection ( callback,
params = array() 
)

Call a function with each open connection object.

Definition at line 866 of file LoadBalancer.php.

LoadBalancer::getAnyOpenConnection ( i  ) 

Get any open connection to a given server index, local or foreign Returns false if there is no connection open.

Definition at line 365 of file LoadBalancer.php.

References $i, and $type.

Referenced by doWait(), getMasterPos(), getMaxLag(), isOpen(), and waitFor().

& LoadBalancer::getConnection ( i,
groups = array(),
wiki = false 
)

Get a connection by index This is the main entry point for this class.

Parameters:
int $i Database
array $groups Query groups
string $wiki Wiki ID

Definition at line 405 of file LoadBalancer.php.

References $i, $wgDBtype, getReaderIndex(), getServerName(), getWriterIndex(), openConnection(), reportConnectionError(), wfDebug(), wfProfileIn(), wfProfileOut(), and wfWikiID().

LoadBalancer::getGroupIndex ( group  ) 

Get a random server to use in a query group.

Deprecated:
use getReaderIndex

Definition at line 338 of file LoadBalancer.php.

References getReaderIndex().

LoadBalancer::getLaggedSlaveMode (  ) 

Definition at line 838 of file LoadBalancer.php.

LoadBalancer::getLagTimes ( wiki = false  ) 

Get lag time for each server Results are cached for a short time in memcached, and indefinitely in the process cache.

Definition at line 906 of file LoadBalancer.php.

References getLoadMonitor().

Referenced by getRandomNonLagged().

LoadBalancer::getLoadMonitor (  ) 

Get a LoadMonitor instance.

Definition at line 82 of file LoadBalancer.php.

Referenced by getLagTimes(), and getReaderIndex().

LoadBalancer::getMasterPos (  ) 

Get the current master position for chronology control purposes.

Returns:
mixed

Definition at line 744 of file LoadBalancer.php.

References $i, getAnyOpenConnection(), and wfDebug().

LoadBalancer::getMaxLag (  ) 

Get the hostname and lag time of the most-lagged slave.

This is useful for maintenance scripts that need to throttle their updates. May attempt to open connections to slaves on the default DB.

Definition at line 882 of file LoadBalancer.php.

References $i, $maxLag, getAnyOpenConnection(), and openConnection().

LoadBalancer::getRandomNonLagged ( loads,
wiki = false 
)

Definition at line 128 of file LoadBalancer.php.

References $i, getLagTimes(), pickRandom(), and wfDebug().

Referenced by getReaderIndex().

LoadBalancer::getReaderIndex ( group = false,
wiki = false 
)

Get the index of the reader connection, which may be a slave This takes into account load ratios and lag times.

It should always return a consistent index during a given invocation

Side effect: opens connections to databases

Definition at line 173 of file LoadBalancer.php.

References $i, $wgDBAvgStatusPoll, $wgDBClusterTimeout, $wgDBtype, $wgReadOnly, doWait(), getLoadMonitor(), getRandomNonLagged(), getWriterIndex(), openConnection(), pickRandom(), reuseConnection(), sleep(), wfDebug(), wfDebugLog(), wfMsgNoDBForContent(), wfProfileIn(), and wfProfileOut().

Referenced by getConnection(), and getGroupIndex().

LoadBalancer::getServerCount (  ) 

Get the number of defined servers (not the number of open connections).

Definition at line 711 of file LoadBalancer.php.

LoadBalancer::getServerInfo ( i  ) 

Return the server info structure for a given index, or false if the index is invalid.

Definition at line 732 of file LoadBalancer.php.

References $i.

LoadBalancer::getServerName ( i  ) 

Get the host name or IP address of the server with the specified index Prefer a readable name if available.

Definition at line 719 of file LoadBalancer.php.

References $i.

Referenced by getConnection().

LoadBalancer::getWriterIndex (  ) 

Definition at line 690 of file LoadBalancer.php.

Referenced by commitMasterChanges(), getConnection(), and getReaderIndex().

LoadBalancer::haveIndex ( i  ) 

Returns true if the specified index is a valid server index.

Definition at line 697 of file LoadBalancer.php.

References $i.

LoadBalancer::isNonZeroLoad ( i  ) 

Returns true if the specified index is valid and has non-zero load.

Definition at line 704 of file LoadBalancer.php.

References $i.

LoadBalancer::isOpen ( index  ) 

Test if the specified index represents an open connection private.

Definition at line 620 of file LoadBalancer.php.

References getAnyOpenConnection().

static LoadBalancer::newFromParams ( servers,
failFunction = false,
waitTimeout = 10 
) [static]

Definition at line 74 of file LoadBalancer.php.

LoadBalancer::openConnection ( i,
wiki = false 
)

Open a connection to the server given by the specified index Index must be an actual index into the array.

If the server is already open, returns it.

On error, returns false, and the connection which caused the error will be available via $this->mErrorConnection.

Parameters:
integer $i Server index
string $wiki Wiki ID to open
Returns:
Database
private

Definition at line 518 of file LoadBalancer.php.

References $i, openForeignConnection(), reallyOpenConnection(), wfDebug(), wfProfileIn(), and wfProfileOut().

Referenced by getConnection(), getMaxLag(), and getReaderIndex().

LoadBalancer::openForeignConnection ( i,
wiki 
)

Open a connection to a foreign DB, or return one if it is already open.

Increments a reference count on the returned connection which locks the connection to the requested wiki. This reference count can be decremented by calling reuseConnection().

If a connection is open to the appropriate server already, but with the wrong database, it will be switched to the right database and returned, as long as it has been freed first with reuseConnection().

On error, returns false, and the connection which caused the error will be available via $this->mErrorConnection.

Parameters:
integer $i Server index
string $wiki Wiki ID to open
Returns:
Database

Definition at line 561 of file LoadBalancer.php.

References $i, $prefix, reallyOpenConnection(), wfDebug(), wfHostname(), wfProfileIn(), wfProfileOut(), and wfSplitWikiID().

Referenced by openConnection().

LoadBalancer::parentInfo ( x = null  ) 

Get or set arbitrary data used by the parent object, usually an LBFactory.

Definition at line 93 of file LoadBalancer.php.

References wfSetVar().

LoadBalancer::pickRandom ( weights  ) 

Given an array of non-normalised probabilities, this function will select an element and return the appropriate key.

Definition at line 101 of file LoadBalancer.php.

References $i.

Referenced by getRandomNonLagged(), and getReaderIndex().

LoadBalancer::pingAll (  ) 

Definition at line 849 of file LoadBalancer.php.

References $success.

LoadBalancer::reallyOpenConnection ( server,
dbNameOverride = false 
)

Really opens a connection.

Uncached. Returns a Database object whether or not the connection was successful. private

Definition at line 632 of file LoadBalancer.php.

References $db, $flags, $password, $type, $user, and wfDebug().

Referenced by openConnection(), and openForeignConnection().

LoadBalancer::reportConnectionError ( &$  conn  ) 

Definition at line 663 of file LoadBalancer.php.

References wfLogDBError(), wfProfileIn(), and wfProfileOut().

Referenced by getConnection().

LoadBalancer::reuseConnection ( conn  ) 

Mark a foreign connection as being available for reuse under a different DB name or prefix.

This mechanism is reference-counted, and must be called the same number of times as getConnection() to work.

Definition at line 467 of file LoadBalancer.php.

References $prefix, and wfDebug().

Referenced by getReaderIndex().

LoadBalancer::sleep ( t  ) 

Wait for a specified number of microseconds, and return the period waited.

Definition at line 326 of file LoadBalancer.php.

References $t, wfDebug(), wfProfileIn(), and wfProfileOut().

Referenced by getReaderIndex().

LoadBalancer::waitFor ( pos  ) 

Set the master wait position If a DB_SLAVE connection has been opened already, waits Otherwise sets a variable telling it to wait if such a connection is opened.

Definition at line 347 of file LoadBalancer.php.

References $i, doWait(), getAnyOpenConnection(), wfProfileIn(), and wfProfileOut().

LoadBalancer::waitTimeout ( value = NULL  ) 

Definition at line 834 of file LoadBalancer.php.

References wfSetVar().


Member Data Documentation

LoadBalancer::$mAllowLagged

Definition at line 16 of file LoadBalancer.php.

LoadBalancer::$mConns

Definition at line 14 of file LoadBalancer.php.

LoadBalancer::$mErrorConnection

Definition at line 15 of file LoadBalancer.php.

LoadBalancer::$mFailFunction

Definition at line 15 of file LoadBalancer.php.

LoadBalancer::$mGroupLoads

Definition at line 14 of file LoadBalancer.php.

LoadBalancer::$mLaggedSlaveMode

Definition at line 18 of file LoadBalancer.php.

LoadBalancer::$mLagTimes

Definition at line 19 of file LoadBalancer.php.

LoadBalancer::$mLastError = 'Unknown error'

Definition at line 18 of file LoadBalancer.php.

LoadBalancer::$mLoadMonitor

Definition at line 20 of file LoadBalancer.php.

LoadBalancer::$mLoadMonitorClass

Definition at line 20 of file LoadBalancer.php.

LoadBalancer::$mLoads

Definition at line 14 of file LoadBalancer.php.

LoadBalancer::$mParentInfo

Definition at line 19 of file LoadBalancer.php.

LoadBalancer::$mReadIndex

Definition at line 16 of file LoadBalancer.php.

LoadBalancer::$mServers

Definition at line 14 of file LoadBalancer.php.

LoadBalancer::$mWaitForPos

Definition at line 17 of file LoadBalancer.php.

LoadBalancer::$mWaitTimeout

Definition at line 17 of file LoadBalancer.php.


The documentation for this class was generated from the following file:

Generated on Sat Sep 5 02:08:41 2009 for MediaWiki by  doxygen 1.5.9