MediaWiki master
ILoadBalancer.php
Go to the documentation of this file.
1<?php
6namespace Wikimedia\Rdbms;
7
99interface ILoadBalancer {
103 public const DB_REPLICA = -1;
109 public const DB_PRIMARY = -2;
110
112 public const DOMAIN_ANY = '';
114 public const GROUP_GENERIC = '';
115
117 public const CONN_TRX_AUTOCOMMIT = 1;
122 public const CONN_UNTRACKED_GAUGE = 2;
127 public const CONN_SILENCE_ERRORS = 4;
128
147 public function getClusterName(): string;
148
156 public function getLocalDomainID(): string;
157
163 public function resolveDomainID( DatabaseDomain|string|false $domain ): string;
164
175 public function setTempTablesOnlyMode( $value, $domain );
176
190 public function getReaderIndex( $group = false );
191
236 public function getConnection( $i, $groups = [], string|false $domain = false, $flags = 0 );
237
258 public function getServerConnection( $i, $domain, $flags = 0 );
259
268 public function getConnectionInternal( $i, $groups = [], $domain = false, $flags = 0 ): IDatabase;
269
288 public function getMaintenanceConnectionRef( $i, $groups = [], $domain = false, $flags = 0 ): DBConnRef;
289
295 public function getServerCount();
296
309 public function hasReplicaServers();
310
327 public function hasStreamingReplicaServers();
328
335 public function getServerName( $i ): string;
336
344 public function getServerInfo( $i );
345
353 public function getServerType( $i );
354
362 public function getServerAttributes( $i );
363
371 public function getPrimaryPos();
372
378 public function hasPrimaryChanges();
379
386 public function explicitTrxActive();
387
396 public function hasOrMadeRecentPrimaryChanges( $age = null );
397
402 public function getReadOnlyReason();
403
407 public function pingAll();
408
418 public function getMaxLag();
419
429 public function getLagTimes();
430
442 public function waitForPrimaryPos( IDatabase $conn );
443
452 public function setTransactionListener( $name, ?callable $callback = null );
453
466 public function setTableAliases( array $aliases );
467
476 public function setDomainAliases( array $aliases );
477}
Helper class used for automatically re-using IDatabase connections and lazily establishing the actual...
Definition DBConnRef.php:37
Class to handle database/schema/prefix specifications for IDatabase.
Interface to a relational database.
Definition IDatabase.php:31
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.
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)
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.
getReaderIndex( $group=false)
Get the specific server index of the reader connection for a given group.
resolveDomainID(DatabaseDomain|string|false $domain)
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.
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.
setTransactionListener( $name, ?callable $callback=null)
Set a callback via IDatabase::setTransactionListener() on all current and future primary connections ...
hasPrimaryChanges()
Whether there are pending changes or callbacks in a transaction by this thread.
getPrimaryPos()
Get the current primary replication position.
getConnection( $i, $groups=[], string|false $domain=false, $flags=0)
Get a lazy-connecting database handle for a specific or virtual (DB_PRIMARY/DB_REPLICA) server index.
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_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.