Missing wait lock timeout when processing in magento pdo_mysql adapter?

If I compare the two classes of the Magento adapter Varien_Db_Adapter_Mysqli and Varien_Db_Adapter_Pdo_Mysql , I can find some differences in the exception handling of the query request from the raw_query method.

<?php class Varien_Db_Adapter_Mysqli extends Zend_Db_Adapter_Mysqli { //.... /** * Run RAW Query * * @param string $sql * @return Zend_Db_Statement_Interface */ public function raw_query($sql) { $timeoutMessage = 'SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction'; $tries = 0; do { $retry = false; try { $this->clear_result(); $result = $this->getConnection()->query($sql); $this->clear_result(); } catch (Exception $e) { if ($tries < 10 && $e->getMessage() == $timeoutMessage) { $retry = true; $tries++; } else { throw $e; } } } while ($retry); return $result; } //.... } 

If I compare this with the equal method in Varien_Db_Adapter_Pdo_Mysql, I will find other error handling. It does not check for wait times, but for lost connections.

 <?php class Varien_Db_Adapter_Pdo_Mysql extends Zend_Db_Adapter_Pdo_Mysql implements Varien_Db_Adapter_Interface { //.... /** * Run RAW Query * * @param string $sql * @return Zend_Db_Statement_Interface * @throws PDOException */ public function raw_query($sql) { $lostConnectionMessage = 'SQLSTATE[HY000]: General error: 2013 Lost connection to MySQL server during query'; $tries = 0; do { $retry = false; try { $result = $this->query($sql); } catch (Exception $e) { // Convert to PDOException to maintain backwards compatibility with usage of MySQL adapter if ($e instanceof Zend_Db_Statement_Exception) { $e = $e->getPrevious(); if (!($e instanceof PDOException)) { $e = new PDOException($e->getMessage(), $e->getCode()); } } // Check to reconnect if ($tries < 10 && $e->getMessage() == $lostConnectionMessage) { $retry = true; $tries++; } else { throw $e; } } } while ($retry); return $result; } //.... } 

It is right? Wouldn't it be better to check both cases of failure?

Example:

 /** * Run RAW Query * * @param string $sql * @return Zend_Db_Statement_Interface * @throws PDOException */ public function raw_query($sql) { $lostConnectionMessages = array( 'SQLSTATE[HY000]: General error: 2013 Lost connection to MySQL server during query', 'SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction', ); $tries = 0; do { $retry = false; try { $result = $this->query($sql); } catch (Exception $e) { // Convert to PDOException to maintain backwards compatibility with usage of MySQL adapter if ($e instanceof Zend_Db_Statement_Exception) { $e = $e->getPrevious(); if (!($e instanceof PDOException)) { $e = new PDOException($e->getMessage(), $e->getCode()); } } // Check to reconnect if ($tries < 10 && in_array($e->getMessage(), $lostConnectionMessages)) { $retry = true; $tries++; } else { throw $e; } } } while ($retry); return $result; } 
+6
source share
2 answers

I would say yes, they should check this too. In Magento2, they even deleted the reconnected connection , but it is still present in the MysqlI adapter.

+2
source

It depends (always a good answer :)

I think that a lost connection should be considered an error in the system setup. The Varien_Db_Adapter_Pdo_Mysql method works around it, hides the origin of slow queries. I would rather see a real exception, after which Magento will try to automatically reconnect.

The same can be said of the lock wait timeout. I want to know if such timeouts occur. Disguising them with automatic repetitions can cause errors to “go away,” but without fixing the real problems.

Such an automatic recovery code should at least be configured using some option in the system configuration, for example, "Enable DB query recovery mode" or something like that, and is "disabled" by default.

+2
source

Source: https://habr.com/ru/post/919872/


All Articles