MediaWiki master
Wikimedia\Rdbms\ILoadBalancerForOwner Interface Reference

Internal interface for load balancer instances exposed to their owner. More...

Inherits Wikimedia\Rdbms\ILoadBalancer.

Inherited by Wikimedia\Rdbms\LoadBalancer.

Collaboration diagram for Wikimedia\Rdbms\ILoadBalancerForOwner:

Public Member Functions

 __construct (array $params)
 
 approvePrimaryChanges (int $maxWriteDuration, $fname=__METHOD__)
 Perform all pre-commit checks for things like replication safety.
 
 beginPrimaryChanges ( $fname=__METHOD__)
 Flush any primary transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set)
 
 closeAll ( $fname=__METHOD__)
 Close all open connections.
 
 commitPrimaryChanges ( $fname=__METHOD__)
 Issue COMMIT on all open primary connections to flush changes and view snapshots.
 
 disable ( $fname=__METHOD__)
 Close all connections and disable this load balancer.
 
 finalizePrimaryChanges ( $fname=__METHOD__)
 Run pre-commit callbacks and defer execution of post-commit callbacks.
 
 flushPrimarySessions ( $fname=__METHOD__)
 Release/destroy session-level named locks, table locks, and temp tables.
 
 flushPrimarySnapshots ( $fname=__METHOD__)
 Commit all primary DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
 
 flushReplicaSnapshots ( $fname=__METHOD__)
 Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshots.
 
 hasPrimaryConnection ()
 
 laggedReplicaUsed ()
 Whether a highly "lagged" replica database connection was queried.
 
 lastPrimaryChangeTimestamp ()
 Get the last time that a tracked connection was used to commit a write.
 
 pendingPrimaryChangeCallers ()
 Get the list of callers that have pending primary changes.
 
 reconfigure (array $conf)
 Reconfigure using the given config array.
 
 redefineLocalDomain ( $domain)
 Close all connection and redefine the local domain for testing or schema creation.
 
 rollbackPrimaryChanges ( $fname=__METHOD__)
 Issue ROLLBACK only on primary, only if queries were done on connection.
 
 runPrimaryTransactionIdleCallbacks ( $fname=__METHOD__)
 Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions.
 
 runPrimaryTransactionListenerCallbacks ( $fname=__METHOD__)
 Run all recurring post-COMMIT/ROLLBACK listener callbacks.
 
 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.
 
 waitForAll (DBPrimaryPos $pos, $timeout=null)
 Set the primary wait position and wait for ALL replica DBs to catch up to it.
 
- Public Member Functions inherited from Wikimedia\Rdbms\ILoadBalancer
 explicitTrxActive ()
 Determine whether an explicit transaction is active on any open primary connection.
 
 getClusterName ()
 Get the name of the overall cluster of database servers managing the dataset.
 
 getConnection ( $i, $groups=[], $domain=false, $flags=0)
 Get a lazy-connecting database handle for a specific or virtual (DB_PRIMARY/DB_REPLICA) server index.
 
 getConnectionInternal ( $i, $groups=[], $domain=false, $flags=0)
 
 getConnectionRef ( $i, $groups=[], $domain=false, $flags=0)
 
 getLagTimes ()
 Get an estimate of replication lag (in seconds) for each server.
 
 getLocalDomainID ()
 Get the local (and default) database domain ID of connection handles.
 
 getMaintenanceConnectionRef ( $i, $groups=[], $domain=false, $flags=0)
 Get a DB handle, suitable for migrations and schema changes, for a server index.
 
 getMaxLag ()
 Get the name and lag time of the most-lagged replica server.
 
 getPrimaryPos ()
 Get the current primary replication position.
 
 getReaderIndex ( $group=false)
 Get the specific server index of the reader connection for a given group.
 
 getReadOnlyReason ()
 
 getServerAttributes ( $i)
 Get basic attributes of the server with the specified index without connecting.
 
 getServerConnection ( $i, $domain, $flags=0)
 Get a DB 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.
 
 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.
 
 hasReplicaServers ()
 Whether there are any replica servers configured.
 
 hasStreamingReplicaServers ()
 Whether any replica servers use streaming replication from the primary server.
 
 pingAll ()
 
 resolveDomainID ( $domain)
 
 setDomainAliases (array $aliases)
 Convert certain database domains to alternative ones.
 
 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.
 
 waitForPrimaryPos (IDatabase $conn)
 Wait for a replica DB to reach a specified primary position.
 

Public Attributes

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.
 
- Public Attributes inherited from Wikimedia\Rdbms\ILoadBalancer
const CONN_SILENCE_ERRORS = 4
 Yield null on connection failure instead of throwing an exception.
 
const CONN_TRX_AUTOCOMMIT = 1
 Yield a tracked autocommit-mode handle (reuse existing ones)
 
const CONN_UNTRACKED_GAUGE = 2
 Yield an untracked, low-timeout, autocommit-mode handle (to gauge server health)
 
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.
 

Detailed Description

Internal interface for load balancer instances exposed to their owner.

Instances are either owned by an LBFactory object or owned by the caller that created the instance using a constructor/factory function such as LBFactory::newMain().

Access: internal
Only for use within LBFactory/LoadMonitor/ChronologyProtector
Since
1.39

Definition at line 34 of file ILoadBalancerForOwner.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Rdbms\ILoadBalancerForOwner::__construct ( array $params)
Parameters
array$paramsParameter map with keys:
  • servers : List of server configuration maps, starting with either the global master or local datacenter multi-master, and optionally followed by local datacenter replicas. Each server configuration map has the same format as the Database::factory() $params argument, with the following additional optional fields:
    • type: the DB type (sqlite, mysql, postgres,...)
    • groupLoads: map of (group => weight for this server) [optional]
    • max lag: per-server override of the "max lag" [optional]
    • is static: whether the dataset is static and this server has a copy [optional]
  • localDomain: A DatabaseDomain or domain ID string
  • loadMonitor : LoadMonitor::__construct() parameters with "class" field [optional]
  • readOnlyReason : Reason the primary server is read-only (false if not) [optional]
  • srvCache : BagOStuff object for server cache [optional]
  • wanCache : WANObjectCache object [optional]
  • databaseFactory: DatabaseFactory object [optional]
  • chronologyProtector: ChronologyProtector object [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 : Callback that takes a section name argument and returns a ScopedCallback instance that ends the profile section in its destructor [optional]
  • trxProfiler: TransactionProfiler instance [optional]
  • logger: 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]
  • clusterName: The name of the overall (single/multi-datacenter) cluster of servers managing the dataset, regardless of 'servers' excluding replicas and multi-masters from remote datacenter [optional]
  • criticalSectionProvider: CriticalSectionProvider instance [optional]

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

Member Function Documentation

◆ approvePrimaryChanges()

Wikimedia\Rdbms\ILoadBalancerForOwner::approvePrimaryChanges ( int $maxWriteDuration,
$fname = __METHOD__ )

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

Use this only for multi-database commits

Parameters
int$maxWriteDuration: max write query duration time in seconds
string$fnameCaller name
Exceptions
DBTransactionError
Since
1.37

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ beginPrimaryChanges()

Wikimedia\Rdbms\ILoadBalancerForOwner::beginPrimaryChanges ( $fname = __METHOD__)

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() This allows for custom transaction rounds from any outer transaction scope.
Parameters
string$fnameCaller name
Exceptions
DBExpectedError
Since
1.37

Implemented in Wikimedia\Rdbms\LoadBalancer.

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

◆ closeAll()

Wikimedia\Rdbms\ILoadBalancerForOwner::closeAll ( $fname = __METHOD__)

Close all open connections.

Parameters
string$fnameCaller name

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ commitPrimaryChanges()

Wikimedia\Rdbms\ILoadBalancerForOwner::commitPrimaryChanges ( $fname = __METHOD__)

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

Parameters
string$fnameCaller name
Exceptions
DBExpectedError
Since
1.37

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ disable()

Wikimedia\Rdbms\ILoadBalancerForOwner::disable ( $fname = __METHOD__)

Close all connections and disable this load balancer.

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

Parameters
string$fnameCaller name

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ finalizePrimaryChanges()

Wikimedia\Rdbms\ILoadBalancerForOwner::finalizePrimaryChanges ( $fname = __METHOD__)

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

Use this only for multi-database commits

Parameters
string$fnameCaller name
Returns
int Number of pre-commit callbacks run (since 1.32)
Since
1.37

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ flushPrimarySessions()

Wikimedia\Rdbms\ILoadBalancerForOwner::flushPrimarySessions ( $fname = __METHOD__)

Release/destroy session-level named locks, table locks, and temp tables.

Only call this function right after calling rollbackPrimaryChanges()

Parameters
string$fnameCaller name
Exceptions
DBExpectedError
Since
1.38

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ flushPrimarySnapshots()

Wikimedia\Rdbms\ILoadBalancerForOwner::flushPrimarySnapshots ( $fname = __METHOD__)

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

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ flushReplicaSnapshots()

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

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

Parameters
string$fnameCaller name

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ hasPrimaryConnection()

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

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ laggedReplicaUsed()

Wikimedia\Rdbms\ILoadBalancerForOwner::laggedReplicaUsed ( )

Whether a highly "lagged" replica database connection was queried.

Note
This method will never cause a new DB connection
Returns
bool

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ lastPrimaryChangeTimestamp()

Wikimedia\Rdbms\ILoadBalancerForOwner::lastPrimaryChangeTimestamp ( )

Get the last time that a tracked connection was used to commit a write.

Access: internal
Should only be called from the rdbms library.
Returns
float|null UNIX timestamp, or, false (if no writes were committed)
Since
1.37

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ pendingPrimaryChangeCallers()

Wikimedia\Rdbms\ILoadBalancerForOwner::pendingPrimaryChangeCallers ( )

Get the list of callers that have pending primary changes.

Returns
string[] List of method names
Since
1.37

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ reconfigure()

Wikimedia\Rdbms\ILoadBalancerForOwner::reconfigure ( array $conf)

Reconfigure using the given config array.

If the config changed, this invalidates all existing connections.

Warning
This must only be called in top level code, typically via LBFactory::reconfigure.
Since
1.39
Parameters
array$confA configuration array, using the same structure as the one passed to the LoadBalancer's constructor.

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ redefineLocalDomain()

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

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

Parameters
DatabaseDomain | string$domain
Since
1.33

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ rollbackPrimaryChanges()

Wikimedia\Rdbms\ILoadBalancerForOwner::rollbackPrimaryChanges ( $fname = __METHOD__)

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

Parameters
string$fnameCaller name
Exceptions
DBExpectedError
Since
1.37

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ runPrimaryTransactionIdleCallbacks()

Wikimedia\Rdbms\ILoadBalancerForOwner::runPrimaryTransactionIdleCallbacks ( $fname = __METHOD__)

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

Parameters
string$fnameCaller name
Returns
Exception|null The first exception or null if there were none
Since
1.37

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ runPrimaryTransactionListenerCallbacks()

Wikimedia\Rdbms\ILoadBalancerForOwner::runPrimaryTransactionListenerCallbacks ( $fname = __METHOD__)

Run all recurring post-COMMIT/ROLLBACK listener callbacks.

Parameters
string$fnameCaller name
Returns
Exception|null The first exception or null if there were none
Since
1.37

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ setIndexAliases()

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

Implemented in Wikimedia\Rdbms\LoadBalancer.

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

◆ setLocalDomainPrefix()

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

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

Parameters
string$prefix
Since
1.33

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ waitForAll()

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

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

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

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

Implemented in Wikimedia\Rdbms\LoadBalancer.

Member Data Documentation

◆ STAGE_POSTCOMMIT_CALLBACKS

const Wikimedia\Rdbms\ILoadBalancerForOwner::STAGE_POSTCOMMIT_CALLBACKS = 'stage-postcommit-callbacks'

Manager of ILoadBalancer instances is running post-commit callbacks.

Definition at line 36 of file ILoadBalancerForOwner.php.

◆ STAGE_POSTROLLBACK_CALLBACKS

const Wikimedia\Rdbms\ILoadBalancerForOwner::STAGE_POSTROLLBACK_CALLBACKS = 'stage-postrollback-callbacks'

Manager of ILoadBalancer instances is running post-rollback callbacks.

Definition at line 38 of file ILoadBalancerForOwner.php.


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