Parent5446 has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/90856


Change subject: Added DatabaseBase::startAtomic and endAtomic
......................................................................

Added DatabaseBase::startAtomic and endAtomic

Added new functions to ensure certain groups of statements
are atomic without having to go through the trouble of
starting a new transaction if one has already been opened.

Change-Id: I5328fb337e5544bf28ea282860ef8f81e19ac43c
---
M includes/db/Database.php
1 file changed, 55 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/56/90856/1

diff --git a/includes/db/Database.php b/includes/db/Database.php
index c3850b9..5cd914d 100644
--- a/includes/db/Database.php
+++ b/includes/db/Database.php
@@ -282,6 +282,20 @@
        private $mTrxAutomatic = false;
 
        /**
+        * Array of levels of atomicity within transactions
+        *
+        * @var Array
+        */
+       private $mTrxAtomicLevels = array();
+
+       /**
+        * Record if the current transaction was started implicitly by 
DatabaseBase::startAtomic
+        *
+        * @var Bool
+        */
+       private $mTrxAutomaticAtomic = false;
+
+       /**
         * @since 1.21
         * @var file handle for upgrade
         */
@@ -3185,6 +3199,28 @@
        }
 
        /**
+        * Begin an atomic section of statements
+        *
+        * If a transaction has been started already, just keep track of the 
given
+        * section name to make sure the transaction is not committed 
pre-maturely.
+        * If there is no transaction, start one.
+        *
+        * 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.
+        *
+        * @param string $fname
+        */
+       final public function startAtomic( $fname = __METHOD__ ) {
+               array_push( $this->mTrxAtomicLevels, $fname );
+
+               if ( !$this->mTrxLevel ) {
+                       $this->begin( $fname );
+                       $this->mTrxAutomatic = true;
+                       $this->mTrxAutomaticAtomic = true;
+               }
+       }
+
+       /**
         * Begin a transaction. If a transaction is already in progress, that 
transaction will be committed before the
         * new transaction is started.
         *
@@ -3243,6 +3279,25 @@
        }
 
        /**
+        * Ends an atomic section of SQL statements
+        *
+        * Ends the next section of atomic SQL statements and commits the 
transaction
+        * if necessary.
+        *
+        * @param string $fname
+        */
+       final public function endAtomic( $fname = __METHOD__ ) {
+               $lastFname = array_pop( $this->mTrxAtomicLevels );
+               if ( $lastFname !== $fname ) {
+                       throw new MWException( 'Invalid atomic section ended.' 
);
+               }
+
+               if ( !$this->mTrxAtomicLevels && $this->mTrxAutomaticAtomic ) {
+                       $this->commit( $fname, 'flush' );
+               }
+       }
+
+       /**
         * Commits a transaction previously started using begin().
         * If no transaction is in progress, a warning is issued.
         *

-- 
To view, visit https://gerrit.wikimedia.org/r/90856
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5328fb337e5544bf28ea282860ef8f81e19ac43c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Parent5446 <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to