MediaWiki  master
Wikimedia\Rdbms\SessionConsistentConnectionManager Class Reference

Database connection manager. More...

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

Public Member Functions

 getReadConnection (?array $groups=null, int $flags=0)
 
 getReadConnectionRef (array $groups=null)
 
 getWriteConnection (int $flags=0)
 
 getWriteConnectionRef ()
 
 prepareForUpdates ()
 Forces all future calls to getReadConnection() to return a write connection. More...
 
- Public Member Functions inherited from Wikimedia\Rdbms\ConnectionManager
 __construct (ILoadBalancer $loadBalancer, $domain=false, array $groups=[])
 
 getLazyReadConnectionRef (array $groups=null)
 Returns a lazy-connecting database connection ref for reading. More...
 
 releaseConnection (IDatabase $db)
 

Private Attributes

bool $forceWriteConnection = false
 

Detailed Description

Database connection manager.

This manages access to primary and replica databases. It also manages state that indicates whether the replica databases are possibly outdated after a write operation, and thus the primary database should be used for subsequent read operations.

Note
: Services that access overlapping sets of database tables, or interact with logically related sets of data in the database, should share a SessionConsistentConnectionManager. Services accessing unrelated sets of information may prefer to not share a SessionConsistentConnectionManager, so they can still perform read operations against replica databases after a (unrelated, per the assumption) write operation to the primary database. Generally, sharing a SessionConsistentConnectionManager improves consistency (by avoiding race conditions due to replication lag), but can reduce performance (by directing more read operations to the primary database server).
Since
1.29
Author
Daniel Kinzler
Addshore

Definition at line 45 of file SessionConsistentConnectionManager.php.

Member Function Documentation

◆ getReadConnection()

Wikimedia\Rdbms\SessionConsistentConnectionManager::getReadConnection ( ?array  $groups = null,
int  $flags = 0 
)
Since
1.29
1.37 Added optional $flags parameter
Parameters
string[] | null$groups
int$flags
Returns
IDatabase

Reimplemented from Wikimedia\Rdbms\ConnectionManager.

Definition at line 71 of file SessionConsistentConnectionManager.php.

References Wikimedia\Rdbms\ConnectionManager\$groups.

◆ getReadConnectionRef()

Wikimedia\Rdbms\SessionConsistentConnectionManager::getReadConnectionRef ( array  $groups = null)
Since
1.29
Parameters
string[] | null$groups
Returns
DBConnRef

Reimplemented from Wikimedia\Rdbms\ConnectionManager.

Definition at line 99 of file SessionConsistentConnectionManager.php.

References Wikimedia\Rdbms\ConnectionManager\$groups.

◆ getWriteConnection()

Wikimedia\Rdbms\SessionConsistentConnectionManager::getWriteConnection ( int  $flags = 0)
Since
1.29
1.37 Added optional $flags parameter
Parameters
int$flags
Returns
IDatabase

Reimplemented from Wikimedia\Rdbms\ConnectionManager.

Definition at line 87 of file SessionConsistentConnectionManager.php.

References Wikimedia\Rdbms\SessionConsistentConnectionManager\prepareForUpdates().

◆ getWriteConnectionRef()

Wikimedia\Rdbms\SessionConsistentConnectionManager::getWriteConnectionRef ( )

◆ prepareForUpdates()

Wikimedia\Rdbms\SessionConsistentConnectionManager::prepareForUpdates ( )

Forces all future calls to getReadConnection() to return a write connection.

Use this before performing read operations that are critical for a future update.

Since
1.29

Definition at line 58 of file SessionConsistentConnectionManager.php.

Referenced by Wikimedia\Rdbms\SessionConsistentConnectionManager\getWriteConnection(), and Wikimedia\Rdbms\SessionConsistentConnectionManager\getWriteConnectionRef().

Member Data Documentation

◆ $forceWriteConnection

bool Wikimedia\Rdbms\SessionConsistentConnectionManager::$forceWriteConnection = false
private

Definition at line 50 of file SessionConsistentConnectionManager.php.


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