MediaWiki
REL1_19
|
Database load balancing object. More...
Public Member Functions | |
__construct ($params) | |
allowLagged ($mode=null) | |
Disables/enables lag checks. | |
clearLagTimeCache () | |
Clear the cache for getLagTimes. | |
closeAll () | |
Close all open connections. | |
closeConnection ($conn) | |
Close a connection Using this function makes sure the LoadBalancer knows the connection is closed. | |
closeConnecton ($conn) | |
Deprecated function, typo in function name. | |
commitAll () | |
Commit transactions on all open connections. | |
commitMasterChanges () | |
Issue COMMIT only on master, only if queries were done on connection. | |
doWait ($index, $open=false) | |
Wait for a given slave to catch up to the master pos stored in $this. | |
forEachOpenConnection ($callback, $params=array()) | |
Call a function with each open connection object. | |
getAnyOpenConnection ($i) | |
Get any open connection to a given server index, local or foreign Returns false if there is no connection open. | |
& | getConnection ($i, $groups=array(), $wiki=false) |
Get a connection by index This is the main entry point for this class. | |
getLaggedSlaveMode () | |
getLagTimes ($wiki=false) | |
Get lag time for each server Results are cached for a short time in memcached, and indefinitely in the process cache. | |
getLoadMonitor () | |
Get a LoadMonitor instance. | |
getMasterPos () | |
Get the current master position for chronology control purposes. | |
getMaxLag ($wiki=false) | |
Get the hostname and lag time of the most-lagged slave. | |
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. | |
getServerCount () | |
Get the number of defined servers (not the number of open connections) | |
getServerInfo ($i) | |
Return the server info structure for a given index, or false if the index is invalid. | |
getServerName ($i) | |
Get the host name or IP address of the server with the specified index Prefer a readable name if available. | |
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. | |
isOpen ($index) | |
Test if the specified index represents an open connection. | |
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. | |
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. | |
pingAll () | |
reallyOpenConnection ($server, $dbNameOverride=false) | |
Really opens a connection. | |
reportConnectionError (&$conn) | |
reuseConnection ($conn) | |
Mark a foreign connection as being available for reuse under a different DB name or prefix. | |
safeGetLag ($conn) | |
Get the lag in seconds for a given connection, or zero if this load balancer does not have replication enabled. | |
setServerInfo ($i, $serverInfo) | |
Sets the server info structure for the given index. | |
sleep ($t) | |
Wait for a specified number of microseconds, and return the period waited. | |
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. | |
waitForAll ($pos) | |
Set the master wait position and wait for ALL slaves to catch up to it. | |
waitTimeout ($value=null) | |
Public Attributes | |
$mAllowLagged | |
$mConns | |
$mGroupLoads | |
$mLagTimes | |
$mLastError = 'Unknown error' | |
$mLoadMonitor | |
$mLoads | |
$mWaitTimeout | |
Private Attributes | |
$mErrorConnection | |
$mLaggedSlaveMode | |
$mLoadMonitorClass | |
$mParentInfo | |
$mReadIndex | |
$mServers | |
$mWaitForPos |
LoadBalancer::__construct | ( | $ | params | ) |
$params | Array with keys: servers Required. Array of server info structures. masterWaitTimeout Replication lag wait timeout loadMonitor Name of a class used to fetch server lag and load. |
Reimplemented in LoadBalancer_Single.
Definition at line 30 of file LoadBalancer.php.
LoadBalancer::allowLagged | ( | $ | mode = null | ) |
Disables/enables lag checks.
$mode | null |
Definition at line 941 of file LoadBalancer.php.
Clear the cache for getLagTimes.
Definition at line 1068 of file LoadBalancer.php.
Close all open connections.
Definition at line 839 of file LoadBalancer.php.
LoadBalancer::closeConnection | ( | $ | 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.
$conn | DatabaseBase |
Definition at line 871 of file LoadBalancer.php.
Referenced by closeConnecton().
LoadBalancer::closeConnecton | ( | $ | conn | ) |
Deprecated function, typo in function name.
$conn |
Definition at line 860 of file LoadBalancer.php.
References closeConnection(), and wfDeprecated().
Commit transactions on all open connections.
Definition at line 893 of file LoadBalancer.php.
Issue COMMIT only on master, only if queries were done on connection.
Definition at line 906 of file LoadBalancer.php.
References getWriterIndex().
LoadBalancer::doWait | ( | $ | index, |
$ | open = false |
||
) |
Wait for a given slave to catch up to the master pos stored in $this.
$index | |
$open | bool |
Definition at line 405 of file LoadBalancer.php.
References $result, getAnyOpenConnection(), openConnection(), and wfDebug().
Referenced by getReaderIndex(), waitFor(), and waitForAll().
LoadBalancer::forEachOpenConnection | ( | $ | callback, |
$ | params = array() |
||
) |
Call a function with each open connection object.
$callback | ||
array | $params |
Definition at line 970 of file LoadBalancer.php.
Get any open connection to a given server index, local or foreign Returns false if there is no connection open.
$i | int |
Definition at line 390 of file LoadBalancer.php.
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.
$i | Integer: server index |
$groups | Array: query groups |
$wiki | String: wiki ID |
Definition at line 444 of file LoadBalancer.php.
References $serverName, getReaderIndex(), getServerName(), getWriterIndex(), openConnection(), reportConnectionError(), wfDebug(), wfProfileIn(), wfProfileOut(), and wfWikiID().
Definition at line 932 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.
$wiki |
Definition at line 1026 of file LoadBalancer.php.
References getLoadMonitor(), and getServerCount().
Referenced by getRandomNonLagged().
Get a LoadMonitor instance.
Definition at line 83 of file LoadBalancer.php.
Referenced by getLagTimes(), and getReaderIndex().
Get the current master position for chronology control purposes.
Definition at line 817 of file LoadBalancer.php.
References getAnyOpenConnection(), and wfDebug().
LoadBalancer::getMaxLag | ( | $ | wiki = false | ) |
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. If there is no lag, the maximum lag will be reported as -1.
$wiki | string Wiki ID, or false for the default database |
Definition at line 991 of file LoadBalancer.php.
References getAnyOpenConnection(), getServerCount(), and openConnection().
LoadBalancer::getRandomNonLagged | ( | $ | loads, |
$ | wiki = false |
||
) |
$loads | array |
$wiki | bool |
Definition at line 139 of file LoadBalancer.php.
References getLagTimes(), pickRandom(), and wfDebugLog().
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
$group | bool |
$wiki | bool |
Definition at line 187 of file LoadBalancer.php.
References $wgDBAvgStatusPoll, $wgDBClusterTimeout, $wgDBtype, $wgReadOnly, doWait(), getLoadMonitor(), getRandomNonLagged(), getWriterIndex(), openConnection(), pickRandom(), reuseConnection(), sleep(), wfDebug(), wfDebugLog(), wfProfileIn(), and wfProfileOut().
Referenced by getConnection().
Get the number of defined servers (not the number of open connections)
Definition at line 771 of file LoadBalancer.php.
Referenced by getLagTimes(), getMaxLag(), and safeGetLag().
LoadBalancer::getServerInfo | ( | $ | i | ) |
Return the server info structure for a given index, or false if the index is invalid.
$i |
Definition at line 796 of file LoadBalancer.php.
LoadBalancer::getServerName | ( | $ | i | ) |
Get the host name or IP address of the server with the specified index Prefer a readable name if available.
$i |
Definition at line 781 of file LoadBalancer.php.
Referenced by getConnection().
Definition at line 742 of file LoadBalancer.php.
Referenced by commitMasterChanges(), getConnection(), and getReaderIndex().
LoadBalancer::haveIndex | ( | $ | i | ) |
Returns true if the specified index is a valid server index.
$i |
Definition at line 752 of file LoadBalancer.php.
LoadBalancer::isNonZeroLoad | ( | $ | i | ) |
Returns true if the specified index is valid and has non-zero load.
$i |
Definition at line 762 of file LoadBalancer.php.
LoadBalancer::isOpen | ( | $ | index | ) |
Test if the specified index represents an open connection.
$index | Integer: server index private |
Definition at line 664 of file LoadBalancer.php.
References getAnyOpenConnection().
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.
$i | Integer server index |
$wiki | String wiki ID to open |
private
Definition at line 559 of file LoadBalancer.php.
References openForeignConnection(), reallyOpenConnection(), wfDebug(), wfProfileIn(), and wfProfileOut().
Referenced by doWait(), 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.
$i | Integer: server index |
$wiki | String: wiki ID to open |
Definition at line 602 of file LoadBalancer.php.
References 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.
$x |
Definition at line 96 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.
$weights | array |
Definition at line 108 of file LoadBalancer.php.
Referenced by getRandomNonLagged(), and getReaderIndex().
LoadBalancer::reallyOpenConnection | ( | $ | server, |
$ | dbNameOverride = false |
||
) |
Really opens a connection.
Uncached. Returns a Database object whether or not the connection was successful. private
$server | |
$dbNameOverride | bool |
Reimplemented in LoadBalancer_Single.
Definition at line 680 of file LoadBalancer.php.
References DatabaseBase\factory(), and wfDebug().
Referenced by openConnection(), and openForeignConnection().
LoadBalancer::reportConnectionError | ( | &$ | conn | ) |
$conn |
DBConnectionError |
Definition at line 722 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.
DatabaseBase | $conn |
Definition at line 508 of file LoadBalancer.php.
References wfDebug().
Referenced by getReaderIndex().
LoadBalancer::safeGetLag | ( | $ | conn | ) |
Get the lag in seconds for a given connection, or zero if this load balancer does not have replication enabled.
This should be used in preference to Database::getLag() in cases where replication may not be in use, since there is no way to determine if replication is in use at the connection level without running potentially restricted queries such as SHOW SLAVE STATUS. Using this function instead of Database::getLag() avoids a fatal error in this case on many installations.
$conn | DatabaseBase |
Definition at line 1057 of file LoadBalancer.php.
References getServerCount().
LoadBalancer::setServerInfo | ( | $ | i, |
$ | serverInfo | ||
) |
Sets the server info structure for the given index.
Entry at index $i is created if it doesn't exist
$i | |
$serverInfo |
Definition at line 809 of file LoadBalancer.php.
LoadBalancer::sleep | ( | $ | t | ) |
Wait for a specified number of microseconds, and return the period waited.
$t | int |
Definition at line 342 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.
$pos | int |
Definition at line 356 of file LoadBalancer.php.
References doWait(), getAnyOpenConnection(), wfProfileIn(), and wfProfileOut().
LoadBalancer::waitForAll | ( | $ | pos | ) |
Set the master wait position and wait for ALL slaves to catch up to it.
$pos | int |
Definition at line 374 of file LoadBalancer.php.
References doWait(), wfProfileIn(), and wfProfileOut().
LoadBalancer::waitTimeout | ( | $ | value = null | ) |
$value | null |
Definition at line 925 of file LoadBalancer.php.
References wfSetVar().
LoadBalancer::$mAllowLagged |
Definition at line 18 of file LoadBalancer.php.
LoadBalancer::$mConns |
Definition at line 16 of file LoadBalancer.php.
LoadBalancer::$mErrorConnection [private] |
Definition at line 17 of file LoadBalancer.php.
LoadBalancer::$mGroupLoads |
Definition at line 16 of file LoadBalancer.php.
LoadBalancer::$mLaggedSlaveMode [private] |
Definition at line 20 of file LoadBalancer.php.
LoadBalancer::$mLagTimes |
Definition at line 21 of file LoadBalancer.php.
LoadBalancer::$mLastError = 'Unknown error' |
Definition at line 20 of file LoadBalancer.php.
LoadBalancer::$mLoadMonitor |
Definition at line 22 of file LoadBalancer.php.
LoadBalancer::$mLoadMonitorClass [private] |
Definition at line 22 of file LoadBalancer.php.
LoadBalancer::$mLoads |
Definition at line 16 of file LoadBalancer.php.
LoadBalancer::$mParentInfo [private] |
Definition at line 21 of file LoadBalancer.php.
LoadBalancer::$mReadIndex [private] |
Definition at line 18 of file LoadBalancer.php.
LoadBalancer::$mServers [private] |
Definition at line 16 of file LoadBalancer.php.
LoadBalancer::$mWaitForPos [private] |
Definition at line 19 of file LoadBalancer.php.
LoadBalancer::$mWaitTimeout |
Definition at line 19 of file LoadBalancer.php.