tests: Reset Postgres sequences when cloning and truncating
[lhc/web/wiklou.git] / includes / libs / rdbms / database / IDatabase.php
index 447c13e..5876d6b 100644 (file)
@@ -49,6 +49,11 @@ interface IDatabase {
        /** @var string Transaction is requested internally via DBO_TRX/startAtomic() */
        const TRANSACTION_INTERNAL = 'implicit';
 
+       /** @var string Atomic section is not cancelable */
+       const ATOMIC_NOT_CANCELABLE = '';
+       /** @var string Atomic section is cancelable */
+       const ATOMIC_CANCELABLE = 'cancelable';
+
        /** @var string Transaction operation comes from service managing all DBs */
        const FLUSHING_ALL_PEERS = 'flush';
        /** @var string Transaction operation comes from the database class internally */
@@ -85,7 +90,7 @@ interface IDatabase {
        const DBO_NOBUFFER = 2;
        /** @var int Ignore query errors (internal use only!) */
        const DBO_IGNORE = 4;
-       /** @var int Autoatically start transaction on first query (work with ILoadBalancer rounds) */
+       /** @var int Automatically start a transaction before running a query if none is active */
        const DBO_TRX = 8;
        /** @var int Use DBO_TRX in non-CLI mode */
        const DBO_DEFAULT = 16;
@@ -248,7 +253,7 @@ interface IDatabase {
        public function writesPending();
 
        /**
-        * Returns true if there is a transaction open with possible write
+        * Returns true if there is a transaction/round open with possible write
         * queries or transaction pre-commit/idle callbacks waiting on it to finish.
         * This does *not* count recurring callbacks, e.g. from setTransactionListener().
         *
@@ -1485,13 +1490,19 @@ interface IDatabase {
        /**
         * Run a callback as soon as there is no transaction pending.
         * If there is a transaction and it is rolled back, then the callback is cancelled.
+        *
+        * When transaction round mode (DBO_TRX) is set, the callback will run at the end
+        * of the round, just after all peer transactions COMMIT. If the transaction round
+        * is rolled back, then the callback is cancelled.
+        *
         * Queries in the function will run in AUTO-COMMIT mode unless there are begin() calls.
         * Callbacks must commit any transactions that they begin.
         *
         * This is useful for updates to different systems or when separate transactions are needed.
         * For example, one might want to enqueue jobs into a system outside the database, but only
         * after the database is updated so that the jobs will see the data when they actually run.
-        * It can also be used for updates that easily cause deadlocks if locks are held too long.
+        * It can also be used for updates that easily suffer from lock timeouts and deadlocks,
+        * but where atomicity is not essential.
         *
         * Updates will execute in the order they were enqueued.
         *
@@ -1507,10 +1518,15 @@ interface IDatabase {
        /**
         * Run a callback before the current transaction commits or now if there is none.
         * If there is a transaction and it is rolled back, then the callback is cancelled.
+        *
+        * When transaction round mode (DBO_TRX) is set, the callback will run at the end
+        * of the round, just before all peer transactions COMMIT. If the transaction round
+        * is rolled back, then the callback is cancelled.
+        *
         * Callbacks must not start nor commit any transactions. If no transaction is active,
         * then a transaction will wrap the callback.
         *
-        * This is useful for updates that easily cause deadlocks if locks are held too long
+        * This is useful for updates that easily suffer from lock timeouts and deadlocks,
         * but where atomicity is strongly desired for these updates and some related updates.
         *
         * Updates will execute in the order they were enqueued.
@@ -1541,11 +1557,11 @@ interface IDatabase {
        /**
         * Begin an atomic section of statements
         *
-        * If a transaction has been started already, sets a savepoint and tracks
-        * the given section name to make sure the transaction is not committed
-        * pre-maturely. This function can be used in layers (with sub-sections),
-        * so use a stack to keep track of the different atomic sections. If there
-        * is no transaction, one is started implicitly.
+        * If a transaction has been started already, (optionally) sets a savepoint
+        * and tracks the given section name to make sure the transaction is not
+        * committed pre-maturely. This function can be used in layers (with
+        * sub-sections), so use a stack to keep track of the different atomic
+        * sections. If there is no transaction, one is started implicitly.
         *
         * The goal of this function is to create an atomic section of SQL queries
         * without having to start a new transaction if it already exists.
@@ -1557,9 +1573,11 @@ interface IDatabase {
         *
         * @since 1.23
         * @param string $fname
+        * @param string $cancelable Pass self::ATOMIC_CANCELABLE to use a
+        *  savepoint and enable self::cancelAtomic() for this section.
         * @throws DBError
         */
-       public function startAtomic( $fname = __METHOD__ );
+       public function startAtomic( $fname = __METHOD__, $cancelable = self::ATOMIC_NOT_CANCELABLE );
 
        /**
         * Ends an atomic section of SQL statements
@@ -1587,6 +1605,8 @@ interface IDatabase {
         * Note that a call to IDatabase::rollback() will also roll back any open
         * atomic sections.
         *
+        * @note As a micro-optimization to save a few DB calls, this method may only
+        *  be called when startAtomic() was called with the ATOMIC_CANCELABLE flag.
         * @since 1.31
         * @see IDatabase::startAtomic
         * @param string $fname
@@ -1743,11 +1763,9 @@ interface IDatabase {
        public function ping( &$rtt = null );
 
        /**
-        * Get replica DB lag. Currently supported only by MySQL.
+        * Get the amount of replication lag for this database server
         *
-        * Note that this function will generate a fatal error on many
-        * installations. Most callers should use LoadBalancer::safeGetLag()
-        * instead.
+        * Callers should avoid using this method while a transaction is active
         *
         * @return int|bool Database replication lag in seconds or false on error
         * @throws DBError