May i barge into this discussion a bit.... and please, feel free to shut me down if i'm missing a point here.
I'm failing to see why all this debate. We already have transactions, we have begin, commit and rollback in the abstraction (Database.php lines 2830+). And this works. All that needs to be done is extending this functonality without breaking the existing MO which maintains a single transaction level.
Daniel, you have the same issue as Akshay has in his extension, which is the fact that doEdit closes a transation before you complete the whole editing process. So you don't need nested transactions as such ... just a way to prevent core from commiting if your extension spans over multiple core transactions and taking over the commiting/rollingback by yourself ... basically what you need is this (not sure about PG compatibility here):
public function begin( $fname = 'DatabaseBase::begin', $maskTransaction ) { if ( $this->mTrxLevel < 2 ) { $this->query( 'BEGIN', $fname ); $this->mTrxLevel = 1; // this is here just to make sure that begin works the same way as now when on txLevel = 1 if ( $maskTransaction ) { $this->mTrxLevel++; } } else { $this->mTrxLevel++; $this->query( 'SAVEPOINT SP'.$this->mTrxLevel, $fname ); }
}
public function commit( $fname = 'DatabaseBase::commit', $doGlobally = false ) { if ( $this->mTrxLevel == 1 || $this->mTrxLevel == 2 || $doGlobally ) { $this->query( 'COMMIT', $fname ); $this->mTrxLevel = 0; } else { $this->mTrxLevel--; } }
public function rollback( $fname = 'DatabaseBase::rollback', $doGlobally = false ) { if ( $this->mTrxLevel == 1|| $this->mTrxLevel == 2 || $doGlobally ) { $this->query( 'ROLLBACK', $fname, true ); $this->mTrxLevel = 0; } elseif ( $this->txLevel > 0 ) { $this->query( 'ROLLBACK TO SAVEPOINT SP'.$this->mTrxLevel, $fname, true ); $this->mTrxLevel--; } }
This should not change anything in core, and an extension gets a way to block core's commits and restarts of an already open transaction. I've added the savepoints-foo, just to have a complete solution.
So what's so drastic about such change? Why all this debate?
On 08/28/2012 09:16 AM, Daniel Kinzler wrote:
On 28.08.2012 06:16, Aaron Schulz wrote:
I'd have to see what you are doing to see if rollback is really needed.
As far as I see, nested transactions are needed, but no rollback. at least not from our side.
So, for that case, a simple counter would be sufficient. I still wonder why that feature got removed from the code.
-- daniel
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l