[TYPO3-dev] Duplicate entry on cache_pagesection on reloading twice

Manuel Rego Casasnovas mrego at igalia.com
Thu Feb 21 10:59:01 CET 2008


Hello,

El mié, 20-02-2008 a las 15:31 +0100, Moreno Feltscher escribió:
> Does this works with dbal? "ON DUPLICATE KEY UPDATE" would be a risk
> in this case..

I don't know if it works with dbal. You can use it since MySQL 3.23 [1].

On the other hand, at the moment there is an important concurrence
problem at line 385 in [2].

The problematic lines:
384: $GLOBALS['TYPO3_DB']->exec_UPDATEquery('cache_pagesection',
'page_id=' . intval($GLOBALS['TSFE']->id) . ' AND mpvar_hash=' .
$mpvar_hash, $dbFields);
385: if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 0) {
386:    $dbFields['page_id'] = intval($GLOBALS['TSFE']->id);
387:    $dbFields['mpvar_hash'] = $mpvar_hash;
388:    $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_pagesection',
$dbFields);
389: }

The problem happens when two process try to do the UPDATE and its can't
do it. Then both process go into if and try to do two INSERT with the
same key.

This problem could happen with more than 2 process.

There are some possible solutions for these:
   * Use ON DUPLICATE KEY UPDATE, I think that this depends on database
or no.
   * Use transactions, maybe it depends on database.
   * Try to do the insert with @ to don't display erros and if there is
error do an UPDATE. This could be problems when you call to
"sql_affected_rows", I don't know if it returns the number of affected
rows for the last query for all database or only for the current
connection, I hope that this will be the second, in the first case we
can't use this function to check the error.

I've added a new patch to bug [3] with this new solution. I don't like
so much this solution because the error is happening anyway. However I'd
like a solution that doesn't depend on database.

What do you think about this concurrence problem?
What solution do you prefer?
Any other idea?

Best regards,
   Rego

[1] http://dev.mysql.com/doc/refman/4.1/en/insert.html
[2]
http://typo3.svn.sourceforge.net/viewvc/typo3/TYPO3core/trunk/t3lib/class.t3lib_tstemplate.php?revision=3044&view=markup
[3] http://bugs.typo3.org/view.php?id=7591

-- 
Manuel Rego Casasnovas 
Computer Science Engineer 
mailto:mrego at igalia.com 
Tel: +34 986 10 76 10 
Fax: +34 981 91 39 49 
Igalia - http://www.igalia.com



More information about the TYPO3-dev mailing list