MediaWiki REL1_37
Wikimedia\Rdbms\LoadBalancer Class Reference

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

Inheritance diagram for Wikimedia\Rdbms\LoadBalancer:
Collaboration diagram for Wikimedia\Rdbms\LoadBalancer:

Public Member Functions

 __construct (array $params)
 Construct a manager of IDatabase connection objects.
 
 __destruct ()
 
 allowLagged ( $mode=null)
 Disables/enables lag checks.
 
 approveMasterChanges (array $options, $fname=__METHOD__, $owner=null)
 
 approvePrimaryChanges (array $options, $fname=__METHOD__, $owner=null)
 Perform all pre-commit checks for things like replication safety.
 
 beginMasterChanges ( $fname=__METHOD__, $owner=null)
 
 beginPrimaryChanges ( $fname=__METHOD__, $owner=null)
 Flush any primary transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set)
 
 closeAll ( $fname=__METHOD__, $owner=null)
 Close all open connections.
 
 closeConnection (IDatabase $conn)
 Close a connection.
 
 commitAll ( $fname=__METHOD__, $owner=null)
 Commit transactions on all open connections.
 
 commitMasterChanges ( $fname=__METHOD__, $owner=null)
 
 commitPrimaryChanges ( $fname=__METHOD__, $owner=null)
 Issue COMMIT on all open primary connections to flush changes and view snapshots.
 
 disable ( $fname=__METHOD__, $owner=null)
 Close all connections and disable this load balancer.
 
 finalizeMasterChanges ( $fname=__METHOD__, $owner=null)
 
 finalizePrimaryChanges ( $fname=__METHOD__, $owner=null)
 Run pre-commit callbacks and defer execution of post-commit callbacks.
 
 flushMasterSnapshots ( $fname=__METHOD__, $owner=null)
 
 flushPrimarySnapshots ( $fname=__METHOD__, $owner=null)
 Commit all primary DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
 
 flushReplicaSnapshots ( $fname=__METHOD__, $owner=null)
 Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
 
 forEachOpenConnection ( $callback, array $params=[])
 Call a function with each open connection object.
 
 forEachOpenMasterConnection ( $callback, array $params=[])
 
 forEachOpenPrimaryConnection ( $callback, array $params=[])
 Call a function with each open connection object to a primary.
 
 forEachOpenReplicaConnection ( $callback, array $params=[])
 Call a function with each open replica DB connection object.
 
 getAnyOpenConnection ( $i, $flags=0)
 Get an existing live handle to the given server index (on any domain)
 
 getClusterName ()
 Get the logical name of the database cluster.
 
 getConnection ( $i, $groups=[], $domain=false, $flags=0)
 Get a live handle for a specific or virtual (DB_PRIMARY/DB_REPLICA) server index.
 
 getConnectionRef ( $i, $groups=[], $domain=false, $flags=0)
 Get a live database handle reference for a server index.
 
 getLaggedReplicaMode ( $domain=false)
 
 getLagTimes ( $domain=false)
 Get an estimate of replication lag (in seconds) for each server.
 
 getLazyConnectionRef ( $i, $groups=[], $domain=false, $flags=0)
 Get a lazy-connecting database handle reference for a server index.
 
 getLocalDomainID ()
 Get the local (and default) database domain ID of connection handles.
 
 getMaintenanceConnectionRef ( $i, $groups=[], $domain=false, $flags=0)
 Get a live database handle, suitable for migrations and schema changes, for a server index.
 
 getMasterPos ()
 
 getMaxLag ( $domain=false)
 Get the name and lag time of the most-lagged replica server.
 
 getPrimaryPos ()
 Get the current primary replication position.
 
 getReaderIndex ( $group=false, $domain=false)
 Get the specific server index of the reader connection for a given group.
 
 getReadOnlyReason ( $domain=false)
 
 getReplicaResumePos ()
 Get the highest DB replication position for chronology control purposes.
 
 getServerAttributes ( $i)
 Get basic attributes of the server with the specified index without connecting.
 
 getServerConnection ( $i, $domain, $flags=0)
 Get a live handle for a specific server index.
 
 getServerCount ()
 Get the number of servers defined in configuration.
 
 getServerInfo ( $i)
 Return the server configuration map for the server with the specified index.
 
 getServerName ( $i)
 Get the readable name of the server with the specified index.
 
 getServerType ( $i)
 Get the RDBMS type of the server with the specified index (e.g.
 
 getTransactionRoundStage ()
 
 getWriterIndex ()
 Get the specific server index of the primary server.
 
 hasMasterChanges ()
 
 hasMasterConnection ()
 
 hasOrMadeRecentMasterChanges ( $age=null)
 
 hasOrMadeRecentPrimaryChanges ( $age=null)
 Check if this load balancer object had any recent or still pending writes issued against it by this PHP thread.
 
 hasPrimaryChanges ()
 Whether there are pending changes or callbacks in a transaction by this thread.
 
 hasPrimaryConnection ()
 
 hasReplicaServers ()
 Whether there are any replica servers configured.
 
 hasStreamingReplicaServers ()
 Whether any replica servers use streaming replication from the primary server.
 
 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.
 
 laggedReplicaUsed ()
 Checks whether the database for generic connections this request was both:
 
 lastMasterChangeTimestamp ()
 
 lastPrimaryChangeTimestamp ()
 Get the timestamp of the latest write query done by this thread.
 
 openConnection ( $i, $domain=false, $flags=0)
 
 pendingMasterChangeCallers ()
 
 pendingPrimaryChangeCallers ()
 Get the list of callers that have pending primary changes.
 
 pingAll ()
 
 redefineLocalDomain ( $domain)
 Close all connection and redefine the local domain for testing or schema creation.
 
 resolveDomainID ( $domain)
 
 reuseConnection (IDatabase $conn)
 Mark a live handle as being available for reuse under a different database domain.
 
 rollbackMasterChanges ( $fname=__METHOD__, $owner=null)
 
 rollbackPrimaryChanges ( $fname=__METHOD__, $owner=null)
 Issue ROLLBACK only on primary, only if queries were done on connection.
 
 runMasterTransactionIdleCallbacks ( $fname=__METHOD__, $owner=null)
 
 runMasterTransactionListenerCallbacks ( $fname=__METHOD__, $owner=null)
 
 runPrimaryTransactionIdleCallbacks ( $fname=__METHOD__, $owner=null)
 Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions.
 
 runPrimaryTransactionListenerCallbacks ( $fname=__METHOD__, $owner=null)
 Run all recurring post-COMMIT/ROLLBACK listener callbacks.
 
 safeGetLag (IDatabase $conn)
 Get the lag in seconds for a given connection, or zero if this load balancer does not have replication enabled.
 
 setDomainAliases (array $aliases)
 Convert certain database domains to alternative ones.
 
 setIndexAliases (array $aliases)
 Convert certain index names to alternative names before querying the DB.
 
 setLocalDomainPrefix ( $prefix)
 Set a new table prefix for the existing local domain ID for testing.
 
 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.
 
 setTempTablesOnlyMode ( $value, $domain)
 Indicate whether the tables on this domain are only temporary tables for testing.
 
 setTransactionListener ( $name, callable $callback=null)
 Set a callback via IDatabase::setTransactionListener() on all current and future primary connections of this load balancer.
 
 waitFor ( $pos)
 Set the primary position to reach before the next generic group DB handle query.
 
 waitForAll ( $pos, $timeout=null)
 Set the primary wait position and wait for ALL replica DBs to catch up to it.
 
 waitForMasterPos (IDatabase $conn, $pos=false, $timeout=null)
 
 waitForOne ( $pos, $timeout=null)
 Set the primary wait position and wait for a generic replica DB to catch up to it.
 
 waitForPrimaryPos (IDatabase $conn, $pos=false, $timeout=null)
 Wait for a replica DB to reach a specified primary position.
 

Public Attributes

const MAX_LAG_DEFAULT = 6
 Default 'maxLag' when unspecified.
 
- Public Attributes inherited from Wikimedia\Rdbms\ILoadBalancer
const CONN_INTENT_WRITABLE = 4
 Caller is requesting the primary DB server for possibly writes.
 
const CONN_REFRESH_READ_ONLY = 8
 Bypass and update any server-side read-only mode state cache.
 
const CONN_SILENCE_ERRORS = 2
 Return null on connection failure instead of throwing an exception.
 
const CONN_TRX_AUTOCOMMIT = 1
 DB handle should have DBO_TRX disabled and the caller will leave it as such.
 
const DB_MASTER = self::DB_PRIMARY
 Request a primary, write-enabled DB connection.
 
const DB_PRIMARY = -2
 Request a primary, write-enabled DB connection.
 
const DB_REPLICA = -1
 Request a replica DB connection.
 
const DOMAIN_ANY = ''
 Domain specifier when no specific database needs to be selected.
 
const GROUP_GENERIC = ''
 The generic query group.
 
const STAGE_POSTCOMMIT_CALLBACKS = 'stage-postcommit-callbacks'
 Manager of ILoadBalancer instances is running post-commit callbacks.
 
const STAGE_POSTROLLBACK_CALLBACKS = 'stage-postrollback-callbacks'
 Manager of ILoadBalancer instances is running post-rollback callbacks.
 

Protected Member Functions

 getConnLogContext (IDatabase $conn, array $extras=[])
 Create a log context to pass to PSR-3 logger functions.
 
 getExistingReaderIndex ( $group)
 Get the server index chosen by the load balancer for use with the given query group.
 
 reallyOpenConnection ( $i, DatabaseDomain $domain, array $lbInfo)
 Open a new network connection to a server (uncached)
 
 resolveDomainInstance ( $domain)
 

Private Member Functions

 applyTransactionRoundFlags (Database $conn)
 Make all DB servers with DBO_DEFAULT/DBO_TRX set join the transaction round.
 
 assertOwnership ( $fname, $owner)
 Assure that if this instance is owned, the caller is either the owner or is internal.
 
 assertTransactionRoundStage ( $stage)
 
 doWait ( $index, $timeout=null)
 Wait for a given replica DB to catch up to the primary DB pos stored in "waitForPos".
 
 enforceConnectionFlags (IDatabase $conn, $flags)
 
 fieldHasBit (int $flags, int $bit)
 
 getConnectionIndex ( $i, array $groups, $domain)
 Get the server index to use for a specified server index and query group list.
 
 getCurrentConnectionCount ()
 
 getForeignConnection ( $i, $domain, $flags=0)
 Open a connection to a foreign DB, or return one if it is already open.
 
 getLoadMonitor ()
 Get a LoadMonitor instance.
 
 getLocalConnection ( $i, $flags=0)
 Open a connection to a local DB, or return one if it is already open.
 
 getPrimaryServerName ()
 
 getRandomNonLagged (array $loads, string $domain, $maxLag=INF)
 
 getRoleFromIndex ( $i)
 
 getServerInfoStrict ( $i, $field=null)
 
 getStreamingReplicaIndexes ()
 
 getTopologyRole ( $i, array $server)
 
 initConnFlags ( $flags)
 
 isOpen ( $index)
 Test if the specified index represents an open connection.
 
 isPrimaryConnectionReadOnly (IDatabase $conn, $flags=0)
 
 isPrimaryRunningReadOnly (DatabaseDomain $domain)
 
 lazyLoadReplicationPositions ()
 Make sure that any "waitForPos" positions are loaded and available to doWait()
 
 pickAnyOpenConnection (array $connsByServer, $autoCommitOnly)
 
 pickReaderIndex (array $loads, string $domain)
 Pick a server that is reachable, preferably non-lagged, and return its server index.
 
 reportConnectionError ()
 
 resolveGroups ( $groups, $i)
 Resolve $groups into a list of query groups defining as having database servers.
 
 sanitizeConnectionFlags ( $flags, $i, $domain)
 
 serverHasLoadInAnyGroup ( $i)
 
 setExistingReaderIndex ( $group, $index)
 Set the server index chosen by the load balancer for use with the given query group.
 
 setLocalDomain (DatabaseDomain $domain)
 
 setWaitForPositionIfHigher ( $pos)
 
 undoTransactionRoundFlags (Database $conn)
 

Static Private Member Functions

static newTrackedConnectionsArray ()
 

Private Attributes

string $agent
 Agent name for query profiling.
 
bool $allowLagged = false
 Whether to disregard replica DB lag as a factor in replica DB selection.
 
callable null $chronologyCallback
 Callback to run before the first connection attempt.
 
bool $chronologyCallbackTriggered = false
 Whether the session consistency callback already executed.
 
bool $cliMode
 Whether this PHP instance is for a CLI script.
 
string null $clusterName
 The name of the DB cluster.
 
int $connectionCounter = 0
 Total number of new connections ever made with this instance.
 
LoggerInterface $connLogger
 
IDatabase[][][] $conns
 Map of (pool category => server index => domain => IDatabase)
 
CriticalSectionProvider null $csProvider
 
string null $defaultGroup
 Default query group to use with getConnection()
 
callable $deprecationLogger
 Deprecation logger.
 
bool $disabled = false
 
DatabaseDomain[] string[] $domainAliases = []
 Map of (domain alias => DB domain)
 
Database $errorConnection
 Connection handle that caused a problem.
 
callable $errorLogger
 Exception logger.
 
array[] $groupLoads
 Map of (group => server index => weight)
 
 $id
 var int An identifier for this class instance
 
string[] $indexAliases = []
 Map of (index alias => index)
 
bool $laggedReplicaMode = false
 Whether the generic reader fell back to a lagged replica DB.
 
string $lastError = 'Unknown error'
 The last DB selection or connection error.
 
ILoadMonitor $loadMonitor
 
array $loadMonitorConfig
 The LoadMonitor configuration.
 
DatabaseDomain $localDomain
 Local DB domain ID and default for selectDB() calls.
 
int $maxLag
 
int[] $maxLagByIndex
 Map of (server index => seconds of lag considered "high")
 
DatabaseDomain[] $nonLocalDomainCache = []
 Map of (domain ID => domain instance)
 
int null $ownerId
 Integer ID of the managing LBFactory instance or null if none.
 
LoggerInterface $perfLogger
 
callable null $profiler
 An optional callback that returns a ScopedCallback instance, meant to profile the actual query execution in {.
 
LoggerInterface $queryLogger
 
int[] $readIndexByGroup = []
 The group replica server indexes keyed by group.
 
string bool $readOnlyReason = false
 Reason this instance is read-only or false if not.
 
LoggerInterface $replLogger
 
array[] $servers
 Map of (server index => server config array)
 
BagOStuff $srvCache
 
array[] $tableAliases = []
 $aliases Map of (table => (dbname, schema, prefix) map)
 
bool[] $tempTablesOnlyMode = []
 Map of (domain => whether to use "temp tables only" mode)
 
TransactionProfiler $trxProfiler
 
callable[] $trxRecurringCallbacks = []
 Map of (name => callable)
 
string bool $trxRoundId = false
 Explicit DBO_TRX transaction round active or false if none.
 
string $trxRoundStage = self::ROUND_CURSORY
 Stage of the current transaction round in the transaction round life-cycle.
 
bool DBPrimaryPos $waitForPos
 Replication sync position or false if not set.
 
int $waitTimeout
 Seconds to spend waiting on replica DB lag to resolve.
 
WANObjectCache $wanCache
 
const CONN_HELD_WARN_THRESHOLD = 10
 Warn when this many connection are held.
 
const INFO_AUTOCOMMIT_ONLY = 'autoCommitOnly'
 
const INFO_FOREIGN_REF_COUNT = 'foreignPoolRefCount'
 
const INFO_FORIEGN = 'foreign'
 
const INFO_SERVER_INDEX = 'serverIndex'
 
const KEY_FOREIGN_FREE = 'foreignFree'
 
const KEY_FOREIGN_FREE_NOROUND = 'foreignFreeAutoCommit'
 
const KEY_FOREIGN_INUSE = 'foreignInUse'
 
const KEY_FOREIGN_INUSE_NOROUND = 'foreignInUseAutoCommit'
 
const KEY_LOCAL = 'local'
 
const KEY_LOCAL_DOMAIN = '__local__'
 
const KEY_LOCAL_NOROUND = 'localAutoCommit'
 
const MAX_WAIT_DEFAULT = 10
 Default 'waitTimeout' when unspecified.
 
const ROUND_APPROVED = 'approved'
 Transaction round passed final pre-commit checks.
 
const ROUND_COMMIT_CALLBACKS = 'commit-callbacks'
 Transaction round was committed and post-commit callbacks must be run.
 
const ROUND_CURSORY = 'cursory'
 Transaction round, explicit or implicit, has not finished writing.
 
const ROUND_ERROR = 'error'
 Transaction round encountered an error.
 
const ROUND_FINALIZED = 'finalized'
 Transaction round writes are complete and ready for pre-commit checks.
 
const ROUND_ROLLBACK_CALLBACKS = 'rollback-callbacks'
 Transaction round was rolled back and post-rollback callbacks must be run.
 
const TTL_CACHE_READONLY = 5
 Seconds to cache primary DB server read-only status.
 

Detailed Description

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

Definition at line 43 of file LoadBalancer.php.

Constructor & Destructor Documentation

◆ __construct()

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

Construct a manager of IDatabase connection objects.

Parameters
array$paramsParameter map with keys:
  • servers : List of server info structures
  • localDomain: A DatabaseDomain or domain ID string
  • loadMonitor : LoadMonitor::__construct() parameters with "class" field. [optional]
  • readOnlyReason : Reason the primary DB is read-only if so [optional]
  • waitTimeout : Maximum time to wait for replicas for consistency [optional]
  • maxLag: Try to avoid DB replicas with lag above this many seconds [optional]
  • srvCache : BagOStuff object for server cache [optional]
  • wanCache : WANObjectCache object [optional]
  • chronologyCallback: Callback to run before the first connection attempt [optional]
  • defaultGroup: Default query group; the generic group if not specified [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]
  • roundStage: STAGE_POSTCOMMIT_* class constant; for internal use [optional]
  • ownerId: integer ID of an LBFactory instance that manages this instance [optional]
  • clusterName: The logical name of the DB cluster [optional]
  • criticalSectionProvider: CriticalSectionProvider instance [optional]
Exceptions
InvalidArgumentException

Implements Wikimedia\Rdbms\ILoadBalancer.

Reimplemented in Wikimedia\Rdbms\LoadBalancerSingle.

Definition at line 191 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\$localDomain, Wikimedia\Rdbms\LoadBalancer\$maxLag, Wikimedia\Rdbms\ILoadBalancer\GROUP_GENERIC, Wikimedia\Rdbms\LoadBalancer\MAX_LAG_DEFAULT, Wikimedia\Rdbms\LoadBalancer\MAX_WAIT_DEFAULT, Wikimedia\Rdbms\DatabaseDomain\newFromId(), Wikimedia\Rdbms\LoadBalancer\newTrackedConnectionsArray(), Wikimedia\Rdbms\DatabaseDomain\newUnspecified(), Wikimedia\Rdbms\LoadBalancer\ROUND_COMMIT_CALLBACKS, Wikimedia\Rdbms\LoadBalancer\ROUND_ROLLBACK_CALLBACKS, and Wikimedia\Rdbms\LoadBalancer\setLocalDomain().

◆ __destruct()

Wikimedia\Rdbms\LoadBalancer::__destruct ( )

Reimplemented in Wikimedia\Rdbms\LoadBalancerSingle.

Definition at line 2631 of file LoadBalancer.php.

Member Function Documentation

◆ allowLagged()

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

Disables/enables lag checks.

Parameters
null | bool$mode
Returns
bool

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2308 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\pickReaderIndex().

◆ applyTransactionRoundFlags()

Wikimedia\Rdbms\LoadBalancer::applyTransactionRoundFlags ( Database  $conn)
private

Make all DB servers with DBO_DEFAULT/DBO_TRX set join the transaction round.

Some servers may have neither flag enabled, meaning that they opt out of such transaction rounds and remain in auto-commit mode. Such behavior might be desired when a DB server is used for something like simple key/value storage.

Parameters
Database$conn

Definition at line 2058 of file LoadBalancer.php.

References Wikimedia\Rdbms\Database\getFlag(), Wikimedia\Rdbms\Database\getLBInfo(), Wikimedia\Rdbms\Database\setFlag(), and Wikimedia\Rdbms\Database\setLBInfo().

◆ approveMasterChanges()

Wikimedia\Rdbms\LoadBalancer::approveMasterChanges ( array  $options,
  $fname = __METHOD__,
  $owner = null 
)
Deprecated:
since 1.37; please use approvePrimaryChanges() instead.
Parameters
array$optionsIncludes:
  • maxWriteDuration : max write query duration time in seconds
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Exceptions
DBTransactionError

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1785 of file LoadBalancer.php.

References wfDeprecated().

◆ approvePrimaryChanges()

Wikimedia\Rdbms\LoadBalancer::approvePrimaryChanges ( array  $options,
  $fname = __METHOD__,
  $owner = null 
)

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
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Exceptions
DBTransactionError
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1742 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\assertNoOpenTransactions(), Wikimedia\Rdbms\IDatabase\pendingWriteQueryDuration(), Wikimedia\Rdbms\IDatabase\ping(), and Wikimedia\Rdbms\IDatabase\writesOrCallbacksPending().

◆ assertOwnership()

Wikimedia\Rdbms\LoadBalancer::assertOwnership (   $fname,
  $owner 
)
private

Assure that if this instance is owned, the caller is either the owner or is internal.

If an LBFactory owns the LoadBalancer, then certain methods should only called through that LBFactory to avoid broken contracts. Otherwise, those methods can publically be called by anything. In any case, internal methods from the LoadBalancer itself should always be allowed.

Parameters
string$fname
int | null$ownerOwner ID of the caller
Exceptions
DBTransactionError

Definition at line 2040 of file LoadBalancer.php.

◆ assertTransactionRoundStage()

Wikimedia\Rdbms\LoadBalancer::assertTransactionRoundStage (   $stage)
private
Parameters
string | string[]$stage
Exceptions
DBTransactionError

Definition at line 2011 of file LoadBalancer.php.

◆ beginMasterChanges()

Wikimedia\Rdbms\LoadBalancer::beginMasterChanges (   $fname = __METHOD__,
  $owner = null 
)
Deprecated:
since 1.37; please use beginPrimaryChanges() instead.
Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Exceptions
DBExpectedError

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1819 of file LoadBalancer.php.

References wfDeprecated().

◆ beginPrimaryChanges()

Wikimedia\Rdbms\LoadBalancer::beginPrimaryChanges (   $fname = __METHOD__,
  $owner = null 
)

Flush any primary 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:

  • commitPrimaryChanges()
  • rollbackPrimaryChanges()
  • commitAll() This allows for custom transaction rounds from any outer transaction scope.
Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Exceptions
DBExpectedError
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1790 of file LoadBalancer.php.

◆ closeAll()

Wikimedia\Rdbms\LoadBalancer::closeAll (   $fname = __METHOD__,
  $owner = null 
)

Close all open connections.

Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1649 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\close(), and Wikimedia\Rdbms\IDatabase\getServerName().

◆ closeConnection()

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.

Definition at line 1664 of file LoadBalancer.php.

References $type, Wikimedia\Rdbms\IDatabase\close(), Wikimedia\Rdbms\IDatabase\getDomainID(), and Wikimedia\Rdbms\IDatabase\getLBInfo().

Referenced by Wikimedia\Rdbms\LoadBalancer\doWait().

◆ commitAll()

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

Commit transactions on all open connections.

Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Exceptions
DBExpectedError

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1702 of file LoadBalancer.php.

◆ commitMasterChanges()

Wikimedia\Rdbms\LoadBalancer::commitMasterChanges (   $fname = __METHOD__,
  $owner = null 
)
Deprecated:
since 1.37; please use commitPrimaryChanges() instead.
Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Exceptions
DBExpectedError

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1864 of file LoadBalancer.php.

References wfDeprecated().

◆ commitPrimaryChanges()

Wikimedia\Rdbms\LoadBalancer::commitPrimaryChanges (   $fname = __METHOD__,
  $owner = null 
)

Issue COMMIT on all open primary connections to flush changes and view snapshots.

Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Exceptions
DBExpectedError
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1824 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\commit().

◆ disable()

Wikimedia\Rdbms\LoadBalancer::disable (   $fname = __METHOD__,
  $owner = null 
)

Close all connections and disable this load balancer.

Any attempt to open a new connection will result in a DBAccessError.

Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1643 of file LoadBalancer.php.

◆ doWait()

Wikimedia\Rdbms\LoadBalancer::doWait (   $index,
  $timeout = null 
)
private

◆ enforceConnectionFlags()

Wikimedia\Rdbms\LoadBalancer::enforceConnectionFlags ( IDatabase  $conn,
  $flags 
)
private
Parameters
IDatabase$conn
int$flags
Exceptions
DBUnexpectedError

Definition at line 402 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\clearFlag(), and Wikimedia\Rdbms\IDatabase\trxLevel().

Referenced by Wikimedia\Rdbms\LoadBalancer\getAnyOpenConnection(), and Wikimedia\Rdbms\LoadBalancer\getServerConnection().

◆ fieldHasBit()

Wikimedia\Rdbms\LoadBalancer::fieldHasBit ( int  $flags,
int  $bit 
)
private
Parameters
int$flagsA bitfield of flags
int$bitBit flag constant
Returns
bool Whether the bit field has the specified bit flag set

Definition at line 2610 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getAnyOpenConnection().

◆ finalizeMasterChanges()

Wikimedia\Rdbms\LoadBalancer::finalizeMasterChanges (   $fname = __METHOD__,
  $owner = null 
)
Deprecated:
since 1.37 Use finalizePrimaryChanges() instead.
Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Returns
int Number of pre-commit callbacks run (since 1.32)

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1737 of file LoadBalancer.php.

References wfDeprecated().

◆ finalizePrimaryChanges()

Wikimedia\Rdbms\LoadBalancer::finalizePrimaryChanges (   $fname = __METHOD__,
  $owner = null 
)

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

Use this only for mutli-database commits

Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Returns
int Number of pre-commit callbacks run (since 1.32)
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1708 of file LoadBalancer.php.

References Wikimedia\Rdbms\Database\runOnTransactionPreCommitCallbacks(), and Wikimedia\Rdbms\Database\setTrxEndCallbackSuppression().

◆ flushMasterSnapshots()

Wikimedia\Rdbms\LoadBalancer::flushMasterSnapshots (   $fname = __METHOD__,
  $owner = null 
)
Deprecated:
since 1.37; please use flushPrimarySnapshots() instead.
Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2105 of file LoadBalancer.php.

References wfDeprecated().

◆ flushPrimarySnapshots()

Wikimedia\Rdbms\LoadBalancer::flushPrimarySnapshots (   $fname = __METHOD__,
  $owner = null 
)

Commit all primary DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.

An error will be thrown if a connection has pending writes or callbacks

Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2098 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\flushSnapshot().

◆ flushReplicaSnapshots()

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

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

Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2091 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\flushSnapshot().

◆ forEachOpenConnection()

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

Call a function with each open connection object.

Parameters
callable$callback
array$params

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2328 of file LoadBalancer.php.

◆ forEachOpenMasterConnection()

Wikimedia\Rdbms\LoadBalancer::forEachOpenMasterConnection (   $callback,
array  $params = [] 
)
Deprecated:
since 1.37; please use forEachOpenPrimaryConnection() instead.
Parameters
callable$callback
array$params

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2350 of file LoadBalancer.php.

References wfDeprecated().

◆ forEachOpenPrimaryConnection()

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

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

Parameters
callable$callback
array$params
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2338 of file LoadBalancer.php.

Referenced by DeferredUpdates\areDatabaseTransactionsActive().

◆ forEachOpenReplicaConnection()

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.

Definition at line 2355 of file LoadBalancer.php.

◆ getAnyOpenConnection()

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

Get an existing live handle to the given server index (on any domain)

Use the CONN_TRX_AUTOCOMMIT flag to only look for connections opened with that flag.

Avoid the use of begin()/commit() and startAtomic()/endAtomic() on any handle returned. This method is largely intended for internal by RDBMs callers that issue queries that do not affect any current transaction.

Parameters
int$iSpecific or virtual (DB_PRIMARY/DB_REPLICA) server index
int$flagsBitfield of CONN_* class constants
Returns
Database|bool False if no such connection is open

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 806 of file LoadBalancer.php.

References $type, Wikimedia\Rdbms\ILoadBalancer\DB_PRIMARY, Wikimedia\Rdbms\LoadBalancer\enforceConnectionFlags(), Wikimedia\Rdbms\LoadBalancer\fieldHasBit(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and Wikimedia\Rdbms\LoadBalancer\pickAnyOpenConnection().

Referenced by Wikimedia\Rdbms\LoadBalancer\doWait().

◆ getClusterName()

Wikimedia\Rdbms\LoadBalancer::getClusterName ( )

Get the logical name of the database cluster.

This is useful for identifying a cluster or replicated dataset, even when:

  • The primary server is sometimes swapped with another one
  • The cluster/dataset is replicated among multiple datacenters, with one "primary" datacenter having the writable primary server and the other datacenters having a read-only replica in the "primary" server slot
  • The dataset is replicated among multiple datacenters, via circular replication, with each datacenter having its own "primary" server
Returns
string
Since
1.36

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 284 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\$clusterName, Wikimedia\Rdbms\LoadBalancer\getServerName(), and Wikimedia\Rdbms\LoadBalancer\getWriterIndex().

◆ getConnection()

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

Get a live handle for a specific or virtual (DB_PRIMARY/DB_REPLICA) server index.

The server index, $i, can be one of the following:

  • DB_REPLICA: a server index will be selected by the load balancer based on read weight, connectivity, and replication lag. Note that the primary server might be configured with read weight. If $groups is empty then it means "the generic group", in which case all servers defined with read weight will be considered. Additional query groups can be configured, having their own list of server indexes and read weights. If a query group list is provided in $groups, then each recognized group will be tried, left-to-right, until server index selection succeeds or all groups have been tried, in which case the generic group will be tried.
  • DB_PRIMARY: the primary server index will be used; the same as getWriterIndex(). The value of $groups should be [] when using this server index.
  • Specific server index: a positive integer can be provided to use the server with that index. An error will be thrown in no such server index is recognized. This server selection method is usually only useful for internal load balancing logic. The value of $groups should be [] when using a specific server index.

Handles acquired by this method, getConnectionRef(), getLazyConnectionRef(), and getMaintenanceConnectionRef() use the same set of shared connection pools. Callers that get a local DB domain handle for the same server will share one handle for all of those callers using CONN_TRX_AUTOCOMMIT (via $flags) and one handle for all of those callers not using CONN_TRX_AUTOCOMMIT. Callers that get a foreign DB domain handle (via $domain) will share any handle that has the right CONN_TRX_AUTOCOMMIT mode and is already on the right DB domain. Otherwise, one of the "free for reuse" handles will be claimed or a new handle will be made if there are none.

Handle sharing is particularly useful when callers get local DB domain (the default), transaction round aware (the default), DB_PRIMARY handles. All such callers will operate within a single database transaction as a consequence. Handle sharing is also useful when callers get local DB domain (the default), transaction round aware (the default), samely query grouped (the default), DB_REPLICA handles. All such callers will operate within a single database transaction as a consequence.

Callers of this function that use a non-local $domain must call reuseConnection() after their last query on this handle executed. This lets the load balancer share the handle with other callers requesting connections on different database domains.

Use CONN_TRX_AUTOCOMMIT to use a separate pool of only auto-commit handles. This flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. getServerAttributes() can be used to check such attributes beforehand. Avoid using IDatabase::begin() and IDatabase::commit() on such handles. If it is not possible to avoid using methods like IDatabase::startAtomic() and IDatabase::endAtomic(), callers should at least make sure that the atomic sections are closed on failure via try/catch and IDatabase::cancelAtomic().

See also
ILoadBalancer::reuseConnection()
ILoadBalancer::getServerAttributes()
Parameters
int$iSpecific (overrides $groups) or virtual (DB_PRIMARY/DB_REPLICA) server index
string[] | string$groupsQuery group(s) in preference order; [] for the default group
string | bool$domainDB domain ID or false for the local domain
int$flagsBitfield of CONN_* class constants
Note
This method throws DBAccessError if ILoadBalancer::disable() was called
Returns
IDatabase|bool This returns false on failure if CONN_SILENCE_ERRORS is set
Exceptions
DBErrorIf no live handle could be obtained and CONN_SILENCE_ERRORS is not set
DBAccessErrorIf disable() was previously called
InvalidArgumentException

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 953 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\getConnectionIndex(), Wikimedia\Rdbms\LoadBalancer\getExistingReaderIndex(), Wikimedia\Rdbms\LoadBalancer\getLaggedReplicaMode(), Wikimedia\Rdbms\LoadBalancer\getServerConnection(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), Wikimedia\Rdbms\LoadBalancer\resolveDomainID(), Wikimedia\Rdbms\LoadBalancer\resolveGroups(), and Wikimedia\Rdbms\LoadBalancer\sanitizeConnectionFlags().

Referenced by Wikimedia\Rdbms\LoadBalancer\getConnectionRef().

◆ getConnectionIndex()

Wikimedia\Rdbms\LoadBalancer::getConnectionIndex (   $i,
array  $groups,
  $domain 
)
private

Get the server index to use for a specified server index and query group list.

Parameters
int$iSpecific server index or DB_PRIMARY/DB_REPLICA
string[]$groupsNon-empty query group list in preference order
string | bool$domain
Returns
int A specific server index (replica DBs are checked for connectivity)

Definition at line 505 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\$lastError, Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and Wikimedia\Rdbms\LoadBalancer\reportConnectionError().

Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection().

◆ getConnectionRef()

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

Get a live database handle reference for a server index.

The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. The getServerAttributes() method can be used to check such flags beforehand. Avoid the use of begin() or startAtomic() on any CONN_TRX_AUTOCOMMIT connections.

See also
ILoadBalancer::getConnection() for parameter information
Parameters
int$iSpecific or virtual (DB_PRIMARY/DB_REPLICA) server index
string[] | string$groupsQuery group(s) in preference order; [] for the default group
string | bool$domainDB domain ID or false for the local domain
int$flagsBitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT)
Returns
DBConnRef

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1087 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\getConnection(), Wikimedia\Rdbms\LoadBalancer\getRoleFromIndex(), and Wikimedia\Rdbms\LoadBalancer\resolveDomainID().

◆ getConnLogContext()

Wikimedia\Rdbms\LoadBalancer::getConnLogContext ( IDatabase  $conn,
array  $extras = [] 
)
protected

Create a log context to pass to PSR-3 logger functions.

Parameters
IDatabase$conn
array$extrasAdditional data to add to context
Returns
array

Definition at line 2621 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\getDomainID(), and Wikimedia\Rdbms\IDatabase\getServerName().

Referenced by Wikimedia\Rdbms\LoadBalancer\doWait(), and Wikimedia\Rdbms\LoadBalancer\pickAnyOpenConnection().

◆ getCurrentConnectionCount()

Wikimedia\Rdbms\LoadBalancer::getCurrentConnectionCount ( )
private
Returns
int

Definition at line 2371 of file LoadBalancer.php.

◆ getExistingReaderIndex()

Wikimedia\Rdbms\LoadBalancer::getExistingReaderIndex (   $group)
protected

Get the server index chosen by the load balancer for use with the given query group.

Parameters
string$groupQuery group; use false for the generic group
Returns
int Server index or LoadBalancer::READER_INDEX_NONE if none was chosen

Definition at line 591 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection(), Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), Wikimedia\Rdbms\LoadBalancer\waitFor(), and Wikimedia\Rdbms\LoadBalancer\waitForOne().

◆ getForeignConnection()

Wikimedia\Rdbms\LoadBalancer::getForeignConnection (   $i,
  $domain,
  $flags = 0 
)
private

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 domain. 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->errorConnection.

Note
If disable() was called on this LoadBalancer, this method will throw a DBAccessError.
Parameters
int$iSpecific server index
string$domainDomain ID to open
int$flagsClass CONN_* constant bitfield
Returns
Database|bool Returns false on connection error
Exceptions
DBErrorWhen database selection fails
InvalidArgumentExceptionWhen the server index is invalid
UnexpectedValueExceptionWhen the DB domain of the connection is corrupted

Definition at line 1231 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getServerConnection().

◆ getLaggedReplicaMode()

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

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2181 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection().

◆ getLagTimes()

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
float[]|int[]|false[] Map of (server index => lag) in order of server index

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2403 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getRandomNonLagged().

◆ getLazyConnectionRef()

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

Get a lazy-connecting database handle reference for a server index.

The handle's methods simply proxy to those of an underlying IDatabase handle which takes care of the actual connection and query logic.

The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. getServerAttributes() can be used to check such flags beforehand. Avoid the use of begin() or startAtomic() on any CONN_TRX_AUTOCOMMIT connections.

See also
ILoadBalancer::getConnection() for parameter information
Parameters
int$iSpecific or virtual (DB_PRIMARY/DB_REPLICA) server index
string[] | string$groupsQuery group(s) in preference order; [] for the default group
string | bool$domainDB domain ID or false for the local domain
int$flagsBitfield of CONN_* class constants
Returns
DBConnRef Live connection handle
Exceptions
DBErrorIf no live handle could be obtained
DBAccessErrorIf disable() was previously called

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1101 of file LoadBalancer.php.

◆ getLoadMonitor()

Wikimedia\Rdbms\LoadBalancer::getLoadMonitor ( )
private

Get a LoadMonitor instance.

Returns
ILoadMonitor

Definition at line 420 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\$loadMonitor.

Referenced by Wikimedia\Rdbms\LoadBalancer\getReaderIndex().

◆ getLocalConnection()

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

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

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

Note
If disable() was called on this LoadBalancer, this method will throw a DBAccessError.
Parameters
int$iSpecific server index
int$flagsClass CONN_* constant bitfield
Returns
Database
Exceptions
InvalidArgumentExceptionWhen the server index is invalid
UnexpectedValueExceptionWhen the DB domain of the connection is corrupted

Definition at line 1168 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getServerConnection().

◆ getLocalDomainID()

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

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 295 of file LoadBalancer.php.

◆ getMaintenanceConnectionRef()

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

Get a live database handle, suitable for migrations and schema changes, for a server index.

The handle's methods simply proxy to those of an underlying IDatabase handle which takes care of the actual connection and query logic.

The CONN_TRX_AUTOCOMMIT flag is ignored for databases with ATTR_DB_LEVEL_LOCKING (e.g. sqlite) in order to avoid deadlocks. getServerAttributes() can be used to check such flags beforehand. Avoid the use of begin() or startAtomic() on any CONN_TRX_AUTOCOMMIT connections.

See also
ILoadBalancer::getConnection() for parameter information
Parameters
int$iSpecific or virtual (DB_PRIMARY/DB_REPLICA) server index
string[] | string$groupsQuery group(s) in preference order; [] for the default group
string | bool$domainDB domain ID or false for the local domain
int$flagsBitfield of CONN_* class constants (e.g. CONN_TRX_AUTOCOMMIT)
Returns
MaintainableDBConnRef Live connection handle
Exceptions
DBErrorIf no live handle could be obtained
DBAccessErrorIf disable() was previously called

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1114 of file LoadBalancer.php.

◆ getMasterPos()

Wikimedia\Rdbms\LoadBalancer::getMasterPos ( )
Deprecated:
since 1.37 Use getPrimaryPos() instead.
Returns
DBPrimaryPos|bool Returns false if not applicable
Exceptions
DBError

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1613 of file LoadBalancer.php.

References wfDeprecated().

◆ getMaxLag()

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

Get the name and lag time of the most-lagged replica server.

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{0:string,1:float|int|false,2:int} (host, max lag, index of max lagged host)

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2382 of file LoadBalancer.php.

◆ getPrimaryPos()

Wikimedia\Rdbms\LoadBalancer::getPrimaryPos ( )

Get the current primary replication position.

Returns
DBPrimaryPos|bool Returns false if not applicable
Exceptions
DBError
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1593 of file LoadBalancer.php.

◆ getPrimaryServerName()

Wikimedia\Rdbms\LoadBalancer::getPrimaryServerName ( )
private
Returns
string Name of the primary DB server of the relevant DB cluster (e.g. "db1052")

Definition at line 2601 of file LoadBalancer.php.

◆ getRandomNonLagged()

Wikimedia\Rdbms\LoadBalancer::getRandomNonLagged ( array  $loads,
string  $domain,
  $maxLag = INF 
)
private
Parameters
array$loads
string$domainResolved DB domain
int$maxLagRestrict the maximum allowed lag to this many seconds
Returns
bool|int|string

Definition at line 447 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\$maxLag, Wikimedia\Rdbms\LoadBalancer\getLagTimes(), Wikimedia\Rdbms\LoadBalancer\getServerName(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and ArrayUtils\pickRandom().

Referenced by Wikimedia\Rdbms\LoadBalancer\pickReaderIndex().

◆ getReaderIndex()

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

Get the specific server index of the reader connection for a given group.

This takes into account load ratios and lag times. It should return a consistent index during the life time of the load balancer. This initially checks replica DBs for connectivity to avoid returning an unusable server. This means that connections might be attempted by calling this method (usally one at the most but possibly more). Subsequent calls with the same $group will not need to make new connection attempts since the acquired connection for each group is preserved.

Parameters
string | bool$groupQuery group or false for the generic group
string | bool$domainDB domain ID or false for the local domain
Returns
int|bool Specific server index, or false if no live handle can be obtained

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 529 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\$laggedReplicaMode, Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getExistingReaderIndex(), Wikimedia\Rdbms\LoadBalancer\getLoadMonitor(), Wikimedia\Rdbms\LoadBalancer\getServerCount(), Wikimedia\Rdbms\LoadBalancer\getServerName(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), Wikimedia\Rdbms\ILoadBalancer\GROUP_GENERIC, Wikimedia\Rdbms\LoadBalancer\lazyLoadReplicationPositions(), Wikimedia\Rdbms\LoadBalancer\pickReaderIndex(), Wikimedia\Rdbms\LoadBalancer\resolveDomainID(), and Wikimedia\Rdbms\LoadBalancer\setExistingReaderIndex().

Referenced by Wikimedia\Rdbms\LoadBalancer\getConnectionIndex().

◆ getReadOnlyReason()

Wikimedia\Rdbms\LoadBalancer::getReadOnlyReason (   $domain = false)
Note
This method may trigger a DB connection if not yet done
Parameters
string | bool$domainDB domain ID or false for the local domain
Returns
string|bool Reason the primary is read-only or false if it is not

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2201 of file LoadBalancer.php.

◆ getReplicaResumePos()

Wikimedia\Rdbms\LoadBalancer::getReplicaResumePos ( )

Get the highest DB replication position for chronology control purposes.

If there is only a primary server then this returns false. If replication is present and correctly configured, then this returns the highest replication position of any server with an open connection. That position can later be passed to waitFor() on a new load balancer instance to make sure that queries on the new connections see data at least as up-to-date as queries (prior to this method call) on the old connections.

This can be useful for implementing session consistency, where the session will be resumed accross multiple HTTP requests or CLI script instances.

Returns
DBPrimaryPos|bool Replication position or false if not applicable
Since
1.34

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1618 of file LoadBalancer.php.

◆ getRoleFromIndex()

Wikimedia\Rdbms\LoadBalancer::getRoleFromIndex (   $i)
private
Parameters
int$iServer index or DB_PRIMARY/DB_REPLICA
Returns
int One of DB_PRIMARY/DB_REPLICA

Definition at line 1137 of file LoadBalancer.php.

References DB_PRIMARY, and DB_REPLICA.

Referenced by Wikimedia\Rdbms\LoadBalancer\getConnectionRef().

◆ getServerAttributes()

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

Get basic attributes of the server with the specified index without connecting.

Parameters
int$iSpecific server index
Returns
array (Database::ATTRIBUTE_* constant => value) for all such constants
Since
1.31

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1327 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\sanitizeConnectionFlags().

◆ getServerConnection()

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

Get a live handle for a specific server index.

This is a simpler version of getConnection() that does not accept virtual server indexes (e.g. DB_PRIMARY/DB_REPLICA), does not assure that primary DB handles have read-only mode when there is high replication lag, and can only trigger attempts to connect to a single server (the one with the specified server index).

See also
ILoadBalancer::getConnection()
Parameters
int$iSpecific server index
string$domainResolved DB domain
int$flagsBitfield of class CONN_* constants
Returns
IDatabase|false This returns false on failure if CONN_SILENCE_ERRORS is set
Exceptions
DBErrorIf no live handle could be obtained and CONN_SILENCE_ERRORS is not set

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 981 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\$connectionCounter, Wikimedia\Rdbms\LoadBalancer\$readOnlyReason, Wikimedia\Rdbms\LoadBalancer\enforceConnectionFlags(), Wikimedia\Rdbms\LoadBalancer\getForeignConnection(), Wikimedia\Rdbms\LoadBalancer\getLocalConnection(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), Wikimedia\Rdbms\LoadBalancer\isPrimaryConnectionReadOnly(), and Wikimedia\Rdbms\LoadBalancer\reportConnectionError().

Referenced by Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getConnection(), and Wikimedia\Rdbms\LoadBalancer\pickReaderIndex().

◆ getServerCount()

Wikimedia\Rdbms\LoadBalancer::getServerCount ( )

Get the number of servers defined in configuration.

Returns
int

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1553 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getReaderIndex().

◆ getServerInfo()

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

Return the server configuration map for the server with the specified index.

Parameters
int$iSpecific server index
Returns
array|false Server configuration map; false if the index is invalid
Since
1.31

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1585 of file LoadBalancer.php.

◆ getServerInfoStrict()

Wikimedia\Rdbms\LoadBalancer::getServerInfoStrict (   $i,
  $field = null 
)
private
Parameters
int$iServer index
string | null$fieldServer index field [optional]
Returns
array|mixed
Exceptions
InvalidArgumentException

Definition at line 2582 of file LoadBalancer.php.

◆ getServerName()

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

Get the readable name of the server with the specified index.

Parameters
int$iSpecific server index
Returns
string Readable server name, falling back to the hostname or IP address

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1579 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getClusterName(), Wikimedia\Rdbms\LoadBalancer\getRandomNonLagged(), Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), and Wikimedia\Rdbms\LoadBalancer\pickReaderIndex().

◆ getServerType()

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

Get the RDBMS type of the server with the specified index (e.g.

"mysql", "sqlite")

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

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1589 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\sanitizeConnectionFlags().

◆ getStreamingReplicaIndexes()

Wikimedia\Rdbms\LoadBalancer::getStreamingReplicaIndexes ( )
private
Returns
int[] List of replica server indexes

Definition at line 1564 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\waitForAll().

◆ getTopologyRole()

Wikimedia\Rdbms\LoadBalancer::getTopologyRole (   $i,
array  $server 
)
private
Parameters
int$iSpecific server index
array$serverServer config map
Returns
string IDatabase::ROLE_* constant

Definition at line 1457 of file LoadBalancer.php.

◆ getTransactionRoundStage()

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

Definition at line 2114 of file LoadBalancer.php.

◆ getWriterIndex()

◆ hasMasterChanges()

Wikimedia\Rdbms\LoadBalancer::hasMasterChanges ( )
Deprecated:
since 1.37; please use hasPrimaryChanges() instead.
Returns
bool

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2136 of file LoadBalancer.php.

References wfDeprecated().

◆ hasMasterConnection()

Wikimedia\Rdbms\LoadBalancer::hasMasterConnection ( )
Deprecated:
since 1.37; please use hasPrimaryConnection() instead.
Returns
bool Whether a primary connection is already open

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2122 of file LoadBalancer.php.

References wfDeprecated().

◆ hasOrMadeRecentMasterChanges()

Wikimedia\Rdbms\LoadBalancer::hasOrMadeRecentMasterChanges (   $age = null)
Deprecated:
since 1.37; please use hasOrMadeRecentPrimaryChanges() instead.
Parameters
float | null$ageHow many seconds ago is "recent" [defaults to mWaitTimeout]
Returns
bool

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2162 of file LoadBalancer.php.

References wfDeprecated().

◆ hasOrMadeRecentPrimaryChanges()

Wikimedia\Rdbms\LoadBalancer::hasOrMadeRecentPrimaryChanges (   $age = null)

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

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

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2155 of file LoadBalancer.php.

◆ hasPrimaryChanges()

Wikimedia\Rdbms\LoadBalancer::hasPrimaryChanges ( )

Whether there are pending changes or callbacks in a transaction by this thread.

Returns
bool
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2127 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\writesOrCallbacksPending().

◆ hasPrimaryConnection()

Wikimedia\Rdbms\LoadBalancer::hasPrimaryConnection ( )
Returns
bool Whether a primary connection is already open
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2118 of file LoadBalancer.php.

◆ hasReplicaServers()

Wikimedia\Rdbms\LoadBalancer::hasReplicaServers ( )

Whether there are any replica servers configured.

This counts both servers using streaming replication from the primary server and servers that just have a clone of the static dataset found on the primary server

Returns
int
Since
1.34

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1557 of file LoadBalancer.php.

◆ hasStreamingReplicaServers()

Wikimedia\Rdbms\LoadBalancer::hasStreamingReplicaServers ( )

Whether any replica servers use streaming replication from the primary server.

Generally this is one less than getServerCount(), though it might otherwise return a lower number if some of the servers are configured with "is static". That flag is used when both the server has no active replication setup and the dataset is either read-only or occasionally updated out-of-band. For example, a script might import a new geographic information dataset each week by writing it to each server and later directing the application to use the new version.

It is possible for some replicas to be configured with "is static" but not others, though it generally should either be set for all or none of the replicas.

If this returns zero, this means that there is generally no reason to execute replication wait logic for session consistency and lag reduction.

Returns
int
Since
1.34

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1575 of file LoadBalancer.php.

◆ haveIndex()

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

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

Parameters
int$i
Returns
bool
Deprecated:
Since 1.34

Definition at line 1538 of file LoadBalancer.php.

◆ initConnFlags()

Wikimedia\Rdbms\LoadBalancer::initConnFlags (   $flags)
private
See also
IDatabase::DBO_DEFAULT
Parameters
int$flagsBit field of IDatabase::DBO_* constants from configuration
Returns
int Bit field of IDatabase::DBO_* constants to use with Database::factory()

Definition at line 1472 of file LoadBalancer.php.

References DBO_TRX.

◆ isNonZeroLoad()

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

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

Parameters
int$i
Returns
bool
Deprecated:
Since 1.34

Definition at line 1549 of file LoadBalancer.php.

◆ isOpen()

Wikimedia\Rdbms\LoadBalancer::isOpen (   $index)
private

Test if the specified index represents an open connection.

Parameters
int$indexServer index
Returns
bool

Definition at line 1340 of file LoadBalancer.php.

◆ isPrimaryConnectionReadOnly()

Wikimedia\Rdbms\LoadBalancer::isPrimaryConnectionReadOnly ( IDatabase  $conn,
  $flags = 0 
)
private
Note
This method suppresses DBError exceptions in order to avoid severe downtime
Parameters
IDatabase$connPrimary connection
int$flagsBitfield of class CONN_* constants
Returns
bool Whether the entire server or currently selected DB/schema is read-only

Definition at line 2225 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\dbSchema(), Wikimedia\Rdbms\IDatabase\getDBname(), Wikimedia\Rdbms\IDatabase\getServerName(), and Wikimedia\Rdbms\IDatabase\serverIsReadOnly().

Referenced by Wikimedia\Rdbms\LoadBalancer\getServerConnection().

◆ isPrimaryRunningReadOnly()

Wikimedia\Rdbms\LoadBalancer::isPrimaryRunningReadOnly ( DatabaseDomain  $domain)
private
Note
This method suppresses DBError exceptions in order to avoid severe downtime
Parameters
DatabaseDomain$domain
Returns
bool Whether the entire primary DB server or the local domain DB is read-only

Definition at line 2267 of file LoadBalancer.php.

References Wikimedia\Rdbms\DatabaseDomain\getDatabase(), Wikimedia\Rdbms\DatabaseDomain\getId(), and Wikimedia\Rdbms\DatabaseDomain\getSchema().

◆ laggedReplicaUsed()

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.

Definition at line 2197 of file LoadBalancer.php.

◆ lastMasterChangeTimestamp()

Wikimedia\Rdbms\LoadBalancer::lastMasterChangeTimestamp ( )
Deprecated:
since 1.37; please use lastPrimaryChangeTimestamp() instead.
Returns
float|bool UNIX timestamp or false

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2150 of file LoadBalancer.php.

References wfDeprecated().

◆ lastPrimaryChangeTimestamp()

Wikimedia\Rdbms\LoadBalancer::lastPrimaryChangeTimestamp ( )

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

Returns
float|bool UNIX timestamp or false
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2141 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\lastDoneWrites().

◆ lazyLoadReplicationPositions()

Wikimedia\Rdbms\LoadBalancer::lazyLoadReplicationPositions ( )
private

Make sure that any "waitForPos" positions are loaded and available to doWait()

Definition at line 1487 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getReaderIndex().

◆ newTrackedConnectionsArray()

static Wikimedia\Rdbms\LoadBalancer::newTrackedConnectionsArray ( )
staticprivate

Definition at line 271 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\__construct().

◆ openConnection()

Wikimedia\Rdbms\LoadBalancer::openConnection (   $i,
  $domain = false,
  $flags = 0 
)
Parameters
int$i
string | bool$domain
int$flags
Returns
Database|bool Live database handle or false on failure
Deprecated:
Since 1.34 Use getConnection() instead

Definition at line 1150 of file LoadBalancer.php.

◆ pendingMasterChangeCallers()

Wikimedia\Rdbms\LoadBalancer::pendingMasterChangeCallers ( )
Deprecated:
since 1.37; please use pendingPrimaryChangeCallers() instead.
Returns
string[] List of method names

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2176 of file LoadBalancer.php.

References wfDeprecated().

◆ pendingPrimaryChangeCallers()

Wikimedia\Rdbms\LoadBalancer::pendingPrimaryChangeCallers ( )

Get the list of callers that have pending primary changes.

Returns
string[] List of method names
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2167 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\pendingWriteCallers().

◆ pickAnyOpenConnection()

Wikimedia\Rdbms\LoadBalancer::pickAnyOpenConnection ( array  $connsByServer,
  $autoCommitOnly 
)
private
Parameters
Database[][]$connsByServerMap of (server index => array of DB handles)
bool$autoCommitOnlyWhether to only look for auto-commit connections
Returns
IDatabase|false An appropriate open connection or false if none found

Definition at line 843 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\$conns, and Wikimedia\Rdbms\LoadBalancer\getConnLogContext().

Referenced by Wikimedia\Rdbms\LoadBalancer\getAnyOpenConnection().

◆ pickReaderIndex()

Wikimedia\Rdbms\LoadBalancer::pickReaderIndex ( array  $loads,
string  $domain 
)
private

Pick a server that is reachable, preferably non-lagged, and return its server index.

This will leave the server connection open within the pool for reuse

Parameters
array$loadsList of server weights
string$domainResolved DB domain
Returns
array (reader index, lagged replica mode) or (false, false) on failure

Definition at line 617 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\$laggedReplicaMode, Wikimedia\Rdbms\LoadBalancer\allowLagged(), Wikimedia\Rdbms\LoadBalancer\getRandomNonLagged(), Wikimedia\Rdbms\LoadBalancer\getServerConnection(), Wikimedia\Rdbms\LoadBalancer\getServerName(), ArrayUtils\pickRandom(), and Wikimedia\Rdbms\LoadBalancer\reuseConnection().

Referenced by Wikimedia\Rdbms\LoadBalancer\getReaderIndex().

◆ pingAll()

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

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2317 of file LoadBalancer.php.

References $success, and Wikimedia\Rdbms\IDatabase\ping().

◆ reallyOpenConnection()

Wikimedia\Rdbms\LoadBalancer::reallyOpenConnection (   $i,
DatabaseDomain  $domain,
array  $lbInfo 
)
protected

Open a new network connection to a server (uncached)

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

Parameters
int$iSpecific server index
DatabaseDomain$domainDomain the connection is for, possibly unspecified
array$lbInfoAdditional information for setLBInfo()
Returns
IDatabase
Exceptions
DBAccessError
InvalidArgumentException

Reimplemented in Wikimedia\Rdbms\LoadBalancerSingle.

Definition at line 1356 of file LoadBalancer.php.

References Wikimedia\Rdbms\DatabaseDomain\getDatabase(), Wikimedia\Rdbms\DatabaseDomain\getId(), Wikimedia\Rdbms\DatabaseDomain\getSchema(), and Wikimedia\Rdbms\DatabaseDomain\getTablePrefix().

◆ redefineLocalDomain()

Wikimedia\Rdbms\LoadBalancer::redefineLocalDomain (   $domain)

Close all connection and redefine the local domain for testing or schema creation.

Parameters
DatabaseDomain | string$domain
Since
1.33

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2552 of file LoadBalancer.php.

◆ reportConnectionError()

Wikimedia\Rdbms\LoadBalancer::reportConnectionError ( )
private
Exceptions
DBConnectionError
Returns
never

Definition at line 1499 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getConnectionIndex(), and Wikimedia\Rdbms\LoadBalancer\getServerConnection().

◆ resolveDomainID()

Wikimedia\Rdbms\LoadBalancer::resolveDomainID (   $domain)
Parameters
DatabaseDomain | string | bool$domainDatabase domain
Returns
string Value of $domain if it is foreign or the local domain otherwise
Since
1.32

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 299 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\resolveDomainInstance().

Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection(), Wikimedia\Rdbms\LoadBalancer\getConnectionRef(), and Wikimedia\Rdbms\LoadBalancer\getReaderIndex().

◆ resolveDomainInstance()

Wikimedia\Rdbms\LoadBalancer::resolveDomainInstance (   $domain)
finalprotected
Parameters
DatabaseDomain | string | bool$domain
Returns
DatabaseDomain

Definition at line 307 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\$localDomain, and Wikimedia\Rdbms\DatabaseDomain\newFromId().

Referenced by Wikimedia\Rdbms\LoadBalancer\resolveDomainID().

◆ resolveGroups()

Wikimedia\Rdbms\LoadBalancer::resolveGroups (   $groups,
  $i 
)
private

Resolve $groups into a list of query groups defining as having database servers.

Parameters
string[] | string | bool$groupsQuery group(s) in preference order, [], or false
int$iSpecific server index or DB_PRIMARY/DB_REPLICA
Returns
string[] Non-empty group list in preference order with the default group appended

Definition at line 335 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\$defaultGroup.

Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection().

◆ reuseConnection()

Wikimedia\Rdbms\LoadBalancer::reuseConnection ( IDatabase  $conn)

Mark a live handle as being available for reuse under a different database domain.

This mechanism is reference-counted, and must be called the same number of times as getConnection() to work. Never call this on handles acquired via getConnectionRef(), getLazyConnectionRef(), and getMaintenanceConnectionRef(), as they already manage the logic of calling this method when they fall out of scope in PHP.

See also
ILoadBalancer::getConnection()
Parameters
IDatabase$conn
Exceptions
LogicException

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1035 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\getDomainID(), Wikimedia\Rdbms\IDatabase\getLBInfo(), Wikimedia\Rdbms\LoadBalancer\KEY_FOREIGN_FREE, Wikimedia\Rdbms\LoadBalancer\KEY_FOREIGN_FREE_NOROUND, Wikimedia\Rdbms\LoadBalancer\KEY_FOREIGN_INUSE, and Wikimedia\Rdbms\LoadBalancer\KEY_FOREIGN_INUSE_NOROUND.

Referenced by Wikimedia\Rdbms\LoadBalancer\pickReaderIndex().

◆ rollbackMasterChanges()

Wikimedia\Rdbms\LoadBalancer::rollbackMasterChanges (   $fname = __METHOD__,
  $owner = null 
)
Deprecated:
since 1.37; please use rollbackPrimaryChanges() instead.
Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Exceptions
DBExpectedError

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2002 of file LoadBalancer.php.

References wfDeprecated().

◆ rollbackPrimaryChanges()

Wikimedia\Rdbms\LoadBalancer::rollbackPrimaryChanges (   $fname = __METHOD__,
  $owner = null 
)

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

Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Exceptions
DBExpectedError
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1980 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\rollback().

◆ runMasterTransactionIdleCallbacks()

Wikimedia\Rdbms\LoadBalancer::runMasterTransactionIdleCallbacks (   $fname = __METHOD__,
  $owner = null 
)
Deprecated:
since 1.37; please use runPrimaryTransactionIdleCallbacks() instead.
Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Returns
Exception|null The first exception or null if there were none

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1941 of file LoadBalancer.php.

References wfDeprecated().

◆ runMasterTransactionListenerCallbacks()

Wikimedia\Rdbms\LoadBalancer::runMasterTransactionListenerCallbacks (   $fname = __METHOD__,
  $owner = null 
)
Deprecated:
since 1.37; please use runPrimaryTransactionListenerCallbacks() instead.
Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Returns
Exception|null The first exception or null if there were none

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1975 of file LoadBalancer.php.

References wfDeprecated().

◆ runPrimaryTransactionIdleCallbacks()

Wikimedia\Rdbms\LoadBalancer::runPrimaryTransactionIdleCallbacks (   $fname = __METHOD__,
  $owner = null 
)

Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions.

Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Returns
Exception|null The first exception or null if there were none
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1869 of file LoadBalancer.php.

References $type, Wikimedia\Rdbms\Database\runOnTransactionIdleCallbacks(), Wikimedia\Rdbms\Database\setTrxEndCallbackSuppression(), Wikimedia\Rdbms\Database\trxLevel(), and Wikimedia\Rdbms\Database\writesPending().

◆ runPrimaryTransactionListenerCallbacks()

Wikimedia\Rdbms\LoadBalancer::runPrimaryTransactionListenerCallbacks (   $fname = __METHOD__,
  $owner = null 
)

Run all recurring post-COMMIT/ROLLBACK listener callbacks.

Parameters
string$fnameCaller name
int | null$ownerID of the calling instance (e.g. the LBFactory ID)
Returns
Exception|null The first exception or null if there were none
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 1946 of file LoadBalancer.php.

References $type, and Wikimedia\Rdbms\Database\runTransactionListenerCallbacks().

◆ safeGetLag()

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
Deprecated:
Since 1.34 Use IDatabase::getLag() instead

Definition at line 2438 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\getLag().

◆ sanitizeConnectionFlags()

Wikimedia\Rdbms\LoadBalancer::sanitizeConnectionFlags (   $flags,
  $i,
  $domain 
)
private
Parameters
int$flagsBitfield of class CONN_* constants
int$iSpecific server index or DB_PRIMARY/DB_REPLICA
string$domainDatabase domain
Returns
int Sanitized bitfield

Definition at line 364 of file LoadBalancer.php.

References $type, Wikimedia\Rdbms\ILoadBalancer\CONN_INTENT_WRITABLE, Wikimedia\Rdbms\ILoadBalancer\CONN_TRX_AUTOCOMMIT, Wikimedia\Rdbms\LoadBalancer\getServerAttributes(), Wikimedia\Rdbms\LoadBalancer\getServerType(), and Wikimedia\Rdbms\LoadBalancer\getWriterIndex().

Referenced by Wikimedia\Rdbms\LoadBalancer\getConnection().

◆ serverHasLoadInAnyGroup()

Wikimedia\Rdbms\LoadBalancer::serverHasLoadInAnyGroup (   $i)
private
Parameters
int$iSpecific server index
Returns
bool

Definition at line 783 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\waitForAll().

◆ setDomainAliases()

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

Convert certain database domains to alternative ones.

This can be used for backwards compatibility logic.

Parameters
DatabaseDomain[] | string[]$aliasesMap of (domain alias => domain)
Since
1.35

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2516 of file LoadBalancer.php.

◆ setExistingReaderIndex()

Wikimedia\Rdbms\LoadBalancer::setExistingReaderIndex (   $group,
  $index 
)
private

Set the server index chosen by the load balancer for use with the given query group.

Parameters
string$groupQuery group; use false for the generic group
int$indexThe index of a specific server

Definition at line 601 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getReaderIndex().

◆ setIndexAliases()

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
Since
1.31

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2512 of file LoadBalancer.php.

◆ setLocalDomain()

Wikimedia\Rdbms\LoadBalancer::setLocalDomain ( DatabaseDomain  $domain)
private
Parameters
DatabaseDomain$domain

Definition at line 2572 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\__construct().

◆ setLocalDomainPrefix()

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

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

Parameters
string$prefix
Since
1.33

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2520 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\getLBInfo().

◆ setTableAliases()

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[]$aliasesMap of (table => (dbname, schema, prefix) map)

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2508 of file LoadBalancer.php.

◆ setTempTablesOnlyMode()

Wikimedia\Rdbms\LoadBalancer::setTempTablesOnlyMode (   $value,
  $domain 
)

Indicate whether the tables on this domain are only temporary tables for testing.

In "temporary tables mode", the ILoadBalancer::CONN_TRX_AUTOCOMMIT flag is ignored

Parameters
bool$value
string$domain
Returns
bool Whether "temporary tables mode" was active
Since
1.34

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2558 of file LoadBalancer.php.

◆ setTransactionListener()

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

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

Parameters
string$nameCallback name
callable | null$callback

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2495 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\setTransactionListener().

◆ setWaitForPositionIfHigher()

Wikimedia\Rdbms\LoadBalancer::setWaitForPositionIfHigher (   $pos)
private
Parameters
DBPrimaryPos | bool$pos

Definition at line 796 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\waitFor().

◆ undoTransactionRoundFlags()

Wikimedia\Rdbms\LoadBalancer::undoTransactionRoundFlags ( Database  $conn)
private

◆ waitFor()

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

Set the primary position to reach before the next generic group DB handle query.

If a generic replica DB connection is already open then this immediately waits for that DB to catch up to the specified replication position. Otherwise, it will do so once such a connection is opened.

If a timeout happens when waiting, then getLaggedReplicaMode()/laggedReplicaUsed() will return true. This is useful for discouraging clients from taking further actions if session consistency could not be maintained with respect to their last actions.

Parameters
DBPrimaryPos | bool$posPrimary position or false

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 705 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\$waitForPos, Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getExistingReaderIndex(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), and Wikimedia\Rdbms\LoadBalancer\setWaitForPositionIfHigher().

◆ waitForAll()

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

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

This method is only intented for use a throttling mechanism for high-volume updates. Unlike waitFor(), failure does not effect getLaggedReplicaMode()/laggedReplicaUsed().

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

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 753 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\$waitForPos, Wikimedia\Rdbms\LoadBalancer\$waitTimeout, Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getStreamingReplicaIndexes(), and Wikimedia\Rdbms\LoadBalancer\serverHasLoadInAnyGroup().

◆ waitForMasterPos()

Wikimedia\Rdbms\LoadBalancer::waitForMasterPos ( IDatabase  $conn,
  $pos = false,
  $timeout = null 
)
Deprecated:
since 1.37; please use waitForPrimaryPos() instead.
Parameters
IDatabase$connReplica DB
DBPrimaryPos | bool$posPrimary position; default: current position
int$timeoutTimeout in seconds [optional]
Returns
bool Success
Since
1.34

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2490 of file LoadBalancer.php.

References wfDeprecated().

◆ waitForOne()

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

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

This method is only intented for use a throttling mechanism for high-volume updates. Unlike waitFor(), failure does not effect getLaggedReplicaMode()/laggedReplicaUsed().

This can be used a faster proxy for waitForAll()

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

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 723 of file LoadBalancer.php.

References Wikimedia\Rdbms\LoadBalancer\$waitForPos, Wikimedia\Rdbms\LoadBalancer\doWait(), Wikimedia\Rdbms\LoadBalancer\getExistingReaderIndex(), Wikimedia\Rdbms\LoadBalancer\getWriterIndex(), Wikimedia\Rdbms\ILoadBalancer\GROUP_GENERIC, and ArrayUtils\pickRandom().

◆ waitForPrimaryPos()

Wikimedia\Rdbms\LoadBalancer::waitForPrimaryPos ( IDatabase  $conn,
  $pos = false,
  $timeout = null 
)

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

If $conn is not a replica server connection, then this will return true. Otherwise, if $pos is not provided, this will connect to the primary server to get an accurate position.

Parameters
IDatabase$connReplica DB
DBPrimaryPos | bool$posPrimary position; default: current position
int$timeoutTimeout in seconds [optional]
Returns
bool Success
Since
1.37

Implements Wikimedia\Rdbms\ILoadBalancer.

Definition at line 2442 of file LoadBalancer.php.

References Wikimedia\Rdbms\IDatabase\getLBInfo(), and Wikimedia\Rdbms\IDatabase\primaryPosWait().

Member Data Documentation

◆ $agent

string Wikimedia\Rdbms\LoadBalancer::$agent
private

Agent name for query profiling.

Definition at line 100 of file LoadBalancer.php.

◆ $allowLagged

bool Wikimedia\Rdbms\LoadBalancer::$allowLagged = false
private

Whether to disregard replica DB lag as a factor in replica DB selection.

Definition at line 124 of file LoadBalancer.php.

◆ $chronologyCallback

callable null Wikimedia\Rdbms\LoadBalancer::$chronologyCallback
private

Callback to run before the first connection attempt.

Definition at line 49 of file LoadBalancer.php.

◆ $chronologyCallbackTriggered

bool Wikimedia\Rdbms\LoadBalancer::$chronologyCallbackTriggered = false
private

Whether the session consistency callback already executed.

Definition at line 136 of file LoadBalancer.php.

◆ $cliMode

bool Wikimedia\Rdbms\LoadBalancer::$cliMode
private

Whether this PHP instance is for a CLI script.

Definition at line 98 of file LoadBalancer.php.

◆ $clusterName

string null Wikimedia\Rdbms\LoadBalancer::$clusterName
private

The name of the DB cluster.

Definition at line 81 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getClusterName().

◆ $connectionCounter

int Wikimedia\Rdbms\LoadBalancer::$connectionCounter = 0
private

Total number of new connections ever made with this instance.

Definition at line 132 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getServerConnection().

◆ $connLogger

LoggerInterface Wikimedia\Rdbms\LoadBalancer::$connLogger
private

Definition at line 62 of file LoadBalancer.php.

◆ $conns

IDatabase [][][] Wikimedia\Rdbms\LoadBalancer::$conns
private

Map of (pool category => server index => domain => IDatabase)

Definition at line 78 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\pickAnyOpenConnection().

◆ $csProvider

CriticalSectionProvider null Wikimedia\Rdbms\LoadBalancer::$csProvider
private

Definition at line 47 of file LoadBalancer.php.

◆ $defaultGroup

string null Wikimedia\Rdbms\LoadBalancer::$defaultGroup
private

Default query group to use with getConnection()

Definition at line 95 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\resolveGroups().

◆ $deprecationLogger

callable Wikimedia\Rdbms\LoadBalancer::$deprecationLogger
private

Deprecation logger.

Definition at line 72 of file LoadBalancer.php.

◆ $disabled

bool Wikimedia\Rdbms\LoadBalancer::$disabled = false
private

Definition at line 134 of file LoadBalancer.php.

◆ $domainAliases

DatabaseDomain [] string [] Wikimedia\Rdbms\LoadBalancer::$domainAliases = []
private

Map of (domain alias => DB domain)

Definition at line 107 of file LoadBalancer.php.

◆ $errorConnection

Database Wikimedia\Rdbms\LoadBalancer::$errorConnection
private

Connection handle that caused a problem.

Definition at line 118 of file LoadBalancer.php.

◆ $errorLogger

callable Wikimedia\Rdbms\LoadBalancer::$errorLogger
private

Exception logger.

Definition at line 70 of file LoadBalancer.php.

◆ $groupLoads

array [] Wikimedia\Rdbms\LoadBalancer::$groupLoads
private

Map of (group => server index => weight)

Definition at line 85 of file LoadBalancer.php.

◆ $id

Wikimedia\Rdbms\LoadBalancer::$id
private

var int An identifier for this class instance

Definition at line 139 of file LoadBalancer.php.

◆ $indexAliases

string [] Wikimedia\Rdbms\LoadBalancer::$indexAliases = []
private

Map of (index alias => index)

Definition at line 105 of file LoadBalancer.php.

◆ $laggedReplicaMode

bool Wikimedia\Rdbms\LoadBalancer::$laggedReplicaMode = false
private

Whether the generic reader fell back to a lagged replica DB.

Definition at line 126 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getReaderIndex(), and Wikimedia\Rdbms\LoadBalancer\pickReaderIndex().

◆ $lastError

string Wikimedia\Rdbms\LoadBalancer::$lastError = 'Unknown error'
private

The last DB selection or connection error.

Definition at line 128 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getConnectionIndex().

◆ $loadMonitor

ILoadMonitor Wikimedia\Rdbms\LoadBalancer::$loadMonitor
private

Definition at line 45 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getLoadMonitor().

◆ $loadMonitorConfig

array Wikimedia\Rdbms\LoadBalancer::$loadMonitorConfig
private

The LoadMonitor configuration.

Definition at line 91 of file LoadBalancer.php.

◆ $localDomain

DatabaseDomain Wikimedia\Rdbms\LoadBalancer::$localDomain
private

Local DB domain ID and default for selectDB() calls.

Definition at line 75 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\__construct(), and Wikimedia\Rdbms\LoadBalancer\resolveDomainInstance().

◆ $maxLag

int Wikimedia\Rdbms\LoadBalancer::$maxLag
private

◆ $maxLagByIndex

int [] Wikimedia\Rdbms\LoadBalancer::$maxLagByIndex
private

Map of (server index => seconds of lag considered "high")

Definition at line 87 of file LoadBalancer.php.

◆ $nonLocalDomainCache

DatabaseDomain [] Wikimedia\Rdbms\LoadBalancer::$nonLocalDomainCache = []
private

Map of (domain ID => domain instance)

Definition at line 144 of file LoadBalancer.php.

◆ $ownerId

int null Wikimedia\Rdbms\LoadBalancer::$ownerId
private

Integer ID of the managing LBFactory instance or null if none.

Definition at line 141 of file LoadBalancer.php.

◆ $perfLogger

LoggerInterface Wikimedia\Rdbms\LoadBalancer::$perfLogger
private

Definition at line 68 of file LoadBalancer.php.

◆ $profiler

callable null Wikimedia\Rdbms\LoadBalancer::$profiler
private

An optional callback that returns a ScopedCallback instance, meant to profile the actual query execution in {.

See also
Database::doQuery}

Definition at line 58 of file LoadBalancer.php.

◆ $queryLogger

LoggerInterface Wikimedia\Rdbms\LoadBalancer::$queryLogger
private

Definition at line 64 of file LoadBalancer.php.

◆ $readIndexByGroup

int [] Wikimedia\Rdbms\LoadBalancer::$readIndexByGroup = []
private

The group replica server indexes keyed by group.

Definition at line 120 of file LoadBalancer.php.

◆ $readOnlyReason

string bool Wikimedia\Rdbms\LoadBalancer::$readOnlyReason = false
private

Reason this instance is read-only or false if not.

Definition at line 130 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\getServerConnection().

◆ $replLogger

LoggerInterface Wikimedia\Rdbms\LoadBalancer::$replLogger
private

Definition at line 66 of file LoadBalancer.php.

◆ $servers

array [] Wikimedia\Rdbms\LoadBalancer::$servers
private

Map of (server index => server config array)

Definition at line 83 of file LoadBalancer.php.

◆ $srvCache

BagOStuff Wikimedia\Rdbms\LoadBalancer::$srvCache
private

Definition at line 51 of file LoadBalancer.php.

◆ $tableAliases

array [] Wikimedia\Rdbms\LoadBalancer::$tableAliases = []
private

$aliases Map of (table => (dbname, schema, prefix) map)

Definition at line 103 of file LoadBalancer.php.

◆ $tempTablesOnlyMode

bool [] Wikimedia\Rdbms\LoadBalancer::$tempTablesOnlyMode = []
private

Map of (domain => whether to use "temp tables only" mode)

Definition at line 111 of file LoadBalancer.php.

◆ $trxProfiler

TransactionProfiler Wikimedia\Rdbms\LoadBalancer::$trxProfiler
private

Definition at line 60 of file LoadBalancer.php.

◆ $trxRecurringCallbacks

callable [] Wikimedia\Rdbms\LoadBalancer::$trxRecurringCallbacks = []
private

Map of (name => callable)

Definition at line 109 of file LoadBalancer.php.

◆ $trxRoundId

string bool Wikimedia\Rdbms\LoadBalancer::$trxRoundId = false
private

Explicit DBO_TRX transaction round active or false if none.

Definition at line 114 of file LoadBalancer.php.

◆ $trxRoundStage

string Wikimedia\Rdbms\LoadBalancer::$trxRoundStage = self::ROUND_CURSORY
private

Stage of the current transaction round in the transaction round life-cycle.

Definition at line 116 of file LoadBalancer.php.

◆ $waitForPos

bool DBPrimaryPos Wikimedia\Rdbms\LoadBalancer::$waitForPos
private

Replication sync position or false if not set.

Definition at line 122 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\waitFor(), Wikimedia\Rdbms\LoadBalancer\waitForAll(), and Wikimedia\Rdbms\LoadBalancer\waitForOne().

◆ $waitTimeout

int Wikimedia\Rdbms\LoadBalancer::$waitTimeout
private

Seconds to spend waiting on replica DB lag to resolve.

Definition at line 89 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\doWait(), and Wikimedia\Rdbms\LoadBalancer\waitForAll().

◆ $wanCache

WANObjectCache Wikimedia\Rdbms\LoadBalancer::$wanCache
private

Definition at line 53 of file LoadBalancer.php.

◆ CONN_HELD_WARN_THRESHOLD

const Wikimedia\Rdbms\LoadBalancer::CONN_HELD_WARN_THRESHOLD = 10
private

Warn when this many connection are held.

Definition at line 158 of file LoadBalancer.php.

◆ INFO_AUTOCOMMIT_ONLY

const Wikimedia\Rdbms\LoadBalancer::INFO_AUTOCOMMIT_ONLY = 'autoCommitOnly'
private

Definition at line 147 of file LoadBalancer.php.

◆ INFO_FOREIGN_REF_COUNT

const Wikimedia\Rdbms\LoadBalancer::INFO_FOREIGN_REF_COUNT = 'foreignPoolRefCount'
private

Definition at line 149 of file LoadBalancer.php.

◆ INFO_FORIEGN

const Wikimedia\Rdbms\LoadBalancer::INFO_FORIEGN = 'foreign'
private

Definition at line 148 of file LoadBalancer.php.

◆ INFO_SERVER_INDEX

const Wikimedia\Rdbms\LoadBalancer::INFO_SERVER_INDEX = 'serverIndex'
private

Definition at line 146 of file LoadBalancer.php.

◆ KEY_FOREIGN_FREE

const Wikimedia\Rdbms\LoadBalancer::KEY_FOREIGN_FREE = 'foreignFree'
private

Definition at line 166 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\reuseConnection().

◆ KEY_FOREIGN_FREE_NOROUND

const Wikimedia\Rdbms\LoadBalancer::KEY_FOREIGN_FREE_NOROUND = 'foreignFreeAutoCommit'
private

Definition at line 170 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\reuseConnection().

◆ KEY_FOREIGN_INUSE

const Wikimedia\Rdbms\LoadBalancer::KEY_FOREIGN_INUSE = 'foreignInUse'
private

Definition at line 167 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\reuseConnection().

◆ KEY_FOREIGN_INUSE_NOROUND

const Wikimedia\Rdbms\LoadBalancer::KEY_FOREIGN_INUSE_NOROUND = 'foreignInUseAutoCommit'
private

Definition at line 171 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\reuseConnection().

◆ KEY_LOCAL

const Wikimedia\Rdbms\LoadBalancer::KEY_LOCAL = 'local'
private

Definition at line 165 of file LoadBalancer.php.

◆ KEY_LOCAL_DOMAIN

const Wikimedia\Rdbms\LoadBalancer::KEY_LOCAL_DOMAIN = '__local__'
private

Definition at line 173 of file LoadBalancer.php.

◆ KEY_LOCAL_NOROUND

const Wikimedia\Rdbms\LoadBalancer::KEY_LOCAL_NOROUND = 'localAutoCommit'
private

Definition at line 169 of file LoadBalancer.php.

◆ MAX_LAG_DEFAULT

const Wikimedia\Rdbms\LoadBalancer::MAX_LAG_DEFAULT = 6

Default 'maxLag' when unspecified.

Access: internal
Only for use within LoadBalancer/LoadMonitor

Definition at line 155 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\__construct(), and Wikimedia\Rdbms\LoadMonitor\__construct().

◆ MAX_WAIT_DEFAULT

const Wikimedia\Rdbms\LoadBalancer::MAX_WAIT_DEFAULT = 10
private

Default 'waitTimeout' when unspecified.

Definition at line 161 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\__construct().

◆ ROUND_APPROVED

const Wikimedia\Rdbms\LoadBalancer::ROUND_APPROVED = 'approved'
private

Transaction round passed final pre-commit checks.

Definition at line 180 of file LoadBalancer.php.

◆ ROUND_COMMIT_CALLBACKS

const Wikimedia\Rdbms\LoadBalancer::ROUND_COMMIT_CALLBACKS = 'commit-callbacks'
private

Transaction round was committed and post-commit callbacks must be run.

Definition at line 182 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\__construct().

◆ ROUND_CURSORY

const Wikimedia\Rdbms\LoadBalancer::ROUND_CURSORY = 'cursory'
private

Transaction round, explicit or implicit, has not finished writing.

Definition at line 176 of file LoadBalancer.php.

◆ ROUND_ERROR

const Wikimedia\Rdbms\LoadBalancer::ROUND_ERROR = 'error'
private

Transaction round encountered an error.

Definition at line 186 of file LoadBalancer.php.

◆ ROUND_FINALIZED

const Wikimedia\Rdbms\LoadBalancer::ROUND_FINALIZED = 'finalized'
private

Transaction round writes are complete and ready for pre-commit checks.

Definition at line 178 of file LoadBalancer.php.

◆ ROUND_ROLLBACK_CALLBACKS

const Wikimedia\Rdbms\LoadBalancer::ROUND_ROLLBACK_CALLBACKS = 'rollback-callbacks'
private

Transaction round was rolled back and post-rollback callbacks must be run.

Definition at line 184 of file LoadBalancer.php.

Referenced by Wikimedia\Rdbms\LoadBalancer\__construct().

◆ TTL_CACHE_READONLY

const Wikimedia\Rdbms\LoadBalancer::TTL_CACHE_READONLY = 5
private

Seconds to cache primary DB server read-only status.

Definition at line 163 of file LoadBalancer.php.


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