瀏覽代碼

Make sure that the SQL mutexes are specific to the current iTop instance, but still preserving the capability for the setup to detect an already running cron job with or without a valid config file.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3591 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 10 年之前
父節點
當前提交
5551f50e4e

+ 12 - 2
core/mutex.class.inc.php

@@ -37,8 +37,19 @@ class iTopMutex
 	public function __construct($sName, $sDBHost = null, $sDBUser = null, $sDBPwd = null)
 	{
 		// Compute the name of a lock for mysql
-		// Note: the name is server-wide!!!
+		// Note: names are server-wide!!! So let's make the name specific to this iTop instance
+		$oConfig = utils::GetConfig(); // Will return an empty config when called during the setup
+		$sDBName = $oConfig->GetDBName();
+		$sDBSubname = $oConfig->GetDBSubname();
 		$this->sName = 'itop.'.$sName;
+		if (substr($sName, -strlen($sDBName.$sDBSubname)) != $sDBName.$sDBSubname)
+		{
+			// If the name supplied already ends with the expected suffix
+			// don't add it twice, since the setup may try to detect an already
+			// running cron job by its mutex, without knowing if the config already exists or not
+			$this->sName .= $sDBName.$sDBSubname;
+		}
+		
 		$this->bLocked = false; // Not yet locked
 
 		if (!array_key_exists($this->sName, self::$aAcquiredLocks))
@@ -48,7 +59,6 @@ class iTopMutex
 
 		// It is a MUST to create a dedicated session each time a lock is required, because
 		// using GET_LOCK anytime on the same session will RELEASE the current and unique session lock (known issue)
-		$oConfig = utils::GetConfig();
 		$sDBHost = is_null($sDBHost) ? $oConfig->GetDBHost() : $sDBHost;
 		$sDBUser = is_null($sDBUser) ? $oConfig->GetDBUser() : $sDBUser;
 		$sDBPwd = is_null($sDBPwd) ? $oConfig->GetDBPwd() : $sDBPwd;

+ 1 - 1
setup/wizardsteps.class.inc.php

@@ -618,7 +618,7 @@ EOF
 			);	
 
 			$oMutex = new iTopMutex(
-				'cron.'.$this->oWizard->GetParameter('db_name', '').'_'.$this->oWizard->GetParameter('db_prefix', ''),
+				'cron'.$this->oWizard->GetParameter('db_name', '').$this->oWizard->GetParameter('db_prefix', ''),
 				$this->oWizard->GetParameter('db_server', ''),
 				$this->oWizard->GetParameter('db_user', ''),
 				$this->oWizard->GetParameter('db_pwd', '')

+ 1 - 1
synchro/synchro_import.php

@@ -468,7 +468,7 @@ try
 	   // Prepare insert columns
 		$sInsertColumns = '`'.implode('`, `', $aInputColumns).'`';
 	
-		$oMutex = new iTopMutex('synchro_import_'.$oDataSource->GetKey().'_'.MetaModel::GetConfig()->GetDBName().'_'.MetaModel::GetConfig()->GetDBSubname());
+		$oMutex = new iTopMutex('synchro_import_'.$oDataSource->GetKey());
 		$oMutex->Lock();
 		foreach($aData as $iRow => $aRow)
 	  	{

+ 1 - 1
synchro/synchrodatasource.class.inc.php

@@ -2415,7 +2415,7 @@ class SynchroExecution
 
 		self::$m_oCurrentTask = $this->m_oDataSource;
 
-		$oMutex = new iTopMutex('synchro_process_'.$this->m_oDataSource->GetKey().'_'.MetaModel::GetConfig()->GetDBName().'_'.MetaModel::GetConfig()->GetDBSubname());
+		$oMutex = new iTopMutex('synchro_process_'.$this->m_oDataSource->GetKey());
 		try
 		{
 			$oMutex->Lock();

+ 1 - 1
webservices/cron.php

@@ -354,7 +354,7 @@ $oP->p("Starting: ".time().' ('.date('Y-m-d H:i:s').')');
 try
 {
 	$oConfig = utils::GetConfig();
-	$oMutex = new iTopMutex('cron.'.$oConfig->GetDBName().'_'.$oConfig->GetDBSubname());
+	$oMutex = new iTopMutex('cron');
 	if ($oMutex->TryLock())
 	{
 		// Note: testing this now in case some of the background processes forces the read-only mode for a while