1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
namespace Wikimedia\Rdbms;
/**
* Provide primary and replica IDatabase connections.
*
* This is a narrow interface intended as the main entrypoint to the Rdbms library.
* No methods should be added unless absolutely needed.
*
* The main implementation is \Wikimedia\Rdbms\LBFactory.
* To obtain an instance, use \MediaWiki\MediaWikiServices::getDBLoadBalancerFactory().
*
* @see ILBFactory
* @since 1.40
* @ingroup Database
*/
interface IConnectionProvider {
/**
* Get connection to the primary database.
*
* This should be used when there the code needs to write to the database.
*
* This method accepts virtual domains
* ({@see \MediaWiki\MainConfigSchema::VirtualDomainsMapping}).
*
* @since 1.40
* @param string|false $domain Domain ID, or false for the current domain
* @return IDatabase
*/
public function getPrimaryDatabase( $domain = false ): IDatabase;
/**
* Get connection to a replica database.
*
* Note that a read can have replication lag.
*
* This method accepts virtual domains
* ({@see \MediaWiki\MainConfigSchema::VirtualDomainsMapping}).
*
* @since 1.40
* @param string|false $domain Domain ID, or false for the current domain
* @param string|null $group Query group; null for the default group
* @return IReadableDatabase
*/
public function getReplicaDatabase( $domain = false, $group = null ): IReadableDatabase;
/**
* Commit primary DB transactions and wait for replication (if $ticket indicates it is safe).
*
* This is mostly used in jobs or deferred updates dealing with batching.
*
* The ticket is used to check that the caller owns the transaction round or can act on
* behalf of the caller that owns the transaction round.
*
* @see ILBFactory::commitPrimaryChanges()
* @see ILBFactory::waitForReplication()
* @since 1.28
* @param string $fname Caller name (e.g. __METHOD__)
* @param mixed $ticket Result of getEmptyTransactionTicket()
* @param array $opts Options to waitForReplication()
* @return bool True if the wait was successful, false on timeout
*/
public function commitAndWaitForReplication( $fname, $ticket, array $opts = [] );
/**
* Get a token asserting that no write transactions are active on tracked connections.
*
* This is mostly used in jobs or deferred updates dealing with batching.
*
* @since 1.28
* @param string $fname Caller name (e.g. __METHOD__)
* @return mixed A value to pass to commitAndWaitForReplication()
*/
public function getEmptyTransactionTicket( $fname );
}
|