Debian Codegraph @

includes/libs/rdbms/lbfactory/IConnectionProvider.php

raw symbols SCIP
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.
7 *
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.
12 *
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
17 *
18 * @file
19 */
20 namespace Wikimedia\Rdbms;
21
22 /**
23 * Provide primary and replica IDatabase connections.
24 *
25 * This is a narrow interface intended as the main entrypoint to the Rdbms library.
26 * No methods should be added unless absolutely needed.
27 *
28 * The main implementation is \Wikimedia\Rdbms\LBFactory.
29 * To obtain an instance, use \MediaWiki\MediaWikiServices::getDBLoadBalancerFactory().
30 *
31 * @see ILBFactory
32 * @since 1.40
33 * @ingroup Database
34 */
35 interface IConnectionProvider {
36 /**
37 * Get connection to the primary database.
38 *
39 * This should be used when there the code needs to write to the database.
40 *
41 * This method accepts virtual domains
42 * ({@see \MediaWiki\MainConfigSchema::VirtualDomainsMapping}).
43 *
44 * @since 1.40
45 * @param string|false $domain Domain ID, or false for the current domain
46 * @return IDatabase
47 */
48 public function getPrimaryDatabase( $domain = false ): IDatabase;
49
50 /**
51 * Get connection to a replica database.
52 *
53 * Note that a read can have replication lag.
54 *
55 * This method accepts virtual domains
56 * ({@see \MediaWiki\MainConfigSchema::VirtualDomainsMapping}).
57 *
58 * @since 1.40
59 * @param string|false $domain Domain ID, or false for the current domain
60 * @param string|null $group Query group; null for the default group
61 * @return IReadableDatabase
62 */
63 public function getReplicaDatabase( $domain = false, $group = null ): IReadableDatabase;
64
65 /**
66 * Commit primary DB transactions and wait for replication (if $ticket indicates it is safe).
67 *
68 * This is mostly used in jobs or deferred updates dealing with batching.
69 *
70 * The ticket is used to check that the caller owns the transaction round or can act on
71 * behalf of the caller that owns the transaction round.
72 *
73 * @see ILBFactory::commitPrimaryChanges()
74 * @see ILBFactory::waitForReplication()
75 * @since 1.28
76 * @param string $fname Caller name (e.g. __METHOD__)
77 * @param mixed $ticket Result of getEmptyTransactionTicket()
78 * @param array $opts Options to waitForReplication()
79 * @return bool True if the wait was successful, false on timeout
80 */
81 public function commitAndWaitForReplication( $fname, $ticket, array $opts = [] );
82
83 /**
84 * Get a token asserting that no write transactions are active on tracked connections.
85 *
86 * This is mostly used in jobs or deferred updates dealing with batching.
87 *
88 * @since 1.28
89 * @param string $fname Caller name (e.g. __METHOD__)
90 * @return mixed A value to pass to commitAndWaitForReplication()
91 */
92 public function getEmptyTransactionTicket( $fname );
93 }