MediaWiki master
IDatabase.php
Go to the documentation of this file.
1<?php
6namespace Wikimedia\Rdbms;
7
8use Exception;
9use Wikimedia\ScopedCallback;
10
31interface IDatabase extends IReadableDatabase {
33 public const TRIGGER_IDLE = 1;
35 public const TRIGGER_COMMIT = 2;
37 public const TRIGGER_ROLLBACK = 3;
39 public const TRIGGER_CANCEL = 4;
40
42 public const TRANSACTION_EXPLICIT = '';
44 public const TRANSACTION_INTERNAL = 'implicit';
45
47 public const ATOMIC_NOT_CANCELABLE = '';
49 public const ATOMIC_CANCELABLE = 'cancelable';
50
52 public const FLUSHING_ONE = '';
57 public const FLUSHING_ALL_PEERS = 'flush';
62 public const FLUSHING_INTERNAL = 'flush-internal';
63
65 public const ESTIMATE_TOTAL = 'total';
67 public const ESTIMATE_DB_APPLY = 'apply';
68
70 public const LOCK_TIMESTAMP = 1;
71
76 public const LB_TRX_ROUND_LEVEL = 'trxRoundLevel';
81 public const LB_TRX_ROUND_FNAME = 'trxRoundOwner';
86 public const LB_READ_ONLY_REASON = 'readOnlyReason';
92
94 public const ROLE_STREAMING_MASTER = 'streaming-master';
96 public const ROLE_STREAMING_REPLICA = 'streaming-replica';
98 public const ROLE_STATIC_CLONE = 'static-clone';
100 public const ROLE_UNKNOWN = 'unknown';
101
110 public function trxLevel();
111
123 public function trxTimestamp();
124
134 public function explicitTrxActive();
135
144 public function getLBInfo( $name = null );
145
166 public function insertId();
167
190 public function affectedRows();
191
222 public function query( $sql, $fname = __METHOD__, $flags = 0 );
223
235
247
259
271
287 public function lockForUpdate(
288 $table, $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
289 );
290
315 public function insert( $table, $rows, $fname = __METHOD__, $options = [] );
316
356 public function update( $table, $set, $conds, $fname = __METHOD__, $options = [] );
357
394 public function replace( $table, $uniqueKeys, $rows, $fname = __METHOD__ );
395
436 public function upsert(
437 $table, array $rows, $uniqueKeys, array $set, $fname = __METHOD__
438 );
439
462 public function deleteJoin(
463 $delTable,
464 $joinTable,
465 $delVar,
466 $joinVar,
467 $conds,
468 $fname = __METHOD__
469 );
470
494 public function delete( $table, $conds, $fname = __METHOD__ );
495
530 public function insertSelect(
531 $destTable,
532 $srcTable,
533 $varMap,
534 $conds,
535 $fname = __METHOD__,
536 $insertOptions = [],
537 $selectOptions = [],
538 $selectJoinConds = []
539 );
540
570 public function onTransactionResolution( callable $callback, $fname = __METHOD__ );
571
605 public function onTransactionCommitOrIdle( callable $callback, $fname = __METHOD__ );
606
633 public function onTransactionPreCommitOrIdle( callable $callback, $fname = __METHOD__ );
634
709 public function startAtomic( $fname = __METHOD__, $cancelable = self::ATOMIC_NOT_CANCELABLE );
710
722 public function endAtomic( $fname = __METHOD__ );
723
749 public function cancelAtomic( $fname = __METHOD__, ?AtomicSectionIdentifier $sectionId = null );
750
823 public function doAtomicSection(
824 $fname, callable $callback, $cancelable = self::ATOMIC_NOT_CANCELABLE
825 );
826
846 public function begin( $fname = __METHOD__, $mode = self::TRANSACTION_EXPLICIT );
847
866 public function commit( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
867
887 public function rollback( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
888
909 public function flushSnapshot( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
910
928 public function setSessionOptions( array $options );
929
939 public function lockIsFree( $lockName, $method );
940
953 public function lock( $lockName, $method, $timeout = 5, $flags = 0 );
954
965 public function unlock( $lockName, $method );
966
988 public function getScopedLockAndFlush( $lockKey, $fname, $timeout );
989
998 public function isReadOnly();
999}
Class used for token representing identifiers for atomic sections from IDatabase instances.
A query builder for DELETE queries with a fluent interface.
Build INSERT queries with a fluent interface.
Build REPLACE queries with a fluent interface.
Build UPDATE queries with a fluent interface.
Interface to a relational database.
Definition IDatabase.php:31
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.
unlock( $lockName, $method)
Release a lock.
explicitTrxActive()
Check whether there is a transaction open at the specific request of a caller.
doAtomicSection( $fname, callable $callback, $cancelable=self::ATOMIC_NOT_CANCELABLE)
Perform an atomic section of reversible SQL statements from a callback.
const ATOMIC_NOT_CANCELABLE
Atomic section is not cancelable.
Definition IDatabase.php:47
endAtomic( $fname=__METHOD__)
Ends an atomic section of SQL statements.
const ROLE_STREAMING_MASTER
Primary server than can stream writes to replica servers.
Definition IDatabase.php:94
lock( $lockName, $method, $timeout=5, $flags=0)
Acquire a named lock.
const ROLE_STATIC_CLONE
Replica server within a static dataset.
Definition IDatabase.php:98
lockForUpdate( $table, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Lock all rows meeting the given conditions/options FOR UPDATE.
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.
const FLUSHING_ONE
Commit/rollback is from outside the IDatabase handle and connection manager.
Definition IDatabase.php:52
deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname=__METHOD__)
Delete all rows in a table that match a condition which includes a join.
newDeleteQueryBuilder()
Get an DeleteQueryBuilder bound to this connection.
const TRANSACTION_INTERNAL
Transaction is requested internally via DBO_TRX/startAtomic()
Definition IDatabase.php:44
affectedRows()
Get the number of rows affected by the last query method call.
const LB_TRX_ROUND_LEVEL
Field for getLBInfo()/setLBInfo(); relevant transaction round level (1 or 0)
Definition IDatabase.php:76
newReplaceQueryBuilder()
Get an ReplaceQueryBuilder bound to this connection.
const TRIGGER_ROLLBACK
Callback triggered by ROLLBACK.
Definition IDatabase.php:37
lockIsFree( $lockName, $method)
Check to see if a named lock is not locked by any thread (non-blocking)
const LB_TRX_ROUND_ID
Alias to LB_TRX_ROUND_FNAME.
Definition IDatabase.php:91
update( $table, $set, $conds, $fname=__METHOD__, $options=[])
Update all rows in a table that match a given condition.
const ROLE_STREAMING_REPLICA
Replica server that receives writes from a primary server.
Definition IDatabase.php:96
upsert( $table, array $rows, $uniqueKeys, array $set, $fname=__METHOD__)
Upsert row(s) into a table, in the provided order, while updating conflicting rows.
const ESTIMATE_DB_APPLY
Estimate time to apply (scanning, applying)
Definition IDatabase.php:67
commit( $fname=__METHOD__, $flush=self::FLUSHING_ONE)
Commits a transaction previously started using begin()
onTransactionCommitOrIdle(callable $callback, $fname=__METHOD__)
Run a callback when the current transaction commits or now if there is none.
const FLUSHING_INTERNAL
Commit/rollback is from the IDatabase handle internally.
Definition IDatabase.php:62
const ROLE_UNKNOWN
Server with unknown topology role.
getScopedLockAndFlush( $lockKey, $fname, $timeout)
Acquire a named lock, flush any transaction, and return an RAII style unlocker object.
query( $sql, $fname=__METHOD__, $flags=0)
Run an SQL query statement and return the result.
cancelAtomic( $fname=__METHOD__, ?AtomicSectionIdentifier $sectionId=null)
Cancel an atomic section of SQL statements.
const LB_TRX_ROUND_FNAME
Field for getLBInfo()/setLBInfo(); relevant transaction round owner name or null.
Definition IDatabase.php:81
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 sequence-based ID assigned by the last query method call.
const TRIGGER_COMMIT
Callback triggered by COMMIT.
Definition IDatabase.php:35
const TRIGGER_CANCEL
Callback triggered by atomic section cancel (ROLLBACK TO SAVEPOINT)
Definition IDatabase.php:39
const ESTIMATE_TOTAL
Estimate total time (RTT, scanning, waiting on locks, applying)
Definition IDatabase.php:65
const LB_READ_ONLY_REASON
Field for getLBInfo()/setLBInfo(); configured read-only mode explanation or false.
Definition IDatabase.php:86
const TRANSACTION_EXPLICIT
Transaction is requested by regular caller outside of the DB layer.
Definition IDatabase.php:42
trxTimestamp()
Get the UNIX timestamp of the time that the transaction was established.
const LOCK_TIMESTAMP
Flag to return the lock acquisition timestamp (null if not acquired)
Definition IDatabase.php:70
newInsertQueryBuilder()
Get an InsertQueryBuilder bound to this connection.
const FLUSHING_ALL_PEERS
Commit/rollback is from the owning connection manager for the IDatabase handle.
Definition IDatabase.php:57
const ATOMIC_CANCELABLE
Atomic section is cancelable.
Definition IDatabase.php:49
const TRIGGER_IDLE
Callback triggered immediately due to no active transaction.
Definition IDatabase.php:33
isReadOnly()
Check if this DB server is marked as read-only according to load balancer info.
A database connection without write operations.