Просмотр исходного кода

#3330 MySQL deadlocks when InnoDB is used: resized files atime update

Alex Trofimov 5 лет назад
Родитель
Сommit
efe269414f
2 измененных файлов с 11 добавлено и 1 удалено
  1. 5 1
      inc/classes/BxDolTranscoder.php
  2. 6 0
      inc/classes/BxDolTranscoderQuery.php

+ 5 - 1
inc/classes/BxDolTranscoder.php

@@ -13,7 +13,11 @@ define('BX_DOL_QUEUE_COMPLETE', 'complete'); ///< file is already processed
 define('BX_DOL_QUEUE_FAILED', 'failed'); ///< file processing was failed
 define('BX_DOL_QUEUE_DELETE', 'delete'); ///< file is subject to delete
 
-define('BX_DOL_MAX_RETINA_DIMENSION_MOBILE', 500); ///< max image dimension which will be processes as retine on mobiles
+if (!defined('BX_DOL_MAX_RETINA_DIMENSION_MOBILE'))
+    define('BX_DOL_MAX_RETINA_DIMENSION_MOBILE', 500); ///< max image dimension which will be processes as retine on mobiles
+
+if (!defined('BX_DOL_SKIP_ATIME_UPDATE'))
+    define('BX_DOL_SKIP_ATIME_UPDATE', 43200); ///< time interval to not update last access time, it should be comaparatively low compared to atime_prining
 
 /**
  * Base class for @see BxDolTranscoderImage and @see BxDolTranscoderVideo transcoders

+ 6 - 0
inc/classes/BxDolTranscoderQuery.php

@@ -93,9 +93,15 @@ class BxDolTranscoderQuery extends BxDolDb
     public function updateAccessTime($mixedHandler)
     {
         $iTime = time();
+
+        if ($this->getOne("SELECT `atime` FROM {$this->_sTableFiles} WHERE `transcoder_object` = :obj AND `handler` = :hndl AND `atime` > :ts LIMIT 1", array('obj' => $this->_aObject['object'], 'hndl' => (string)$mixedHandler, 'ts' => $iTime - BX_DOL_SKIP_ATIME_UPDATE))) // avoid deadlocks by making changes less frequent
+            return true;
+
         $sQuery = $this->prepare("UPDATE {$this->_sTableFiles} SET `atime` = ? WHERE `transcoder_object` = ? AND `handler` = ? LIMIT 1", $iTime, $this->_aObject['object'], (string)$mixedHandler);
         $mixedRes = $this->res($sQuery);
+
         $this->setReadOnlyMode(true);
+
         return $mixedRes;
     }