MediaWiki  master
Wikimedia\Rdbms\ILoadBalancerForOwner Interface Reference

Interface for internal LoadBalancer methods, suitable for use on untracked objects returned by newMainLB() or for internal use by LBFactory. More...

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

Public Member Functions

 __construct (array $params)
 Construct a manager of IDatabase connection objects. More...
 
 approvePrimaryChanges (array $options, $fname=__METHOD__)
 Perform all pre-commit checks for things like replication safety. More...
 
 beginPrimaryChanges ( $fname=__METHOD__)
 Flush any primary transaction snapshots and set DBO_TRX (if DBO_DEFAULT is set) More...
 
 closeAll ( $fname=__METHOD__)
 Close all open connections. More...
 
 commitAll ( $fname=__METHOD__)
 Commit transactions on all open connections. More...
 
 commitPrimaryChanges ( $fname=__METHOD__)
 Issue COMMIT on all open primary connections to flush changes and view snapshots. More...
 
 disable ( $fname=__METHOD__)
 Close all connections and disable this load balancer. More...
 
 finalizePrimaryChanges ( $fname=__METHOD__)
 Run pre-commit callbacks and defer execution of post-commit callbacks. More...
 
 flushPrimarySessions ( $fname=__METHOD__)
 Release/destroy session-level named locks, table locks, and temp tables. More...
 
 flushPrimarySnapshots ( $fname=__METHOD__)
 Commit all primary DB transactions so as to flush any REPEATABLE-READ or SSI snapshots. More...
 
 flushReplicaSnapshots ( $fname=__METHOD__)
 Commit all replica DB transactions so as to flush any REPEATABLE-READ or SSI snapshots. More...
 
 forEachOpenConnection ( $callback, array $params=[])
 Call a function with each open connection object. More...
 
 forEachOpenPrimaryConnection ( $callback, array $params=[])
 Call a function with each open connection object to a primary. More...
 
 pendingPrimaryChangeCallers ()
 Get the list of callers that have pending primary changes. More...
 
 rollbackPrimaryChanges ( $fname=__METHOD__)
 Issue ROLLBACK only on primary, only if queries were done on connection. More...
 
 runPrimaryTransactionIdleCallbacks ( $fname=__METHOD__)
 Consume and run all pending post-COMMIT/ROLLBACK callbacks and commit dangling transactions. More...
 
 runPrimaryTransactionListenerCallbacks ( $fname=__METHOD__)
 Run all recurring post-COMMIT/ROLLBACK listener callbacks. More...
 
 setLocalDomainPrefix ( $prefix)
 Set a new table prefix for the existing local domain ID for testing. More...
 
- Public Member Functions inherited from Wikimedia\Rdbms\ILoadBalancer
 closeConnection (IDatabase $conn)
 Close a connection. More...
 
 explicitTrxActive ()
 Determine whether an explicit transaction is active on any open primary connection. More...
 
 getAnyOpenConnection ( $i, $flags=0)
 Get an existing live handle to the given server index (on any domain) More...
 
 getClusterName ()
 Get the logical name of the database cluster. More...
 
 getConnection ( $i, $groups=[], $domain=false, $flags=0)
 Get a lazy handle for a specific or virtual (DB_PRIMARY/DB_REPLICA) server index. More...
 
 getConnectionInternal ( $i, $groups=[], $domain=false, $flags=0)
 
 getConnectionRef ( $i, $groups=[], $domain=false, $flags=0)
 
 getLaggedReplicaMode ( $domain=false)
 
 getLagTimes ( $domain=false)
 Get an estimate of replication lag (in seconds) for each server. More...
 
 getLazyConnectionRef ( $i, $groups=[], $domain=false, $flags=0)
 Get a lazy-connecting database handle reference for a server index. More...
 
 getLocalDomainID ()
 Get the local (and default) database domain ID of connection handles. More...
 
 getMaintenanceConnectionRef ( $i, $groups=[], $domain=false, $flags=0)
 Get a live database handle, suitable for migrations and schema changes, for a server index. More...
 
 getMaxLag ( $domain=false)
 Get the name and lag time of the most-lagged replica server. More...
 
 getPrimaryPos ()
 Get the current primary replication position. More...
 
 getReaderIndex ( $group=false, $domain=false)
 Get the specific server index of the reader connection for a given group. More...
 
 getReadOnlyReason ( $domain=false)
 
 getReplicaResumePos ()
 Get the highest DB replication position for chronology control purposes. More...
 
 getServerAttributes ( $i)
 Get basic attributes of the server with the specified index without connecting. More...
 
 getServerConnection ( $i, $domain, $flags=0)
 Get a live handle for a specific server index. More...
 
 getServerCount ()
 Get the number of servers defined in configuration. More...
 
 getServerInfo ( $i)
 Return the server configuration map for the server with the specified index. More...
 
 getServerName ( $i)
 Get the readable name of the server with the specified index. More...
 
 getServerType ( $i)
 Get the RDBMS type of the server with the specified index (e.g. More...
 
 getWriterIndex ()
 Get the specific server index of the primary server. More...
 
 hasOrMadeRecentPrimaryChanges ( $age=null)
 Check if this load balancer object had any recent or still pending writes issued against it by this PHP thread. More...
 
 hasPrimaryChanges ()
 Whether there are pending changes or callbacks in a transaction by this thread. More...
 
 hasPrimaryConnection ()
 
 hasReplicaServers ()
 Whether there are any replica servers configured. More...
 
 hasStreamingReplicaServers ()
 Whether any replica servers use streaming replication from the primary server. More...
 
 laggedReplicaUsed ()
 Checks whether the database for generic connections this request was both: More...
 
 lastPrimaryChangeTimestamp ()
 Get the timestamp of the latest write query done by this thread. More...
 
 pingAll ()
 
 redefineLocalDomain ( $domain)
 Close all connection and redefine the local domain for testing or schema creation. More...
 
 resolveDomainID ( $domain)
 
 reuseConnection (IDatabase $conn)
 
 reuseConnectionInternal (IDatabase $conn)
 
 setDomainAliases (array $aliases)
 Convert certain database domains to alternative ones. More...
 
 setIndexAliases (array $aliases)
 Convert certain index names to alternative names before querying the DB. More...
 
 setTableAliases (array $aliases)
 Make certain table names use their own database, schema, and table prefix when passed into SQL queries pre-escaped and without a qualified database name. More...
 
 setTempTablesOnlyMode ( $value, $domain)
 Indicate whether the tables on this domain are only temporary tables for testing. More...
 
 setTransactionListener ( $name, callable $callback=null)
 Set a callback via IDatabase::setTransactionListener() on all current and future primary connections of this load balancer. More...
 
 waitFor ( $pos)
 Set the primary position to reach before the next generic group DB handle query. More...
 
 waitForAll ( $pos, $timeout=null)
 Set the primary wait position and wait for ALL replica DBs to catch up to it. More...
 
 waitForPrimaryPos (IDatabase $conn, $pos=false, $timeout=10)
 Wait for a replica DB to reach a specified primary position. More...
 

Public Attributes

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

Detailed Description

Interface for internal LoadBalancer methods, suitable for use on untracked objects returned by newMainLB() or for internal use by LBFactory.

Access: internal
Since
1.39

Definition at line 38 of file ILoadBalancerForOwner.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Rdbms\ILoadBalancerForOwner::__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 : 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]
  • 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]
  • clusterName: The logical name of the DB cluster [optional]
  • criticalSectionProvider: CriticalSectionProvider instance [optional]
Exceptions
InvalidArgumentException

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

Member Function Documentation

◆ approvePrimaryChanges()

Wikimedia\Rdbms\ILoadBalancerForOwner::approvePrimaryChanges ( array  $options,
  $fname = __METHOD__ 
)

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

Use this only for multi-database commits

Parameters
array$optionsIncludes:
  • 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:

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.

◆ commitAll()

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

Commit transactions on all open connections.

Parameters
string$fnameCaller name
Exceptions
DBExpectedError

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.

◆ forEachOpenConnection()

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

Call a function with each open connection object.

Deprecated:
since 1.39
Parameters
callable$callback
array$params

Implemented in Wikimedia\Rdbms\LoadBalancer.

◆ forEachOpenPrimaryConnection()

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

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

Deprecated:
since 1.39
Parameters
callable$callback
array$params
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.

◆ 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.

◆ 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.

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 40 of file ILoadBalancerForOwner.php.

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

◆ 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 42 of file ILoadBalancerForOwner.php.

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


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