<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3ADB_layer_2.0_delegated_transactions</id>
	<title>Development:DB layer 2.0 delegated transactions - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3ADB_layer_2.0_delegated_transactions"/>
	<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:DB_layer_2.0_delegated_transactions&amp;action=history"/>
	<updated>2026-05-06T19:44:13Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:DB_layer_2.0_delegated_transactions&amp;diff=10982&amp;oldid=prev</id>
		<title>Олег Давидович: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:DB_layer_2.0_delegated_transactions&amp;diff=10982&amp;oldid=prev"/>
		<updated>2024-10-21T08:51:08Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 08:51, 21 октября 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Олег Давидович</name></author>
	</entry>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:DB_layer_2.0_delegated_transactions&amp;diff=10981&amp;oldid=prev</id>
		<title>1&gt;Skodak: /* The Flow */</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:DB_layer_2.0_delegated_transactions&amp;diff=10981&amp;oldid=prev"/>
		<updated>2009-11-08T20:20:08Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;The Flow&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Work in progress}}{{Template:Development:dmllib 2.0}}{{Moodle_2.0}}__NOTOC__&lt;br /&gt;
=== General principles ===&lt;br /&gt;
&lt;br /&gt;
# Everybody thinks it&amp;#039;s a good idea to have those logical nested transactions in Moodle (but me and ML)&lt;br /&gt;
# No matter of they nested nature, they are really &amp;#039;&amp;#039;&amp;#039;&amp;quot;delegated transactions&amp;quot;&amp;#039;&amp;#039;&amp;#039; (so outer levels get the control over inner ones), so we are going to apply that naming to enforce the real concept.&lt;br /&gt;
# Code will &amp;#039;&amp;#039;&amp;#039;never&amp;#039;&amp;#039;&amp;#039; rely on rollback happening. it&amp;#039;s only a maeasure to reduce (not to eliminate) DB garbled information.&lt;br /&gt;
# Any problem related with the use of transactions (unfinished ones,  unbalanced, finished twice...) will end &amp;#039;&amp;#039;&amp;#039;always&amp;#039;&amp;#039;&amp;#039; with one transaction_exception that will &amp;#039;&amp;#039;&amp;#039;always&amp;#039;&amp;#039;&amp;#039; end performing one DB rollback.  &lt;br /&gt;
# If one transaction (at any level) has been marked for rollback() there won&amp;#039;t be any method to change it. Finally Moodle will perform the DB rollback.&lt;br /&gt;
# If one transaction (at any level) has been marked for commit() it will be possible to change that status to rollback() in any outer level.&lt;br /&gt;
# It will be &amp;#039;&amp;#039;&amp;#039;optional&amp;#039;&amp;#039;&amp;#039; to catch exceptions when using transactions, but if they are caught, then it&amp;#039;s mandatory to mark the transaction for rollback()&lt;br /&gt;
# Any explicit rollback() call will pass the exception originating it, i.e. rollback($exception) to be re-thrown.&lt;br /&gt;
# API will work in a natural and similar fashion to current recordsets one.&lt;br /&gt;
# We&amp;#039;ll start &amp;#039;&amp;#039;&amp;#039;recommending&amp;#039;&amp;#039;&amp;#039; to use InnoDB for 2.0 in environmental tests. Posibly, at some point in the future that will become a &amp;#039;&amp;#039;&amp;#039;must&amp;#039;&amp;#039;&amp;#039;. But &amp;#039;&amp;#039;&amp;#039;it is not&amp;#039;&amp;#039;&amp;#039; for now (be warned!).&lt;br /&gt;
&lt;br /&gt;
=== The API ===&lt;br /&gt;
&lt;br /&gt;
# All the handling must go, exclusively, to moodle_database object, leaving real drivers only implementing (protected) the old begin/commit/rollback_sql() functions.&lt;br /&gt;
# One array of objects of type moodle_delegated_transaction will be stored / checked from $DB&lt;br /&gt;
# $DB will be the responsible to instantiate / accumulate / pair / compare moodle_delegated_transactions&lt;br /&gt;
# Each moodle_transaction will be able to set the global mark for rollback. Commit won&amp;#039;t change anything.&lt;br /&gt;
# Inner-most commit/rollback will printout one complete stack of moodle_transactions information if we are under DEBUG_DEVELOPER and new setting (delegatedtransactionsdebug) is enabled.&lt;br /&gt;
# Normal usage of the moodle_transaction will be:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$transaction = $DB-&amp;gt;start_delegated_transaction();&lt;br /&gt;
// Perform some $DB stuff&lt;br /&gt;
$transaction-&amp;gt;allow_commit();&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
7. If, for any reason, developer needs to catch exceptions when using transactions, it will be mandatory to use it in this way:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
try {&lt;br /&gt;
    $transaction = $DB-&amp;gt;start_delegated_transaction();&lt;br /&gt;
    // Perform some $DB stuff&lt;br /&gt;
    $transaction-&amp;gt;allow_commit();&lt;br /&gt;
} catch (Exception $e) {&lt;br /&gt;
    //extra cleanup steps&lt;br /&gt;
    $transaction-&amp;gt;rollback($e); // rethrows exception&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
8. In order to be able to keep some parts of code out from top transactions completely, if we know it can lead to problems, we can use:&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
 $DB-&amp;gt;transactions_forbidden(); // Instant check to confirm we aren&amp;#039;t using transactions in this point. Will throw exception if transaction is found.&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The Flow===&lt;br /&gt;
&lt;br /&gt;
[[Image:TransactionsAndExceptionsFlow.png|thumb|right|caption]]&lt;br /&gt;
# Any default exception handler will:&lt;br /&gt;
## Catch uncaught transaction_exception exceptions, &lt;br /&gt;
## Properly perform the DB rollback&lt;br /&gt;
## debug/error/log honouring related settings.&lt;br /&gt;
## inform with as many details as possible (token, place... whatever).&lt;br /&gt;
# Any &amp;quot;footer&amp;quot; (meaning some place before ending &amp;lt;html&amp;gt; output) will:&lt;br /&gt;
## Detect &amp;quot;in-transaction&amp;quot; status.&lt;br /&gt;
## Let execution continue, transaction is automatically rolled back in $DB-&amp;gt;dispose()&lt;br /&gt;
## inform with as many details as possible (token, place... whatever).&lt;br /&gt;
# $DB-&amp;gt;dispose() will:&lt;br /&gt;
## Detect &amp;quot;in-transaction&amp;quot; status.&lt;br /&gt;
## log error (not possible to honour settings!)&lt;br /&gt;
## Properly perform the full DB rollback&lt;br /&gt;
&lt;br /&gt;
===Related tasks===&lt;br /&gt;
&lt;br /&gt;
# Move this to MoodleDocs and publicy in Dev Forum.&lt;br /&gt;
# Implement fulfilling current specs / review / test iterations&lt;br /&gt;
# Re-enforce in Docs, phpdocs, everywhere, the &amp;quot;Code will *never* rely on rollback happening&amp;quot; and the &amp;quot;delegated&amp;quot; nature of the whole thing.&lt;br /&gt;
# Be extremely careful about any use of delegated transactions until we get used to them, reviewing them in core often.&lt;br /&gt;
# Point somewhere about the move to InnoDB, pros/cons, migration process... to have it documented.&lt;/div&gt;</summary>
		<author><name>1&gt;Skodak</name></author>
	</entry>
</feed>