MediaWiki REL1_40
IDatabase.php
Go to the documentation of this file.
1<?php
20namespace Wikimedia\Rdbms;
21
22use Exception;
23use Wikimedia\ScopedCallback;
24
36interface IDatabase extends IReadableDatabase {
38 public const TRIGGER_IDLE = 1;
40 public const TRIGGER_COMMIT = 2;
42 public const TRIGGER_ROLLBACK = 3;
44 public const TRIGGER_CANCEL = 4;
45
47 public const TRANSACTION_EXPLICIT = '';
49 public const TRANSACTION_INTERNAL = 'implicit';
50
52 public const ATOMIC_NOT_CANCELABLE = '';
54 public const ATOMIC_CANCELABLE = 'cancelable';
55
57 public const FLUSHING_ONE = '';
59 public const FLUSHING_ALL_PEERS = 'flush';
61 public const FLUSHING_INTERNAL = 'flush-internal';
62
64 public const ESTIMATE_TOTAL = 'total';
66 public const ESTIMATE_DB_APPLY = 'apply';
71 public const DBO_SSL = 256;
73 public const DBO_COMPRESS = 512;
74
76 public const LOCK_TIMESTAMP = 1;
77
79 public const UNION_ALL = true;
81 public const UNION_DISTINCT = false;
82
84 public const LB_TRX_ROUND_ID = 'trxRoundId';
86 public const LB_READ_ONLY_REASON = 'readOnlyReason';
87
89 public const ROLE_STREAMING_MASTER = 'streaming-master';
91 public const ROLE_STREAMING_REPLICA = 'streaming-replica';
93 public const ROLE_STATIC_CLONE = 'static-clone';
95 public const ROLE_UNKNOWN = 'unknown';
96
108 public function getTopologyBasedServerId();
109
121 public function getTopologyRole();
122
131 public function trxLevel();
132
144 public function trxTimestamp();
145
155 public function explicitTrxActive();
156
163 public function getLBInfo( $name = null );
164
173 public function setLBInfo( $nameOrArray, $value = null );
174
181 public function lastDoneWrites();
182
187 public function writesPending();
188
197 public function writesOrCallbacksPending();
198
208 public function pendingWriteQueryDuration( $type = self::ESTIMATE_TOTAL );
209
216 public function pendingWriteCallers();
217
227 public function insertId();
228
238 public function affectedRows();
239
268 public function query( $sql, $fname = __METHOD__, $flags = 0 );
269
289 public function queryMulti(
290 array $sqls, string $fname = __METHOD__, int $flags = 0, ?string $summarySql = null
291 );
292
304
317 public function lockForUpdate(
318 $table, $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
319 );
320
343 public function insert( $table, $rows, $fname = __METHOD__, $options = [] );
344
372 public function update( $table, $set, $conds, $fname = __METHOD__, $options = [] );
373
390 public function nextSequenceValue( $seqName );
391
426 public function replace( $table, $uniqueKeys, $rows, $fname = __METHOD__ );
427
468 public function upsert(
469 $table, array $rows, $uniqueKeys, array $set, $fname = __METHOD__
470 );
471
492 public function deleteJoin(
493 $delTable,
494 $joinTable,
495 $delVar,
496 $joinVar,
497 $conds,
498 $fname = __METHOD__
499 );
500
516 public function delete( $table, $conds, $fname = __METHOD__ );
517
551 public function insertSelect(
552 $destTable,
553 $srcTable,
554 $varMap,
555 $conds,
556 $fname = __METHOD__,
557 $insertOptions = [],
558 $selectOptions = [],
559 $selectJoinConds = []
560 );
561
569 public function getPrimaryPos();
570
576 public function serverIsReadOnly();
577
610 public function onTransactionResolution( callable $callback, $fname = __METHOD__ );
611
646 public function onTransactionCommitOrIdle( callable $callback, $fname = __METHOD__ );
647
677 public function onTransactionPreCommitOrIdle( callable $callback, $fname = __METHOD__ );
678
702 public function onAtomicSectionCancel( callable $callback, $fname = __METHOD__ );
703
721 public function setTransactionListener( $name, callable $callback = null );
722
797 public function startAtomic( $fname = __METHOD__, $cancelable = self::ATOMIC_NOT_CANCELABLE );
798
810 public function endAtomic( $fname = __METHOD__ );
811
837 public function cancelAtomic( $fname = __METHOD__, AtomicSectionIdentifier $sectionId = null );
838
911 public function doAtomicSection(
912 $fname, callable $callback, $cancelable = self::ATOMIC_NOT_CANCELABLE
913 );
914
934 public function begin( $fname = __METHOD__, $mode = self::TRANSACTION_EXPLICIT );
935
954 public function commit( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
955
975 public function rollback( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
976
994 public function flushSession( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
995
1016 public function flushSnapshot( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
1017
1029 public function setSessionOptions( array $options );
1030
1040 public function lockIsFree( $lockName, $method );
1041
1054 public function lock( $lockName, $method, $timeout = 5, $flags = 0 );
1055
1066 public function unlock( $lockName, $method );
1067
1089 public function getScopedLockAndFlush( $lockKey, $fname, $timeout );
1090
1097 public function namedLocksEnqueue();
1098
1103 public function isReadOnly();
1104}
1105
1109class_alias( IDatabase::class, 'IDatabase' );
Class used for token representing identifiers for atomic sections from IDatabase instances.
A query builder for UPDATE queries with a fluent interface.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:36
onTransactionResolution(callable $callback, $fname=__METHOD__)
Run a callback when the current transaction commits or rolls back.
onTransactionPreCommitOrIdle(callable $callback, $fname=__METHOD__)
Run a callback before the current transaction commits or now if there is none.
flushSnapshot( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
Commit any transaction but error out if writes or callbacks are pending.
rollback( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
Rollback a transaction previously started using begin()
setSessionOptions(array $options)
Override database's default behavior.
nextSequenceValue( $seqName)
Deprecated method, calls should be removed.
lastDoneWrites()
Get the last time the connection may have been used for a write query.
unlock( $lockName, $method)
Release a lock.
explicitTrxActive()
Check whether there is a transaction open at the specific request of a caller.
namedLocksEnqueue()
Check to see if a named lock used by lock() use blocking queues.
doAtomicSection( $fname, callable $callback, $cancelable=self::ATOMIC_NOT_CANCELABLE)
Perform an atomic section of reversible SQL statements from a callback.
endAtomic( $fname=__METHOD__)
Ends an atomic section of SQL statements.
lock( $lockName, $method, $timeout=5, $flags=0)
Acquire a named lock.
setLBInfo( $nameOrArray, $value=null)
Set the entire array or a particular key of the managing load balancer info array.
setTransactionListener( $name, callable $callback=null)
Run a callback after each time any transaction commits or rolls back.
flushSession( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
Release important session-level state (named lock, table locks) as post-rollback cleanup.
lockForUpdate( $table, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Lock all rows meeting the given conditions/options FOR UPDATE.
queryMulti(array $sqls, string $fname=__METHOD__, int $flags=0, ?string $summarySql=null)
Run a batch of SQL query statements and return the results.
getLBInfo( $name=null)
Get properties passed down from the server info array of the load balancer.
newUpdateQueryBuilder()
Get an UpdateQueryBuilder bound to this connection.
insertSelect( $destTable, $srcTable, $varMap, $conds, $fname=__METHOD__, $insertOptions=[], $selectOptions=[], $selectJoinConds=[])
INSERT SELECT wrapper.
deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname=__METHOD__)
Delete all rows in a table that match a condition which includes a join.
getTopologyBasedServerId()
Get a non-recycled ID that uniquely identifies this server within the replication topology.
affectedRows()
Get the number of rows affected by the last attempted query statement.
lockIsFree( $lockName, $method)
Check to see if a named lock is not locked by any thread (non-blocking)
pendingWriteQueryDuration( $type=self::ESTIMATE_TOTAL)
Get the time spend running write queries for this transaction.
update( $table, $set, $conds, $fname=__METHOD__, $options=[])
Update all rows in a table that match a given condition.
upsert( $table, array $rows, $uniqueKeys, array $set, $fname=__METHOD__)
Upsert row(s) into a table, in the provided order, while updating conflicting rows.
commit( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
Commits a transaction previously started using begin()
getTopologyRole()
Get the replication topology role of this server.
onTransactionCommitOrIdle(callable $callback, $fname=__METHOD__)
Run a callback when the current transaction commits or now if there is none.
getScopedLockAndFlush( $lockKey, $fname, $timeout)
Acquire a named lock, flush any transaction, and return an RAII style unlocker object.
onAtomicSectionCancel(callable $callback, $fname=__METHOD__)
Run a callback when the atomic section is cancelled.
query( $sql, $fname=__METHOD__, $flags=0)
Run an SQL query statement and return the result.
begin( $fname=__METHOD__, $mode=self::TRANSACTION_EXPLICIT)
Begin a transaction.
insert( $table, $rows, $fname=__METHOD__, $options=[])
Insert row(s) into a table, in the provided order.
replace( $table, $uniqueKeys, $rows, $fname=__METHOD__)
Insert row(s) into a table, in the provided order, while deleting conflicting rows.
trxLevel()
Gets the current transaction level.
startAtomic( $fname=__METHOD__, $cancelable=self::ATOMIC_NOT_CANCELABLE)
Begin an atomic section of SQL statements.
insertId()
Get the inserted value of an auto-increment row.
trxTimestamp()
Get the UNIX timestamp of the time that the transaction was established.
writesOrCallbacksPending()
Whether there is a transaction open with either possible write queries or unresolved pre-commit/commi...
const LOCK_TIMESTAMP
Flag to return the lock acquisition timestamp (null if not acquired)
Definition IDatabase.php:76
pendingWriteCallers()
Get the list of method names that did write queries for this transaction.
getPrimaryPos()
Get the position of this primary DB.
cancelAtomic( $fname=__METHOD__, AtomicSectionIdentifier $sectionId=null)
Cancel an atomic section of SQL statements.
A database connection without write operations.
const DBO_COMPRESS
Definition defines.php:19
const DBO_SSL
Definition defines.php:18