MediaWiki  1.29.2
Wikimedia\Rdbms\ILoadBalancer Interface Reference

Database cluster connection, tracking, load balancing, and transaction manager interface. More...

Inheritance diagram for Wikimedia\Rdbms\ILoadBalancer:

Public Member Functions

 __construct (array $params)
 Construct a manager of IDatabase connection objects. More...
 
 allowLagged ( $mode=null)
 Disables/enables lag checks. More...
 
 approveMasterChanges (array $options)
 Perform all pre-commit checks for things like replication safety. More...
 
 beginMasterChanges ( $fname=__METHOD__)
 Flush any master transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set) More...
 
 closeAll ()
 Close all open connections. More...
 
 closeConnection (IDatabase $conn)
 Close a connection. More...
 
 commitAll ( $fname=__METHOD__)
 Commit transactions on all open connections. More...
 
 commitMasterChanges ( $fname=__METHOD__)
 Issue COMMIT on all master connections where writes where done. More...
 
 disable ()
 Disable this load balancer. More...
 
 finalizeMasterChanges ()
 Perform all pre-commit callbacks that remain part of the atomic transactions and disable any post-commit callbacks until runMasterPostTrxCallbacks() More...
 
 flushReplicaSnapshots ( $fname=__METHOD__)
 Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshot. More...
 
 forEachOpenConnection ( $callback, array $params=[])
 Call a function with each open connection object. More...
 
 forEachOpenMasterConnection ( $callback, array $params=[])
 Call a function with each open connection object to a master. More...
 
 forEachOpenReplicaConnection ( $callback, array $params=[])
 Call a function with each open replica DB connection object. More...
 
 getAnyOpenConnection ( $i)
 Get any open connection to a given server index, local or foreign. More...
 
 getConnection ( $i, $groups=[], $domain=false)
 Get a connection by index. More...
 
 getConnectionRef ( $i, $groups=[], $domain=false)
 Get a database connection handle reference. More...
 
 getLaggedReplicaMode ( $domain=false)
 
 getLagTimes ( $domain=false)
 Get an estimate of replication lag (in seconds) for each server. More...
 
 getLazyConnectionRef ( $i, $groups=[], $domain=false)
 Get a database connection handle reference without connecting yet. More...
 
 getMaintenanceConnectionRef ( $db, $groups=[], $domain=false)
 Get a maintenance database connection handle reference for migrations and schema changes. More...
 
 getMasterPos ()
 Get the current master position for chronology control purposes. More...
 
 getMaxLag ( $domain=false)
 Get the hostname and lag time of the most-lagged replica DB. More...
 
 getReaderIndex ( $group=false, $domain=false)
 Get the index of the reader connection, which may be a replica DB. More...
 
 getReadOnlyReason ( $domain=false, IDatabase $conn=null)
 
 getServerCount ()
 Get the number of defined servers (not the number of open connections) More...
 
 getServerInfo ( $i)
 Return the server info structure for a given index, or false if the index is invalid. More...
 
 getServerName ( $i)
 Get the host name or IP address of the server with the specified index Prefer a readable name if available. More...
 
 getWriterIndex ()
 
 hasMasterChanges ()
 Determine if there are pending changes in a transaction by this thread. More...
 
 hasMasterConnection ()
 
 hasOrMadeRecentMasterChanges ( $age=null)
 Check if this load balancer object had any recent or still pending writes issued against it by this PHP thread. More...
 
 haveIndex ( $i)
 Returns true if the specified index is a valid server index. More...
 
 isNonZeroLoad ( $i)
 Returns true if the specified index is valid and has non-zero load. More...
 
 laggedReplicaUsed ()
 Checks whether the database for generic connections this request was both: More...
 
 lastMasterChangeTimestamp ()
 Get the timestamp of the latest write query done by this thread. More...
 
 openConnection ( $i, $domain=false)
 Open a connection to the server given by the specified index Index must be an actual index into the array. More...
 
 pendingMasterChangeCallers ()
 Get the list of callers that have pending master changes. More...
 
 pingAll ()
 
 reuseConnection ( $conn)
 Mark a foreign connection as being available for reuse under a different DB domain. More...
 
 rollbackMasterChanges ( $fname=__METHOD__)
 Issue ROLLBACK only on master, only if queries were done on connection. More...
 
 runMasterPostTrxCallbacks ( $type)
 Issue all pending post-COMMIT/ROLLBACK callbacks. More...
 
 safeGetLag (IDatabase $conn)
 Get the lag in seconds for a given connection, or zero if this load balancer does not have replication enabled. More...
 
 safeWaitForMasterPos (IDatabase $conn, $pos=false, $timeout=10)
 Wait for a replica DB to reach a specified master position. More...
 
 setDomainPrefix ( $prefix)
 Set a new table prefix for the existing local domain ID for testing. More...
 
 setServerInfo ( $i, array $serverInfo)
 Sets the server info structure for the given index. More...
 
 setTableAliases (array $aliases)
 Make certain table names use their own database, schema, and table prefix when passed into SQL queries pre-escaped and without a qualified database name. More...
 
 setTransactionListener ( $name, callable $callback=null)
 Set a callback via IDatabase::setTransactionListener() on all current and future master connections of this load balancer. More...
 
 suppressTransactionEndCallbacks ()
 Suppress all pending post-COMMIT/ROLLBACK callbacks. More...
 
 waitFor ( $pos)
 Set the master wait position. More...
 
 waitForAll ( $pos, $timeout=null)
 Set the master wait position and wait for ALL replica DBs to catch up to it. More...
 
 waitForOne ( $pos, $timeout=null)
 Set the master wait position and wait for a "generic" replica DB to catch up to it. More...
 

Detailed Description

Database cluster connection, tracking, load balancing, and transaction manager interface.

A "cluster" is considered to be one master database and zero or more replica databases. Typically, the replica DBs replicate from the master asynchronously. The first node in the "servers" configuration array is always considered the "master". However, this class can still be used when all or some of the "replica" DBs are multi-master peers of the master or even when all the DBs are non-replicating clones of each other holding read-only data. Thus, the role of "master" is in some cases merely nominal.

By default, each DB server uses DBO_DEFAULT for its 'flags' setting, unless explicitly set otherwise in configuration. DBO_DEFAULT behavior depends on whether 'cliMode' is set:

  • In CLI mode, the flag has no effect with regards to LoadBalancer.
  • In non-CLI mode, the flag causes implicit transactions to be used; the first query on a database starts a transaction on that database. The transactions are meant to remain pending until either commitMasterChanges() or rollbackMasterChanges() is called. The application must have some point where it calls commitMasterChanges() near the end of the PHP request. Every iteration of beginMasterChanges()/commitMasterChanges() is called a "transaction round". Rounds are useful on the master DB connections because they make single-DB (and by and large multi-DB) updates in web requests all-or-nothing. Also, transactions on replica DBs are useful when REPEATABLE-READ or SERIALIZABLE isolation is used because all foriegn keys and constraints hold across separate queries in the DB transaction since the data appears within a consistent point-in-time snapshot.

The typical caller will use LoadBalancer::getConnection( DB_* ) to yield a live database connection handle. The choice of which DB server to use is based on pre-defined loads for weighted random selection, adjustments thereof by LoadMonitor, and the amount of replication lag on each DB server. Lag checks might cause problems in certain setups, so they should be tuned in the server configuration maps as follows:

  • Master + N Replica(s): set 'max lag' to an appropriate threshold for avoiding any database lagged by this much or more. If all DBs are this lagged, then the load balancer considers the cluster to be read-only.
  • Galera Cluster: Seconds_Behind_Master will be 0, so there probably is nothing to tune. Note that lag is still possible depending on how wsrep-sync-wait is set server-side.
  • Read-only archive clones: set 'is static' in the server configuration maps. This will treat all such DBs as having 0 lag.
  • SQL load balancing proxy: any proxy should handle lag checks on its own, so the 'max lag' parameter should probably be set to INF in the server configuration maps. This will make the load balancer ignore whatever it detects as the lag of the logical replica is (which would probably just randomly bounce around).

If using a SQL proxy service, it would probably be best to have two proxy hosts for the load balancer to talk to. One would be the 'host' of the master server entry and another for the (logical) replica server entry. The proxy could map the load balancer's "replica" DB to any number of physical replica DBs.

Since
1.28

Definition at line 79 of file ILoadBalancer.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Rdbms\ILoadBalancer::__construct ( array  $params)

Construct a manager of IDatabase connection objects.

Parameters
array$paramsParameter map with keys:
  • servers : Required. Array of server info structures.
  • localDomain: A DatabaseDomain or domain ID string.
  • loadMonitor : Name of a class used to fetch server lag and load.
  • readOnlyReason : Reason the master DB is read-only if so [optional]
  • waitTimeout : Maximum time to wait for replicas for consistency [optional]
  • srvCache : BagOStuff object for server cache [optional]
  • memCache : BagOStuff object for cluster memory cache [optional]
  • wanCache : WANObjectCache object [optional]
  • chronologyProtector: ChronologyProtector object [optional]
  • hostname : The name of the current server [optional]
  • cliMode: Whether the execution context is a CLI script. [optional]
  • profiler : Class name or instance with profileIn()/profileOut() methods. [optional]
  • trxProfiler: TransactionProfiler instance. [optional]
  • replLogger: PSR-3 logger instance. [optional]
  • connLogger: PSR-3 logger instance. [optional]
  • queryLogger: PSR-3 logger instance. [optional]
  • perfLogger: PSR-3 logger instance. [optional]
  • errorLogger : Callback that takes an Exception and logs it. [optional]
Exceptions
InvalidArgumentException

Implemented in Wikimedia\Rdbms\LoadBalancer, and Wikimedia\Rdbms\LoadBalancerSingle.

Member Function Documentation

◆ allowLagged()

Wikimedia\Rdbms\ILoadBalancer::allowLagged (   $mode = null)

Disables/enables lag checks.

Parameters
null | bool$mode
Returns
bool

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ approveMasterChanges()

Wikimedia\Rdbms\ILoadBalancer::approveMasterChanges ( array  $options)

Perform all pre-commit checks for things like replication safety.

Use this only for mutli-database commits

Parameters
array$optionsIncludes:
  • maxWriteDuration : max write query duration time in seconds
Exceptions
DBTransactionError

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ beginMasterChanges()

Wikimedia\Rdbms\ILoadBalancer::beginMasterChanges (   $fname = __METHOD__)

Flush any master transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set)

The DBO_TRX setting will be reverted to the default in each of these methods:

Parameters
string$fname
Exceptions
DBExpectedError

Implemented in Wikimedia\Rdbms\LoadBalancer.

Referenced by Wikimedia\Rdbms\LBFactory\initLoadBalancer().

◆ closeAll()

Wikimedia\Rdbms\ILoadBalancer::closeAll ( )

Close all open connections.

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ closeConnection()

Wikimedia\Rdbms\ILoadBalancer::closeConnection ( IDatabase  $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.

Parameters
IDatabase$conn

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ commitAll()

Wikimedia\Rdbms\ILoadBalancer::commitAll (   $fname = __METHOD__)

Commit transactions on all open connections.

Parameters
string$fnameCaller name
Exceptions
DBExpectedError

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ commitMasterChanges()

Wikimedia\Rdbms\ILoadBalancer::commitMasterChanges (   $fname = __METHOD__)

Issue COMMIT on all master connections where writes where done.

Parameters
string$fnameCaller name
Exceptions
DBExpectedError

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ disable()

Wikimedia\Rdbms\ILoadBalancer::disable ( )

Disable this load balancer.

All connections are closed, and any attempt to open a new connection will result in a DBAccessError.

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ finalizeMasterChanges()

Wikimedia\Rdbms\ILoadBalancer::finalizeMasterChanges ( )

Perform all pre-commit callbacks that remain part of the atomic transactions and disable any post-commit callbacks until runMasterPostTrxCallbacks()

Use this only for mutli-database commits

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ flushReplicaSnapshots()

Wikimedia\Rdbms\ILoadBalancer::flushReplicaSnapshots (   $fname = __METHOD__)

Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshot.

Parameters
string$fnameCaller name

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ forEachOpenConnection()

Wikimedia\Rdbms\ILoadBalancer::forEachOpenConnection (   $callback,
array  $params = [] 
)

Call a function with each open connection object.

Parameters
callable$callback
array$params

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ forEachOpenMasterConnection()

Wikimedia\Rdbms\ILoadBalancer::forEachOpenMasterConnection (   $callback,
array  $params = [] 
)

Call a function with each open connection object to a master.

Parameters
callable$callback
array$params

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ forEachOpenReplicaConnection()

Wikimedia\Rdbms\ILoadBalancer::forEachOpenReplicaConnection (   $callback,
array  $params = [] 
)

Call a function with each open replica DB connection object.

Parameters
callable$callback
array$params

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ getAnyOpenConnection()

Wikimedia\Rdbms\ILoadBalancer::getAnyOpenConnection (   $i)

Get any open connection to a given server index, local or foreign.

Parameters
int$iServer index or DB_MASTER/DB_REPLICA
Returns
Database|bool False if no such connection is open

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ getConnection()

Wikimedia\Rdbms\ILoadBalancer::getConnection (   $i,
  $groups = [],
  $domain = false 
)

Get a connection by index.

Parameters
int$iServer index or DB_MASTER/DB_REPLICA
array | string | bool$groupsQuery group(s), or false for the generic reader
string | bool$domainDomain ID, or false for the current domain
Exceptions
DBError
Returns
Database

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ getConnectionRef()

Wikimedia\Rdbms\ILoadBalancer::getConnectionRef (   $i,
  $groups = [],
  $domain = false 
)

Get a database connection handle reference.

The handle's methods simply wrap those of a Database handle

See also
ILoadBalancer::getConnection() for parameter information
Parameters
int$iServer index or DB_MASTER/DB_REPLICA
array | string | bool$groupsQuery group(s), or false for the generic reader
string | bool$domainDomain ID, or false for the current domain
Returns
DBConnRef

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ getLaggedReplicaMode()

Wikimedia\Rdbms\ILoadBalancer::getLaggedReplicaMode (   $domain = false)
Note
This method will trigger a DB connection if not yet done
Parameters
string | bool$domainDomain ID, or false for the current domain
Returns
bool Whether the database for generic connections this request is highly "lagged"

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ getLagTimes()

Wikimedia\Rdbms\ILoadBalancer::getLagTimes (   $domain = false)

Get an estimate of replication lag (in seconds) for each server.

Results are cached for a short time in memcached/process cache

Values may be "false" if replication is too broken to estimate

Parameters
string | bool$domain
Returns
int[] Map of (server index => float|int|bool)

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ getLazyConnectionRef()

Wikimedia\Rdbms\ILoadBalancer::getLazyConnectionRef (   $i,
  $groups = [],
  $domain = false 
)

Get a database connection handle reference without connecting yet.

The handle's methods simply wrap those of a Database handle

See also
ILoadBalancer::getConnection() for parameter information
Parameters
int$iServer index or DB_MASTER/DB_REPLICA
array | string | bool$groupsQuery group(s), or false for the generic reader
string | bool$domainDomain ID, or false for the current domain
Returns
DBConnRef

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ getMaintenanceConnectionRef()

Wikimedia\Rdbms\ILoadBalancer::getMaintenanceConnectionRef (   $db,
  $groups = [],
  $domain = false 
)

Get a maintenance database connection handle reference for migrations and schema changes.

The handle's methods simply wrap those of a Database handle

See also
ILoadBalancer::getConnection() for parameter information
Parameters
int$dbServer index or DB_MASTER/DB_REPLICA
array | string | bool$groupsQuery group(s), or false for the generic reader
string | bool$domainDomain ID, or false for the current domain
Returns
MaintainableDBConnRef

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ getMasterPos()

Wikimedia\Rdbms\ILoadBalancer::getMasterPos ( )

Get the current master position for chronology control purposes.

Returns
DBMasterPos|bool Returns false if not applicable

Implemented in Wikimedia\Rdbms\LoadBalancer.

Referenced by Wikimedia\Rdbms\ChronologyProtector\shutdownLB().

◆ getMaxLag()

Wikimedia\Rdbms\ILoadBalancer::getMaxLag (   $domain = false)

Get the hostname and lag time of the most-lagged replica DB.

This is useful for maintenance scripts that need to throttle their updates. May attempt to open connections to replica DBs on the default DB. If there is no lag, the maximum lag will be reported as -1.

Parameters
bool | string$domainDomain ID, or false for the default database
Returns
array ( host, max lag, index of max lagged host )

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ getReaderIndex()

Wikimedia\Rdbms\ILoadBalancer::getReaderIndex (   $group = false,
  $domain = false 
)

Get the index of the reader connection, which may be a replica DB.

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

Parameters
string | bool$groupQuery group, or false for the generic reader
string | bool$domainDomain ID, or false for the current domain
Exceptions
DBError
Returns
bool|int|string

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ getReadOnlyReason()

Wikimedia\Rdbms\ILoadBalancer::getReadOnlyReason (   $domain = false,
IDatabase  $conn = null 
)
Note
This method may trigger a DB connection if not yet done
Parameters
string | bool$domainDomain ID, or false for the current domain
IDatabase | null$connDB master connection; used to avoid loops [optional]
Returns
string|bool Reason the master is read-only or false if it is not

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ getServerCount()

Wikimedia\Rdbms\ILoadBalancer::getServerCount ( )

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

Returns
int

Implemented in Wikimedia\Rdbms\LoadBalancer.

Referenced by Wikimedia\Rdbms\LBFactory\appendPreShutdownTimeAsQuery(), Wikimedia\Rdbms\ChronologyProtector\initLB(), and Wikimedia\Rdbms\ChronologyProtector\shutdownLB().

◆ getServerInfo()

Wikimedia\Rdbms\ILoadBalancer::getServerInfo (   $i)

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

Parameters
int$i
Returns
array|bool

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ getServerName()

Wikimedia\Rdbms\ILoadBalancer::getServerName (   $i)

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

Parameters
string$i
Returns
string

Implemented in Wikimedia\Rdbms\LoadBalancer.

Referenced by Wikimedia\Rdbms\ChronologyProtector\initLB(), Wikimedia\Rdbms\LBFactory\logIfMultiDbTransaction(), Wikimedia\Rdbms\LBFactory\shutdownChronologyProtector(), and Wikimedia\Rdbms\ChronologyProtector\shutdownLB().

◆ getWriterIndex()

◆ hasMasterChanges()

Wikimedia\Rdbms\ILoadBalancer::hasMasterChanges ( )

Determine if there are pending changes in a transaction by this thread.

Returns
bool

Implemented in Wikimedia\Rdbms\LoadBalancer.

Referenced by Wikimedia\Rdbms\LBFactory\hasMasterChanges().

◆ hasMasterConnection()

Wikimedia\Rdbms\ILoadBalancer::hasMasterConnection ( )
Returns
bool Whether a master connection is already open

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ hasOrMadeRecentMasterChanges()

Wikimedia\Rdbms\ILoadBalancer::hasOrMadeRecentMasterChanges (   $age = null)

Check if this load balancer object had any recent or still pending writes issued against it by this PHP thread.

Parameters
float$ageHow many seconds ago is "recent" [defaults to mWaitTimeout]
Returns
bool

Implemented in Wikimedia\Rdbms\LoadBalancer.

Referenced by Wikimedia\Rdbms\LBFactory\hasOrMadeRecentMasterChanges(), and Wikimedia\Rdbms\ChronologyProtector\shutdownLB().

◆ haveIndex()

Wikimedia\Rdbms\ILoadBalancer::haveIndex (   $i)

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

Parameters
string$i
Returns
bool

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ isNonZeroLoad()

Wikimedia\Rdbms\ILoadBalancer::isNonZeroLoad (   $i)

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

Parameters
string$i
Returns
bool

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ laggedReplicaUsed()

Wikimedia\Rdbms\ILoadBalancer::laggedReplicaUsed ( )

Checks whether the database for generic connections this request was both:

  • a) Already choosen due to a prior connection attempt
  • b) Considered highly "lagged"
Note
This method will never cause a new DB connection
Returns
bool

Implemented in Wikimedia\Rdbms\LoadBalancer.

Referenced by Wikimedia\Rdbms\LBFactory\laggedReplicaUsed().

◆ lastMasterChangeTimestamp()

Wikimedia\Rdbms\ILoadBalancer::lastMasterChangeTimestamp ( )

Get the timestamp of the latest write query done by this thread.

Returns
float|bool UNIX timestamp or false

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ openConnection()

Wikimedia\Rdbms\ILoadBalancer::openConnection (   $i,
  $domain = 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.

Note
If disable() was called on this LoadBalancer, this method will throw a DBAccessError.
Parameters
int$iServer index or DB_MASTER/DB_REPLICA
string | bool$domainDomain ID, or false for the current domain
Returns
Database|bool Returns false on errors
Exceptions
DBAccessError

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ pendingMasterChangeCallers()

Wikimedia\Rdbms\ILoadBalancer::pendingMasterChangeCallers ( )

Get the list of callers that have pending master changes.

Returns
string[] List of method names

Implemented in Wikimedia\Rdbms\LoadBalancer.

Referenced by Wikimedia\Rdbms\LBFactory\logIfMultiDbTransaction().

◆ pingAll()

Wikimedia\Rdbms\ILoadBalancer::pingAll ( )
Returns
bool

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ reuseConnection()

Wikimedia\Rdbms\ILoadBalancer::reuseConnection (   $conn)

Mark a foreign connection as being available for reuse under a different DB domain.

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

Parameters
IDatabase$conn
Exceptions
InvalidArgumentException

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ rollbackMasterChanges()

Wikimedia\Rdbms\ILoadBalancer::rollbackMasterChanges (   $fname = __METHOD__)

Issue ROLLBACK only on master, only if queries were done on connection.

Parameters
string$fnameCaller name
Exceptions
DBExpectedError

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ runMasterPostTrxCallbacks()

Wikimedia\Rdbms\ILoadBalancer::runMasterPostTrxCallbacks (   $type)

Issue all pending post-COMMIT/ROLLBACK callbacks.

Use this only for mutli-database commits

Parameters
int$typeIDatabase::TRIGGER_* constant
Returns
Exception|null The first exception or null if there were none

Implemented in Wikimedia\Rdbms\LoadBalancer.

Referenced by Wikimedia\Rdbms\LBFactory\commitMasterChanges(), and Wikimedia\Rdbms\LBFactory\rollbackMasterChanges().

◆ safeGetLag()

Wikimedia\Rdbms\ILoadBalancer::safeGetLag ( IDatabase  $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.

Parameters
IDatabase$conn
Returns
int|bool Returns false on error

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ safeWaitForMasterPos()

Wikimedia\Rdbms\ILoadBalancer::safeWaitForMasterPos ( IDatabase  $conn,
  $pos = false,
  $timeout = 10 
)

Wait for a replica DB to reach a specified master position.

This will connect to the master to get an accurate position if $pos is not given

Parameters
IDatabase$connReplica DB
DBMasterPos | bool$posMaster position; default: current position
int$timeoutTimeout in seconds [optional]
Returns
bool Success

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ setDomainPrefix()

Wikimedia\Rdbms\ILoadBalancer::setDomainPrefix (   $prefix)

Set a new table prefix for the existing local domain ID for testing.

Parameters
string$prefix

Implemented in Wikimedia\Rdbms\LoadBalancer.

Referenced by Wikimedia\Rdbms\LBFactory\setDomainPrefix().

◆ setServerInfo()

Wikimedia\Rdbms\ILoadBalancer::setServerInfo (   $i,
array  $serverInfo 
)

Sets the server info structure for the given index.

Entry at index $i is created if it doesn't exist

Parameters
int$i
array$serverInfo

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ setTableAliases()

Wikimedia\Rdbms\ILoadBalancer::setTableAliases ( array  $aliases)

Make certain table names use their own database, schema, and table prefix when passed into SQL queries pre-escaped and without a qualified database name.

For example, "user" can be converted to "myschema.mydbname.user" for convenience. Appearances like user, somedb.user, somedb.someschema.user will used literally.

Calling this twice will completely clear any old table aliases. Also, note that callers are responsible for making sure the schemas and databases actually exist.

Parameters
array[]$aliasesMap of (table => (dbname, schema, prefix) map)

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ setTransactionListener()

Wikimedia\Rdbms\ILoadBalancer::setTransactionListener (   $name,
callable  $callback = null 
)

Set a callback via IDatabase::setTransactionListener() on all current and future master connections of this load balancer.

Parameters
string$nameCallback name
callable | null$callback

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ suppressTransactionEndCallbacks()

Wikimedia\Rdbms\ILoadBalancer::suppressTransactionEndCallbacks ( )

Suppress all pending post-COMMIT/ROLLBACK callbacks.

Use this only for mutli-database commits

Returns
Exception|null The first exception or null if there were none

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ waitFor()

Wikimedia\Rdbms\ILoadBalancer::waitFor (   $pos)

Set the master wait position.

If a DB_REPLICA connection has been opened already, then wait immediately. Otherwise sets a variable telling it to wait if such a connection is opened.

This only applies to connections to the generic replica DB for this request. If a timeout happens when waiting, then getLaggedReplicaMode()/laggedReplicaUsed() will return true.

Parameters
DBMasterPos | bool$posMaster position or false

Implemented in Wikimedia\Rdbms\LoadBalancer.

Referenced by Wikimedia\Rdbms\ChronologyProtector\initLB().

◆ waitForAll()

Wikimedia\Rdbms\ILoadBalancer::waitForAll (   $pos,
  $timeout = null 
)

Set the master wait position and wait for ALL replica DBs to catch up to it.

Parameters
DBMasterPos | bool$posMaster position or false
int$timeoutMax seconds to wait; default is mWaitTimeout
Returns
bool Success (able to connect and no timeouts reached)

Implemented in Wikimedia\Rdbms\LoadBalancer.

Referenced by Wikimedia\Rdbms\LBFactory\shutdownChronologyProtector().

◆ waitForOne()

Wikimedia\Rdbms\ILoadBalancer::waitForOne (   $pos,
  $timeout = null 
)

Set the master wait position and wait for a "generic" replica DB to catch up to it.

This can be used a faster proxy for waitForAll()

Parameters
DBMasterPos | bool$posMaster position or false
int$timeoutMax seconds to wait; default is mWaitTimeout
Returns
bool Success (able to connect and no timeouts reached)

Implemented in Wikimedia\Rdbms\LoadBalancer.


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