MediaWiki REL1_39
ILoadBalancer.php
Go to the documentation of this file.
1<?php
20namespace Wikimedia\Rdbms;
21
77interface ILoadBalancer {
79 public const DB_REPLICA = -1;
84 public const DB_PRIMARY = -2;
85
86 // phpcs:disable MediaWiki.Usage.DeprecatedConstantUsage.DB_MASTER
92 // phpcs:enable MediaWiki.Usage.DeprecatedConstantUsage.DB_MASTER
93
95 public const DOMAIN_ANY = '';
97 public const GROUP_GENERIC = '';
98
100 public const CONN_TRX_AUTOCOMMIT = 1;
102 public const CONN_SILENCE_ERRORS = 2;
104 public const CONN_INTENT_WRITABLE = 4;
106 public const CONN_REFRESH_READ_ONLY = 8;
107
122 public function getClusterName(): string;
123
131 public function getLocalDomainID(): string;
132
138 public function resolveDomainID( $domain ): string;
139
146 public function redefineLocalDomain( $domain );
147
158 public function setTempTablesOnlyMode( $value, $domain );
159
174 public function getReaderIndex( $group = false, $domain = false );
175
189 public function waitFor( $pos );
190
201 public function waitForAll( $pos, $timeout = null );
202
217 public function getAnyOpenConnection( $i, $flags = 0 );
218
269 public function getConnection( $i, $groups = [], $domain = false, $flags = 0 );
270
291 public function getServerConnection( $i, $domain, $flags = 0 );
292
297 public function reuseConnection( IDatabase $conn );
298
303 public function reuseConnectionInternal( IDatabase $conn );
304
313 public function getConnectionRef( $i, $groups = [], $domain = false, $flags = 0 ): IDatabase;
314
323 public function getConnectionInternal( $i, $groups = [], $domain = false, $flags = 0 ): IDatabase;
324
341 public function getLazyConnectionRef( $i, $groups = [], $domain = false, $flags = 0 ): IDatabase;
342
361 public function getMaintenanceConnectionRef( $i, $groups = [], $domain = false, $flags = 0 ): DBConnRef;
362
368 public function getWriterIndex();
369
375 public function getServerCount();
376
386 public function hasReplicaServers();
387
407 public function hasStreamingReplicaServers();
408
415 public function getServerName( $i ): string;
416
424 public function getServerInfo( $i );
425
433 public function getServerType( $i );
434
442 public function getServerAttributes( $i );
443
451 public function getPrimaryPos();
452
468 public function getReplicaResumePos();
469
478 public function closeConnection( IDatabase $conn );
479
484 public function hasPrimaryConnection();
485
491 public function hasPrimaryChanges();
492
499 public function explicitTrxActive();
500
506 public function lastPrimaryChangeTimestamp();
507
516 public function hasOrMadeRecentPrimaryChanges( $age = null );
517
523 public function getLaggedReplicaMode( $domain = false );
524
533 public function laggedReplicaUsed();
534
540 public function getReadOnlyReason( $domain = false );
541
545 public function pingAll();
546
557 public function getMaxLag( $domain = false );
558
569 public function getLagTimes( $domain = false );
570
584 public function waitForPrimaryPos( IDatabase $conn, $pos = false, $timeout = 10 );
585
593 public function setTransactionListener( $name, callable $callback = null );
594
607 public function setTableAliases( array $aliases );
608
621 public function setIndexAliases( array $aliases );
622
631 public function setDomainAliases( array $aliases );
632}
Helper class used for automatically marking an IDatabase connection as reusable (once it no longer ma...
Definition DBConnRef.php:29
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:39
Create and track the database connections and transactions for a given database cluster.
getClusterName()
Get the logical name of the database cluster.
reuseConnection(IDatabase $conn)
getConnection( $i, $groups=[], $domain=false, $flags=0)
Get a lazy-connecting database handle for a specific or virtual (DB_PRIMARY/DB_REPLICA) server index.
const CONN_INTENT_WRITABLE
Caller is requesting the primary DB server for possibly writes.
hasOrMadeRecentPrimaryChanges( $age=null)
Check if this load balancer object had any recent or still pending writes issued against it by this P...
getServerType( $i)
Get the RDBMS type of the server with the specified index (e.g.
const GROUP_GENERIC
The generic query group.
getMaxLag( $domain=false)
Get the name and lag time of the most-lagged replica server.
waitFor( $pos)
Set the primary position to reach before the next generic group DB query.
getServerConnection( $i, $domain, $flags=0)
Get a DB handle for a specific server index.
getReadOnlyReason( $domain=false)
getReplicaResumePos()
Get the highest DB replication position for chronology control purposes.
setTransactionListener( $name, callable $callback=null)
Set a callback via IDatabase::setTransactionListener() on all current and future primary connections ...
reuseConnectionInternal(IDatabase $conn)
getReaderIndex( $group=false, $domain=false)
Get the specific server index of the reader connection for a given group.
waitForPrimaryPos(IDatabase $conn, $pos=false, $timeout=10)
Wait for a replica DB to reach a specified primary position.
getLaggedReplicaMode( $domain=false)
const DOMAIN_ANY
Domain specifier when no specific database needs to be selected.
const DB_REPLICA
Request a replica DB connection.
const CONN_TRX_AUTOCOMMIT
DB handle should have DBO_TRX disabled and the caller will leave it as such.
setTableAliases(array $aliases)
Make certain table names use their own database, schema, and table prefix when passed into SQL querie...
redefineLocalDomain( $domain)
Close all connection and redefine the local domain for testing or schema creation.
const CONN_SILENCE_ERRORS
Return null on connection failure instead of throwing an exception.
setTempTablesOnlyMode( $value, $domain)
Indicate whether the tables on this domain are only temporary tables for testing.
getWriterIndex()
Get the specific server index of the primary server.
setDomainAliases(array $aliases)
Convert certain database domains to alternative ones.
laggedReplicaUsed()
Checks whether the database for generic connections this request was both:
getServerCount()
Get the number of servers defined in configuration.
getLocalDomainID()
Get the local (and default) database domain ID of connection handles.
getServerInfo( $i)
Return the server configuration map for the server with the specified index.
const CONN_REFRESH_READ_ONLY
Bypass and update any server-side read-only mode state cache.
getConnectionRef( $i, $groups=[], $domain=false, $flags=0)
hasPrimaryChanges()
Whether there are pending changes or callbacks in a transaction by this thread.
getPrimaryPos()
Get the current primary replication position.
getMaintenanceConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a DB handle, suitable for migrations and schema changes, for a server index.
setIndexAliases(array $aliases)
Convert certain index names to alternative names before querying the DB.
getLazyConnectionRef( $i, $groups=[], $domain=false, $flags=0)
Get a lazy-connecting database handle for a server index.
explicitTrxActive()
Determine whether an explicit transaction is active on any open primary connection.
lastPrimaryChangeTimestamp()
Get the timestamp of the latest write query done by this thread.
const DB_MASTER
Request a primary, write-enabled DB connection.
const DB_PRIMARY
Request a primary, write-enabled DB connection.
closeConnection(IDatabase $conn)
Close a connection.
getConnectionInternal( $i, $groups=[], $domain=false, $flags=0)
hasReplicaServers()
Whether there are any replica servers configured.
getLagTimes( $domain=false)
Get an estimate of replication lag (in seconds) for each server.
hasStreamingReplicaServers()
Whether any replica servers use streaming replication from the primary server.
getServerName( $i)
Get the readable name of the server with the specified index.
getServerAttributes( $i)
Get basic attributes of the server with the specified index without connecting.
waitForAll( $pos, $timeout=null)
Set the primary wait position and wait for ALL replica DBs to catch up to it.
getAnyOpenConnection( $i, $flags=0)
Get an existing DB handle to the given server index (on any domain)