Explorar o código

Synchro: need to order the replicas by id for the split algorithm to work fine

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1734 a333f486-631f-4898-b8df-5754b55c2be0
romainq %!s(int64=13) %!d(string=hai) anos
pai
achega
88919ffcc6
Modificáronse 2 ficheiros con 22 adicións e 8 borrados
  1. 4 1
      core/metamodel.class.php
  2. 18 7
      synchro/synchrodatasource.class.inc.php

+ 4 - 1
core/metamodel.class.php

@@ -1989,7 +1989,10 @@ if (!array_key_exists($sAttCode, self::$m_aAttribDefs[$sClass]))
 		$aOrderSpec = array();
 		foreach ($aOrderBy as $sFieldAlias => $bAscending)
 		{
-			MyHelpers::CheckValueInArray('field name in ORDER BY spec', $sFieldAlias, self::GetAttributesList($oFilter->GetFirstJoinedClass()));
+			if ($sFieldAlias != 'id')
+			{
+				MyHelpers::CheckValueInArray('field name in ORDER BY spec', $sFieldAlias, self::GetAttributesList($oFilter->GetFirstJoinedClass()));
+			}
 			if (!is_bool($bAscending))
 			{
 				throw new CoreException("Wrong direction in ORDER BY spec, found '$bAscending' and expecting a boolean value");

+ 18 - 7
synchro/synchrodatasource.class.inc.php

@@ -2361,7 +2361,15 @@ class SynchroExecution
 				$aArguments['step_count'] = $iStepCount;
 				$iStepCount++;
 
+				$this->m_oStatLog->AddTrace("Launching a separate process: step $iStepCount");
+
 				list ($iRes, $aOut) = utils::ExecITopScript('synchro/priv_sync_chunk.php', $aArguments);
+
+				$this->m_oStatLog->AddTrace("The script replied:");
+				foreach ($aOut as $sOut)
+				{
+					$this->m_oStatLog->AddTrace(">>> $sOut");
+				}
 	
 				$sLastRes = strtolower(trim(end($aOut)));
 				$bContinue = ($sLastRes == 'continue');
@@ -2447,8 +2455,9 @@ class SynchroExecution
 
 			if ($iMaxReplica)
 			{
-				// Re-build the object set and set a LIMIT
-				$oSetToProcess = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToObsolete), array() /* order by*/, array('source_id' => $this->m_oDataSource->GetKey(), 'last_import' => $sLimitDate, 'curr_pos' => $iCurrPos));
+				// Consider a given subset, starting from replica iCurrPos, limited to the count of iMaxReplica
+				// The replica have to be ordered by id
+				$oSetToProcess = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToObsolete), array('id'=>true) /* order by*/, array('source_id' => $this->m_oDataSource->GetKey(), 'last_import' => $sLimitDate, 'curr_pos' => $iCurrPos));
 				$oSetToProcess->SetLimit($iMaxReplica);
 			}
 			else
@@ -2542,8 +2551,9 @@ class SynchroExecution
 
 		if ($iMaxReplica)
 		{
-			// Re-build the object set and set a LIMIT
-			$oSetToProcess = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToSync), array() /* order by*/, array('source_id' => $this->m_oDataSource->GetKey(), 'last_import' => $sLimitDate, 'curr_pos' => $iCurrPos), $this->m_aExtDataSpec);
+			// Consider a given subset, starting from replica iCurrPos, limited to the count of iMaxReplica
+			// The replica have to be ordered by id
+			$oSetToProcess = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToSync), array('id'=>true) /* order by*/, array('source_id' => $this->m_oDataSource->GetKey(), 'last_import' => $sLimitDate, 'curr_pos' => $iCurrPos), $this->m_aExtDataSpec);
 			$oSetToProcess->SetLimit($iMaxReplica);
 		}
 		else
@@ -2608,14 +2618,15 @@ class SynchroExecution
 		{
 			$this->m_oStatLog->AddTrace("Deletion date: $sDeletionDate");
 		}
-		$sSelectToDelete  = "SELECT SynchroReplica WHERE id > :curr_pos AND sync_source_id = :source_id AND status IN ('obsolete') AND status_last_seen < :last_import";
+		$sSelectToDelete = "SELECT SynchroReplica WHERE id > :curr_pos AND sync_source_id = :source_id AND status IN ('obsolete') AND status_last_seen < :last_import";
 		$oSetScope = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToDelete), array() /* order by*/, array('source_id' => $this->m_oDataSource->GetKey(), 'last_import' => $sDeletionDate, 'curr_pos' => $iCurrPos));
 		$iCountScope = $oSetScope->Count();
 
 		if ($iMaxReplica)
 		{
-			// Re-build the object set and set a LIMIT
-			$oSetToProcess = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToDelete), array() /* order by*/, array('source_id' => $this->m_oDataSource->GetKey(), 'last_import' => $sDeletionDate, 'curr_pos' => $iCurrPos));
+			// Consider a given subset, starting from replica iCurrPos, limited to the count of iMaxReplica
+			// The replica have to be ordered by id
+			$oSetToProcess = new DBObjectSet(DBObjectSearch::FromOQL($sSelectToDelete), array('id'=>true) /* order by*/, array('source_id' => $this->m_oDataSource->GetKey(), 'last_import' => $sDeletionDate, 'curr_pos' => $iCurrPos));
 			$oSetToProcess->SetLimit($iMaxReplica);
 		}
 		else