gallery: Fix phan annotation for ImageGalleryBase::getImages
[mediawiki.git] / includes / libs / rdbms / connectionmanager / SessionConsistentConnectionManager.php
blobea12722bb241d95982a9d5d49cb521e18e64fe31
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
20 namespace Wikimedia\Rdbms;
22 /**
23 * Database connection manager.
25 * This manages access to primary and replica databases. It also manages state that indicates whether
26 * the replica databases are possibly outdated after a write operation, and thus the primary database
27 * should be used for subsequent read operations.
29 * @note: Services that access overlapping sets of database tables, or interact with logically
30 * related sets of data in the database, should share a SessionConsistentConnectionManager.
31 * Services accessing unrelated sets of information may prefer to not share a
32 * SessionConsistentConnectionManager, so they can still perform read operations against replica
33 * databases after a (unrelated, per the assumption) write operation to the primary database.
34 * Generally, sharing a SessionConsistentConnectionManager improves consistency (by avoiding race
35 * conditions due to replication lag), but can reduce performance (by directing more read
36 * operations to the primary database server).
38 * @since 1.29
39 * @ingroup Database
40 * @author Daniel Kinzler
41 * @author Addshore
43 class SessionConsistentConnectionManager extends ConnectionManager {
45 /**
46 * @var bool
48 private $forceWriteConnection = false;
50 /**
51 * Forces all future calls to getReadConnection() to return a write connection.
52 * Use this before performing read operations that are critical for a future update.
54 * @since 1.29
56 public function prepareForUpdates() {
57 $this->forceWriteConnection = true;
60 /**
61 * @since 1.29
62 * @since 1.37 Added optional $flags parameter
64 * @param string[]|null $groups
65 * @param int $flags
67 * @return IReadableDatabase
69 public function getReadConnection( ?array $groups = null, int $flags = 0 ) {
70 if ( $this->forceWriteConnection ) {
71 return parent::getWriteConnection( $flags );
74 return parent::getReadConnection( $groups, $flags );
77 /**
78 * @since 1.29
79 * @since 1.37 Added optional $flags parameter
81 * @param int $flags
83 * @return IDatabase
85 public function getWriteConnection( int $flags = 0 ) {
86 $this->prepareForUpdates();
87 return parent::getWriteConnection( $flags );