MediaWiki master
ILBFactory.php
Go to the documentation of this file.
1<?php
6namespace Wikimedia\Rdbms;
7
8use Generator;
9use InvalidArgumentException;
10
34 public const SHUTDOWN_NORMAL = 0;
36 public const SHUTDOWN_NO_CHRONPROT = 1;
37
39 public const CLUSTER_MAIN_DEFAULT = 'DEFAULT';
40
74 public function __construct( array $conf );
75
83 public function destroy();
84
89 public function autoReconfigure(): void;
90
98 public function getLocalDomainID(): string;
99
110 public function redefineLocalDomain( $domain );
111
124 public function getLoadBalancer( $domain = false ): ILoadBalancer;
125
144 public function newMainLB( $domain = false ): ILoadBalancerForOwner;
145
157 public function getMainLB( $domain = false ): ILoadBalancer;
158
174 public function newExternalLB( $cluster ): ILoadBalancerForOwner;
175
185 public function getExternalLB( $cluster ): ILoadBalancer;
186
197 public function getAllMainLBs(): array;
198
207 public function getAllExternalLBs(): array;
208
215 public function getAllLBs();
216
225 public function shutdown(
226 $flags = self::SHUTDOWN_NORMAL,
227 ?callable $workCallback = null,
228 &$cpIndex = null,
229 &$cpClientId = null
230 );
231
242 public function flushReplicaSnapshots( $fname = __METHOD__ );
243
269 public function beginPrimaryChanges( $fname = __METHOD__ );
270
286 public function commitPrimaryChanges( $fname = __METHOD__, int $maxWriteDuration = 0 );
287
296 public function rollbackPrimaryChanges( $fname = __METHOD__ );
297
309 public function flushPrimarySessions( $fname = __METHOD__ );
310
317 public function hasTransactionRound();
318
327 public function isReadyForRoundOperations();
328
337 public function hasPrimaryChanges();
338
346 public function laggedReplicaUsed();
347
356 public function hasOrMadeRecentPrimaryChanges( $age = null );
357
379 public function waitForReplication( array $opts = [] );
380
390 public function setWaitForReplicationListener( $name, ?callable $callback = null );
391
398
405 public function setLocalDomainPrefix( $prefix );
406
412 public function closeAll( $fname = __METHOD__ );
413
417 public function setAgentName( $agent );
418
425 public function hasStreamingReplicaServers();
426
434 public function setDefaultReplicationWaitTimeout( $seconds );
435
449 public function setTableAliases( array $aliases );
450
459 public function setDomainAliases( array $aliases );
460
467 public function setDefaultGroupName( string $defaultGroup ): void;
468
476
491 public function getAutoCommitPrimaryConnection( $domain = false ): IDatabase;
492}
Detect high-contention DB queries via profiling calls.
Provide primary and replica IDatabase connections.
Interface to a relational database.
Definition IDatabase.php:31
Manager of ILoadBalancer objects and, indirectly, IDatabase connections.
getLocalDomainID()
Get the local (and default) database domain ID of connection handles.
autoReconfigure()
Reload the configuration if necessary.
redefineLocalDomain( $domain)
Close all connections and redefine the local database domain.
beginPrimaryChanges( $fname=__METHOD__)
Wrap subsequent queries for all transaction round aware primary connections in a transaction.
getAllExternalLBs()
Get the tracked load balancer instances for all external clusters.
setDefaultGroupName(string $defaultGroup)
Set the default group name for all load balancers.
setTableAliases(array $aliases)
Make certain table names use their own database, schema, and table prefix when passed into SQL querie...
newMainLB( $domain=false)
Create a new load balancer instance for the main cluster that handles the given domain.
setLocalDomainPrefix( $prefix)
Set a new table prefix for the existing local domain ID for testing.
commitPrimaryChanges( $fname=__METHOD__, int $maxWriteDuration=0)
Commit all primary connection transactions and flush all replica connection transactions.
hasPrimaryChanges()
Determine if any primary connection has pending changes.
getLoadBalancer( $domain=false)
Get the tracked load balancer instance for a given domain.
waitForReplication(array $opts=[])
Waits for the replica database server to catch up to the current primary position.
rollbackPrimaryChanges( $fname=__METHOD__)
Rollback all primary connection transactions and flush all replica connection transactions.
closeAll( $fname=__METHOD__)
Close all connections on instantiated tracked load balancer instances.
flushPrimarySessions( $fname=__METHOD__)
Release important session-level state (named lock, table locks) as post-rollback cleanup.
__construct(array $conf)
Sub-classes may extend the required keys in $conf with additional parameters.
destroy()
Close all connections and make further attempts to open connections result in DBAccessError.
laggedReplicaUsed()
Determine if any lagged replica database server connection was used.
getAllLBs()
Get all tracked load balancer instances (generator)
setDomainAliases(array $aliases)
Convert certain database domains to alternative ones.
getExternalLB( $cluster)
Get the tracked load balancer instance for an external cluster.
getMainLB( $domain=false)
Get the tracked load balancer instance for the main cluster that handles the given domain.
disableChronologyProtection()
Disable the ChronologyProtector on all instantiated tracked load balancer instances.
setDefaultReplicationWaitTimeout( $seconds)
Set the default timeout for replication wait checks.
getAutoCommitPrimaryConnection( $domain=false)
Like IConnectionProvider::getPrimaryDatabase() but with AUTOCOMMIT mode.
const SHUTDOWN_NO_CHRONPROT
Do not save "session consistency" DB replication positions.
hasTransactionRound()
Check if an explicit transaction round is active.
const SHUTDOWN_NORMAL
Idiom for "no special shutdown flags".
hasStreamingReplicaServers()
Whether it has streaming replica servers.
getAllMainLBs()
Get the tracked load balancer instances for all main clusters.
shutdown( $flags=self::SHUTDOWN_NORMAL, ?callable $workCallback=null, &$cpIndex=null, &$cpClientId=null)
Prepare all instantiated tracked load balancer instances for shutdown.
setWaitForReplicationListener( $name, ?callable $callback=null)
Add a callback to be run in every call to waitForReplication() prior to any waiting.
const CLUSTER_MAIN_DEFAULT
Default main cluster name (do not change this)
getTransactionProfiler()
Get the TransactionProfiler used by this instance.
hasOrMadeRecentPrimaryChanges( $age=null)
Determine if any primary connection has pending/written changes from this request.
newExternalLB( $cluster)
Create a new load balancer instance for an external cluster.
isReadyForRoundOperations()
Check if transaction rounds can be started, committed, or rolled back right now.
flushReplicaSnapshots( $fname=__METHOD__)
Commit all replica database server transactions, clearing any point-in-time view snapshots.
Internal interface for load balancer instances exposed to their owner.
This class is a delegate to ILBFactory for a given database cluster.