mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Log database deadlocks in EventIssue
This commit is contained in:
@@ -661,6 +661,7 @@ class CMDBSource
|
|||||||
}
|
}
|
||||||
catch (mysqli_sql_exception $e)
|
catch (mysqli_sql_exception $e)
|
||||||
{
|
{
|
||||||
|
self::LogDeadLock($e);
|
||||||
throw new MySQLException('Failed to issue SQL query', array('query' => $sSql, $e));
|
throw new MySQLException('Failed to issue SQL query', array('query' => $sSql, $e));
|
||||||
}
|
}
|
||||||
$oKPI->ComputeStats('Query exec (mySQL)', $sSql);
|
$oKPI->ComputeStats('Query exec (mySQL)', $sSql);
|
||||||
@@ -674,13 +675,65 @@ class CMDBSource
|
|||||||
{
|
{
|
||||||
throw new MySQLHasGoneAwayException(self::GetError(), $aContext);
|
throw new MySQLHasGoneAwayException(self::GetError(), $aContext);
|
||||||
}
|
}
|
||||||
|
$e = new MySQLException('Failed to issue SQL query', $aContext);
|
||||||
throw new MySQLException('Failed to issue SQL query', $aContext);
|
self::LogDeadLock($e);
|
||||||
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $oResult;
|
return $oResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function LogDeadLock(Exception $e)
|
||||||
|
{
|
||||||
|
// Deadlock detection
|
||||||
|
$iMySqlErrorNo = self::$m_oMysqli->errno;
|
||||||
|
if (($iMySqlErrorNo == 1213) || ($iMySqlErrorNo == 1205))
|
||||||
|
{
|
||||||
|
// Try to log the deadlock
|
||||||
|
$oError = self::$m_oMysqli->query("SHOW ENGINE INNODB STATUS");
|
||||||
|
$aData = array();
|
||||||
|
if ($oError !== false)
|
||||||
|
{
|
||||||
|
$aData = $oError->fetch_all(MYSQLI_ASSOC);
|
||||||
|
}
|
||||||
|
if (MetaModel::IsLogEnabledIssue())
|
||||||
|
{
|
||||||
|
if (MetaModel::IsValidClass('EventIssue'))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$bInTransaction = self::IsInsideTransaction();
|
||||||
|
if ($bInTransaction)
|
||||||
|
{
|
||||||
|
// In order to log the error, we have to rollback the current transaction
|
||||||
|
// Else the caller will rollback our log
|
||||||
|
self::DBQuery('ROLLBACK');
|
||||||
|
}
|
||||||
|
$oLog = new EventIssue();
|
||||||
|
$oLog->Set('message', $e->getMessage());
|
||||||
|
$oLog->Set('userinfo', UserRights::GetUser());
|
||||||
|
$oLog->Set('issue', 'Database DeadLock');
|
||||||
|
$oLog->Set('impact', 'Request execution failed');
|
||||||
|
$oLog->Set('callstack', $e->getTrace());
|
||||||
|
$oLog->Set('data', $aData[0]);
|
||||||
|
$oLog->DBInsertNoReload();
|
||||||
|
if ($bInTransaction)
|
||||||
|
{
|
||||||
|
self::DBQuery('START TRANSACTION');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception $e1)
|
||||||
|
{
|
||||||
|
IssueLog::Error("Failed to log database deadlock issue into the DB\n".$e1->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IssueLog::Error($e->getMessage());
|
||||||
|
IssueLog::Error(print_r($aData[0], true));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If nested transaction, we are not starting a new one : only one global transaction will exist.
|
* If nested transaction, we are not starting a new one : only one global transaction will exist.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ class EventIssue extends Event
|
|||||||
MetaModel::Init_AddAttribute(new AttributePropertySet("data", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
|
MetaModel::Init_AddAttribute(new AttributePropertySet("data", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
|
||||||
|
|
||||||
// Display lists
|
// Display lists
|
||||||
MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'issue', 'impact', 'page', 'arguments_post', 'arguments_get', 'callstack', 'data')); // Attributes to be displayed for the complete details
|
MetaModel::Init_SetZListItems('details', array('date', 'message', 'userinfo', 'issue', 'impact', 'page', 'arguments_post', 'arguments_get', 'callstack', 'data')); // Attributes to be displayed for the complete details
|
||||||
MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'issue', 'impact')); // Attributes to be displayed for a list
|
MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'issue', 'impact')); // Attributes to be displayed for a list
|
||||||
// Search criteria
|
// Search criteria
|
||||||
// MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
|
// MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
|
||||||
|
|||||||
Reference in New Issue
Block a user