BlueSpice MediaWiki master
 All Classes Namespaces Files Functions Variables Groups Pages
Wikimedia\Rdbms\LoadBalancer Class Reference
Inheritance diagram for Wikimedia\Rdbms\LoadBalancer:
Collaboration diagram for Wikimedia\Rdbms\LoadBalancer:

Public Member Functions

 __construct (array $params)
 
 getLocalDomainID ()
 
 getReaderIndex ($group=false, $domain=false)
 
 waitFor ($pos)
 
 waitForOne ($pos, $timeout=null)
 
 waitForAll ($pos, $timeout=null)
 
 getAnyOpenConnection ($i, $flags=0)
 
 getConnection ($i, $groups=[], $domain=false, $flags=0)
 
 reuseConnection (IDatabase $conn)
 
 getConnectionRef ($db, $groups=[], $domain=false, $flags=0)
 
 getLazyConnectionRef ($db, $groups=[], $domain=false, $flags=0)
 
 getMaintenanceConnectionRef ($db, $groups=[], $domain=false, $flags=0)
 
 openConnection ($i, $domain=false, $flags=0)
 
 getServerAttributes ($i)
 
 getWriterIndex ()
 
 haveIndex ($i)
 
 isNonZeroLoad ($i)
 
 getServerCount ()
 
 getServerName ($i)
 
 getServerType ($i)
 
 getMasterPos ()
 
 disable ()
 
 closeAll ()
 
 closeConnection (IDatabase $conn)
 
 commitAll ($fname=__METHOD__)
 
 finalizeMasterChanges ()
 
 approveMasterChanges (array $options)
 
 beginMasterChanges ($fname=__METHOD__)
 
 commitMasterChanges ($fname=__METHOD__)
 
 runMasterTransactionIdleCallbacks ()
 
 runMasterTransactionListenerCallbacks ()
 
 rollbackMasterChanges ($fname=__METHOD__)
 
 flushReplicaSnapshots ($fname=__METHOD__)
 
 getTransactionRoundStage ()
 
 hasMasterConnection ()
 
 hasMasterChanges ()
 
 lastMasterChangeTimestamp ()
 
 hasOrMadeRecentMasterChanges ($age=null)
 
 pendingMasterChangeCallers ()
 
 getLaggedReplicaMode ($domain=false)
 
 laggedReplicaUsed ()
 
 laggedSlaveUsed ()
 
 getReadOnlyReason ($domain=false, IDatabase $conn=null)
 
 allowLagged ($mode=null)
 
 pingAll ()
 
 forEachOpenConnection ($callback, array $params=[])
 
 forEachOpenReplicaConnection ($callback, array $params=[])
 
 getMaxLag ($domain=false)
 
 getLagTimes ($domain=false)
 
 safeGetLag (IDatabase $conn)
 
 safeWaitForMasterPos (IDatabase $conn, $pos=false, $timeout=null)
 
 setTransactionListener ($name, callable $callback=null)
 
 setTableAliases (array $aliases)
 
 setIndexAliases (array $aliases)
 
 setDomainPrefix ($prefix)
 
- Public Member Functions inherited from Wikimedia\Rdbms\ILoadBalancer
 forEachOpenMasterConnection ($callback, array $params=[])
 

Public Attributes

const CONN_HELD_WARN_THRESHOLD = 10
 
const MAX_LAG_DEFAULT = 10
 
const MAX_WAIT_DEFAULT = 10
 
const TTL_CACHE_READONLY = 5
 
const KEY_LOCAL = 'local'
 
const KEY_FOREIGN_FREE = 'foreignFree'
 
const KEY_FOREIGN_INUSE = 'foreignInUse'
 
const KEY_LOCAL_NOROUND = 'localAutoCommit'
 
const KEY_FOREIGN_FREE_NOROUND = 'foreignFreeAutoCommit'
 
const KEY_FOREIGN_INUSE_NOROUND = 'foreignInUseAutoCommit'
 
const ROUND_CURSORY = 'cursory'
 
const ROUND_FINALIZED = 'finalized'
 
const ROUND_APPROVED = 'approved'
 
const ROUND_COMMIT_CALLBACKS = 'commit-callbacks'
 
const ROUND_ROLLBACK_CALLBACKS = 'rollback-callbacks'
 
const ROUND_ERROR = 'error'
 
- Public Attributes inherited from Wikimedia\Rdbms\ILoadBalancer
const DB_REPLICA = -1
 
const DB_MASTER = -2
 
const DOMAIN_ANY = ''
 
const CONN_TRX_AUTOCOMMIT = 1
 
const CONN_TRX_AUTO = 1
 

Protected Member Functions

 reallyOpenConnection (array $server, DatabaseDomain $domainOverride)
 
 getScopedPHPBehaviorForCommit ()
 

Protected Attributes

 $profiler
 
 $trxProfiler
 
 $replLogger
 
 $connLogger
 
 $queryLogger
 
 $perfLogger
 
 $cliMode
 
 $agent
 

Detailed Description

Database connection, tracking, load balancing, and transaction manager for a cluster

Constructor & Destructor Documentation

Wikimedia\Rdbms\LoadBalancer::__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]
  • maxLag: Avoid replica DB servers with more lag than this [optional]
  • srvCache : BagOStuff object for server cache [optional]
  • wanCache : WANObjectCache object [optional]
  • chronologyCallback: Callback to run before the first connection attempt [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]
  • deprecationLogger: Callback to log a deprecation warning. [optional]
Exceptions
InvalidArgumentException

Implements Wikimedia\Rdbms\ILoadBalancer.

Member Function Documentation

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

Disables/enables lag checks

Parameters
null | bool$mode
Returns
bool

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::closeAll ( )

Close all open connections

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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

Implements Wikimedia\Rdbms\ILoadBalancer.

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

Commit transactions on all open connections

Parameters
string$fnameCaller name
Exceptions
DBExpectedError

Implements Wikimedia\Rdbms\ILoadBalancer.

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

Issue COMMIT on all master connections where writes where done

Parameters
string$fnameCaller name
Exceptions
DBExpectedError

PhpUnusedLocalVariableInspection

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::disable ( )

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

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::finalizeMasterChanges ( )

Run pre-commit callbacks and defer execution of post-commit callbacks

Use this only for mutli-database commits

Implements Wikimedia\Rdbms\ILoadBalancer.

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

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

Parameters
string$fnameCaller name

Implements Wikimedia\Rdbms\ILoadBalancer.

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

Call a function with each open connection object

Parameters
callable$callback
array$params

Implements Wikimedia\Rdbms\ILoadBalancer.

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

Call a function with each open replica DB connection object

Parameters
callable$callback
array$params

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::getAnyOpenConnection (   $i,
  $flags = 0 
)

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

Use CONN_TRX_AUTOCOMMIT to only look for connections opened with that flag

Parameters
int$iServer index or DB_MASTER/DB_REPLICA
int$flagsBitfield of CONN_* class constants
Returns
Database|bool False if no such connection is open

Implements Wikimedia\Rdbms\ILoadBalancer.

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

Get a connection handle by server index

The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. ILoadBalancer::getServerAttributes() can be used to check such flags beforehand.

If the caller uses $domain or sets CONN_TRX_AUTOCOMMIT in $flags, then it must also call ILoadBalancer::reuseConnection() on the handle when finished using it. In all other cases, this is not necessary, though not harmful either.

Parameters
int$iServer index (overrides $groups) 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
int$flagsBitfield of CONN_* class constants
Note
This method throws DBAccessError if ILoadBalancer::disable() was called
Exceptions
DBError
Returns
Database

Implements Wikimedia\Rdbms\ILoadBalancer.

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

Get a database connection handle reference

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

The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. ILoadBalancer::getServerAttributes() can be used to check such flags beforehand.

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
int$flagsBitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT)
Returns
DBConnRef

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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"

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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)

Implements Wikimedia\Rdbms\ILoadBalancer.

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

Get a database connection handle reference without connecting yet

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

The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. ILoadBalancer::getServerAttributes() can be used to check such flags beforehand.

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
int$flagsBitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT)
Returns
DBConnRef

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::getLocalDomainID ( )

Get the local (and default) database domain ID of connection handles

See Also
DatabaseDomain
Returns
string Database domain ID; this specifies DB name, schema, and table prefix
Since
1.31
Wikimedia\Rdbms\LoadBalancer::getMaintenanceConnectionRef (   $db,
  $groups = [],
  $domain = false,
  $flags = 0 
)

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

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

The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. ILoadBalancer::getServerAttributes() can be used to check such flags beforehand.

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
int$flagsBitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT)
Returns
MaintainableDBConnRef

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::getMasterPos ( )

Get the current master position for chronology control purposes

Returns
DBMasterPos|bool Returns false if not applicable

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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 )

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::getScopedPHPBehaviorForCommit ( )
finalprotected

Make PHP ignore user aborts/disconnects until the returned value leaves scope. This returns null and does nothing in CLI mode.

Returns
ScopedCallback|null
Wikimedia\Rdbms\LoadBalancer::getServerAttributes (   $i)
Parameters
int$iServer index
Returns
array (Database::ATTRIBUTE_* constant => value) for all such constants
Since
1.31

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::getServerCount ( )

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

Returns
int

Implements Wikimedia\Rdbms\ILoadBalancer.

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

Get the host name or IP address of the server with the specified index

Parameters
int$i
Returns
string Readable name if available or IP/host otherwise

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::getServerType (   $i)

Get DB type of the server with the specified index

Parameters
int$i
Returns
string One of (mysql,postgres,sqlite,...) or "unknown" for bad indexes
Since
1.30

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::getTransactionRoundStage ( )
Returns
string
Since
1.32
Wikimedia\Rdbms\LoadBalancer::getWriterIndex ( )
Returns
int

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::hasMasterChanges ( )

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

Returns
bool

Implements Wikimedia\Rdbms\ILoadBalancer.

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

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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

Implements Wikimedia\Rdbms\ILoadBalancer.

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

Returns true if the specified index is a valid server index

Parameters
int$i
Returns
bool

Implements Wikimedia\Rdbms\ILoadBalancer.

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

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

Parameters
int$i
Returns
bool

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::laggedSlaveUsed ( )
Returns
bool
Since
1.27
Deprecated:
Since 1.28; use laggedReplicaUsed()
Wikimedia\Rdbms\LoadBalancer::lastMasterChangeTimestamp ( )

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

Returns
float|bool UNIX timestamp or false

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::openConnection (   $i,
  $domain = false,
  $flags = 0 
)

Open a connection to the server given by the specified index

The index must be an actual index into the array. If a connection to the server is already open and not considered an "in use" foreign connection, this simply returns it.

Avoid using CONN_TRX_AUTOCOMMIT for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. ILoadBalancer::getServerAttributes() can be used to check such flags beforehand.

If the caller uses $domain or sets CONN_TRX_AUTOCOMMIT in $flags, then it must also call ILoadBalancer::reuseConnection() on the handle when finished using it. In all other cases, this is not necessary, though not harmful either.

Note
This method throws DBAccessError if ILoadBalancer::disable() was called
Parameters
int$iServer index (does not support DB_MASTER/DB_REPLICA)
string | bool$domainDomain ID, or false for the current domain
int$flagsBitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT)
Returns
Database|bool Returns false on errors
Exceptions
DBAccessError

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::pendingMasterChangeCallers ( )

Get the list of callers that have pending master changes

Returns
string[] List of method names

Implements Wikimedia\Rdbms\ILoadBalancer.

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

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::reallyOpenConnection ( array  $server,
DatabaseDomain  $domainOverride 
)
protected

Open a new network connection to a server (uncached)

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

Parameters
array$server
DatabaseDomain$domainOverrideUse an unspecified domain to not select any database
Returns
Database
Exceptions
DBAccessError
InvalidArgumentException
Wikimedia\Rdbms\LoadBalancer::reuseConnection ( IDatabase  $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

This can happen in code like: foreach ( $dbs as $db ) { $conn = $lb->getConnection(

lb:
DB_REPLICA, [],

db ); ... $lb->reuseConnection( $conn ); } When a connection to the local DB is opened in this way, reuseConnection() should be ignored

Implements Wikimedia\Rdbms\ILoadBalancer.

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

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

Parameters
string$fnameCaller name
Exceptions
DBExpectedError

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::runMasterTransactionIdleCallbacks ( )

Consume and run all pending post-COMMIT/ROLLBACK callbacks

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

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::runMasterTransactionListenerCallbacks ( )

Run all recurring post-COMMIT/ROLLBACK listener callbacks

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

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::safeWaitForMasterPos ( IDatabase  $conn,
  $pos = false,
  $timeout = null 
)
Parameters
IDatabase$conn
DBMasterPos | bool$pos
int | null$timeout
Returns
bool

Implements Wikimedia\Rdbms\ILoadBalancer.

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

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

Parameters
string$prefix

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::setIndexAliases ( array  $aliases)

Convert certain index names to alternative names before querying the DB

Note that this applies to indexes regardless of the table they belong to.

This can be employed when an index was renamed X => Y in code, but the new Y-named indexes were not yet built on all DBs. After all the Y-named ones are added by the DBA, the aliases can be removed, and then the old X-named indexes dropped.

Parameters
string[]$aliases
Returns
mixed
Since
1.31

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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[]$aliases Map of (table => (dbname, schema, prefix) map)

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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)

Implements Wikimedia\Rdbms\ILoadBalancer.

Wikimedia\Rdbms\LoadBalancer::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)

Implements Wikimedia\Rdbms\ILoadBalancer.


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