MediaWiki master
ILoadBalancer.php
Go to the documentation of this file.
1<?php
20namespace Wikimedia\Rdbms;
21
113interface ILoadBalancer {
117 public const DB_REPLICA = -1;
123 public const DB_PRIMARY = -2;
124
125 // phpcs:disable MediaWiki.Usage.DeprecatedConstantUsage.DB_MASTER
131 // phpcs:enable MediaWiki.Usage.DeprecatedConstantUsage.DB_MASTER
132
134 public const DOMAIN_ANY = '';
136 public const GROUP_GENERIC = '';
137
139 public const CONN_UNTRACKED_GAUGE = 1;
141 public const CONN_TRX_AUTOCOMMIT = 2;
143 public const CONN_SILENCE_ERRORS = 4;
145 public const CONN_INTENT_WRITABLE = 8;
146
165 public function getClusterName(): string;
166
174 public function getLocalDomainID(): string;
175
181 public function resolveDomainID( $domain ): string;
182
193 public function setTempTablesOnlyMode( $value, $domain );
194
208 public function getReaderIndex( $group = false );
209
254 public function getConnection( $i, $groups = [], $domain = false, $flags = 0 );
255
276 public function getServerConnection( $i, $domain, $flags = 0 );
277
282 public function reuseConnection( IDatabase $conn );
283
292 public function getConnectionRef( $i, $groups = [], $domain = false, $flags = 0 ): DBConnRef;
293
302 public function getConnectionInternal( $i, $groups = [], $domain = false, $flags = 0 ): IDatabase;
303
322 public function getMaintenanceConnectionRef( $i, $groups = [], $domain = false, $flags = 0 ): DBConnRef;
323
335 public function getWriterIndex();
336
342 public function getServerCount();
343
356 public function hasReplicaServers();
357
374 public function hasStreamingReplicaServers();
375
382 public function getServerName( $i ): string;
383
391 public function getServerInfo( $i );
392
400 public function getServerType( $i );
401
409 public function getServerAttributes( $i );
410
418 public function getPrimaryPos();
419
425 public function hasPrimaryChanges();
426
433 public function explicitTrxActive();
434
443 public function hasOrMadeRecentPrimaryChanges( $age = null );
444
450 public function getReadOnlyReason( $domain = false );
451
455 public function pingAll();
456
466 public function getMaxLag();
467
477 public function getLagTimes();
478
490 public function waitForPrimaryPos( IDatabase $conn );
491
499 public function setTransactionListener( $name, callable $callback = null );
500
513 public function setTableAliases( array $aliases );
514
523 public function setDomainAliases( array $aliases );
524}
Helper class used for automatically re-using IDatabase connections and lazily establishing the actual...
Definition DBConnRef.php:36
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:36
This class is a delegate to ILBFactory for a given database cluster.
getClusterName()
Get the name of the overall cluster of database servers managing the dataset.
reuseConnection(IDatabase $conn)
getMaxLag()
Get the name and lag time of the most-lagged replica server.
const CONN_UNTRACKED_GAUGE
Yield an untracked, low-timeout, autocommit-mode handle (to gauge server health)
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...
getLagTimes()
Get an estimate of replication lag (in seconds) for each server.
getServerType( $i)
Get the RDBMS type of the server with the specified index (e.g.
const GROUP_GENERIC
The generic query group.
getServerConnection( $i, $domain, $flags=0)
Get a DB handle for a specific server index.
getReadOnlyReason( $domain=false)
setTransactionListener( $name, callable $callback=null)
Set a callback via IDatabase::setTransactionListener() on all current and future primary connections ...
getReaderIndex( $group=false)
Get the specific server index of the reader connection for a given group.
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
Yield a tracked autocommit-mode handle (reuse existing ones)
setTableAliases(array $aliases)
Make certain table names use their own database, schema, and table prefix when passed into SQL querie...
const CONN_SILENCE_ERRORS
Yield 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 "writer server".
setDomainAliases(array $aliases)
Convert certain database domains to alternative ones.
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.
waitForPrimaryPos(IDatabase $conn)
Wait for a replica DB to reach a specified primary position.
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.
explicitTrxActive()
Determine whether an explicit transaction is active on any open primary connection.
const DB_MASTER
Request a primary, write-enabled DB connection.
const DB_PRIMARY
Request a primary, write-enabled DB connection.
getConnectionInternal( $i, $groups=[], $domain=false, $flags=0)
hasReplicaServers()
Whether there are any replica servers configured.
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.