MediaWiki master
IDatabase.php
Go to the documentation of this file.
1<?php
20namespace Wikimedia\Rdbms;
21
22use Exception;
23use Wikimedia\ScopedCallback;
24
45interface IDatabase extends IReadableDatabase {
47 public const TRIGGER_IDLE = 1;
49 public const TRIGGER_COMMIT = 2;
51 public const TRIGGER_ROLLBACK = 3;
53 public const TRIGGER_CANCEL = 4;
54
56 public const TRANSACTION_EXPLICIT = '';
58 public const TRANSACTION_INTERNAL = 'implicit';
59
61 public const ATOMIC_NOT_CANCELABLE = '';
63 public const ATOMIC_CANCELABLE = 'cancelable';
64
66 public const FLUSHING_ONE = '';
71 public const FLUSHING_ALL_PEERS = 'flush';
76 public const FLUSHING_INTERNAL = 'flush-internal';
77
79 public const ESTIMATE_TOTAL = 'total';
81 public const ESTIMATE_DB_APPLY = 'apply';
82
84 public const LOCK_TIMESTAMP = 1;
85
90 public const LB_TRX_ROUND_LEVEL = 'trxRoundLevel';
95 public const LB_TRX_ROUND_FNAME = 'trxRoundOwner';
100 public const LB_READ_ONLY_REASON = 'readOnlyReason';
106
108 public const ROLE_STREAMING_MASTER = 'streaming-master';
110 public const ROLE_STREAMING_REPLICA = 'streaming-replica';
112 public const ROLE_STATIC_CLONE = 'static-clone';
114 public const ROLE_UNKNOWN = 'unknown';
115
124 public function trxLevel();
125
137 public function trxTimestamp();
138
148 public function explicitTrxActive();
149
158 public function getLBInfo( $name = null );
159
180 public function insertId();
181
204 public function affectedRows();
205
236 public function query( $sql, $fname = __METHOD__, $flags = 0 );
237
249
261
273
285
301 public function lockForUpdate(
302 $table, $conds = '', $fname = __METHOD__, $options = [], $join_conds = []
303 );
304
329 public function insert( $table, $rows, $fname = __METHOD__, $options = [] );
330
370 public function update( $table, $set, $conds, $fname = __METHOD__, $options = [] );
371
408 public function replace( $table, $uniqueKeys, $rows, $fname = __METHOD__ );
409
450 public function upsert(
451 $table, array $rows, $uniqueKeys, array $set, $fname = __METHOD__
452 );
453
476 public function deleteJoin(
477 $delTable,
478 $joinTable,
479 $delVar,
480 $joinVar,
481 $conds,
482 $fname = __METHOD__
483 );
484
508 public function delete( $table, $conds, $fname = __METHOD__ );
509
544 public function insertSelect(
545 $destTable,
546 $srcTable,
547 $varMap,
548 $conds,
549 $fname = __METHOD__,
550 $insertOptions = [],
551 $selectOptions = [],
552 $selectJoinConds = []
553 );
554
584 public function onTransactionResolution( callable $callback, $fname = __METHOD__ );
585
619 public function onTransactionCommitOrIdle( callable $callback, $fname = __METHOD__ );
620
647 public function onTransactionPreCommitOrIdle( callable $callback, $fname = __METHOD__ );
648
723 public function startAtomic( $fname = __METHOD__, $cancelable = self::ATOMIC_NOT_CANCELABLE );
724
736 public function endAtomic( $fname = __METHOD__ );
737
763 public function cancelAtomic( $fname = __METHOD__, ?AtomicSectionIdentifier $sectionId = null );
764
837 public function doAtomicSection(
838 $fname, callable $callback, $cancelable = self::ATOMIC_NOT_CANCELABLE
839 );
840
860 public function begin( $fname = __METHOD__, $mode = self::TRANSACTION_EXPLICIT );
861
880 public function commit( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
881
901 public function rollback( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
902
923 public function flushSnapshot( $fname = __METHOD__, $flush = self::FLUSHING_ONE );
924
942 public function setSessionOptions( array $options );
943
953 public function lockIsFree( $lockName, $method );
954
967 public function lock( $lockName, $method, $timeout = 5, $flags = 0 );
968
979 public function unlock( $lockName, $method );
980
1002 public function getScopedLockAndFlush( $lockKey, $fname, $timeout );
1003
1012 public function isReadOnly();
1013}
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:45
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:61
endAtomic( $fname=__METHOD__)
Ends an atomic section of SQL statements.
const ROLE_STREAMING_MASTER
Primary server than can stream writes to replica servers.
lock( $lockName, $method, $timeout=5, $flags=0)
Acquire a named lock.
const ROLE_STATIC_CLONE
Replica server within a static dataset.
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:66
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:58
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:90
newReplaceQueryBuilder()
Get an ReplaceQueryBuilder bound to this connection.
const TRIGGER_ROLLBACK
Callback triggered by ROLLBACK.
Definition IDatabase.php:51
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.
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.
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:81
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:76
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:95
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:49
const TRIGGER_CANCEL
Callback triggered by atomic section cancel (ROLLBACK TO SAVEPOINT)
Definition IDatabase.php:53
const ESTIMATE_TOTAL
Estimate total time (RTT, scanning, waiting on locks, applying)
Definition IDatabase.php:79
const LB_READ_ONLY_REASON
Field for getLBInfo()/setLBInfo(); configured read-only mode explanation or false.
const TRANSACTION_EXPLICIT
Transaction is requested by regular caller outside of the DB layer.
Definition IDatabase.php:56
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:84
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:71
const ATOMIC_CANCELABLE
Atomic section is cancelable.
Definition IDatabase.php:63
const TRIGGER_IDLE
Callback triggered immediately due to no active transaction.
Definition IDatabase.php:47
isReadOnly()
Check if this DB server is marked as read-only according to load balancer info.
A database connection without write operations.