Commit 33d61e2a authored by skummer's avatar skummer

ZP-249 #comment Mark a state as "used" for heartbeat when data is imported....

ZP-249 #comment Mark a state as "used" for heartbeat when data is imported. Heartbeat should return an invalid state when an imports happenes on an observed folder. #time 3h

git-svn-id: https://z-push.org/svn/z-push/trunk@1557 b7dd7b3b-3a3c-0410-9da9-bee62a6cc5b5
parent a9acf7dd
......@@ -607,7 +607,7 @@ class DeviceManager {
}
/**
* Checks if the given counter for a certain uuid+folderid was exported before.
* Checks if the given counter for a certain uuid+folderid was already exported or modified.
* This is called when a heartbeat request found changes to make sure that the same
* changes are not exported twice, as during the heartbeat there could have been a normal
* sync request.
......@@ -623,6 +623,21 @@ class DeviceManager {
return $this->loopdetection->IsSyncStateObsolete($folderid, $uuid, $counter);
}
/**
* Marks a syncstate as obsolete for Heartbeat, as e.g. an import was started using it.
*
* @param string $folderid folder id
* @param string $uuid synkkey
* @param string $counter synckey counter
* @param int $flags
*
* @access public
* @return
*/
public function SetHeartbeatStateIntegrity($folderid, $uuid, $counter, $flags = 1) {
return $this->loopdetection->SetSyncStateUsage($folderid, $uuid, $counter, $flags);
}
/**
* Indicates if the device needs an AS version update
*
......
......@@ -476,6 +476,43 @@ class LoopDetection extends InterProcessData {
return $okIds;
}
/**
* Marks a SyncState as "already used", e.g. when an import process started.
* This is most critical for DiffBackends, as an imported message would be exported again
* in the heartbeat if the notification is triggered before the import is complete.
*
* @param string $folderid folder id
* @param string $uuid synkkey
* @param string $counter synckey counter
* @param int $flags
*
* @access public
* @return boolean
*/
public function SetSyncStateUsage($folderid, $uuid, $counter, $flags) {
// initialize params
$this->InitializeParams();
// exclusive block
if ($this->blockMutex()) {
$loopdata = ($this->hasData()) ? $this->getData() : array();
// check and initialize the array structure
$this->checkArrayStructure($loopdata, $folderid);
$current = $loopdata[self::$devid][self::$user][$folderid];
// update the usage flag
$current["usage"] = $flags;
// update loop data
$loopdata[self::$devid][self::$user][$folderid] = $current;
$ok = $this->setData($loopdata);
$this->releaseMutex();
}
// end exclusive block
}
/**
* Checks if the given counter for a certain uuid+folderid was exported before.
* Returns also true if the counter are the same but previously there were
......@@ -516,6 +553,12 @@ class LoopDetection extends InterProcessData {
ZLog::Write(LOGLEVEL_DEBUG, "LoopDetection->IsSyncStateObsolete(): yes, counter already processed");
$obsolete = true;
}
if (isset($current["usage"]) && $current["uuid"] == $uuid && $current["count"] == $counter) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("LoopDetection->IsSyncStateObsolete(): yes, state is already in use, flag: %d", $current["usage"]));
$obsolete = true;
}
}
}
......
......@@ -1046,6 +1046,9 @@ class Sync extends RequestProcessor {
if ($this->importer == false)
throw StatusException(sprintf("Sync->importMessage(): importer not available", SYNC_STATUS_SERVERERROR));
// mark this state as used, e.g. for HeartBeat
self::$deviceManager->SetHeartbeatStateIntegrity($spa->GetFolderId(), $spa->GetUuid(), $spa->GetUuidCounter());
// Detect incoming loop
// messages which were created/removed before will not have the same action executed again
// if a message is edited we perform this action "again", as the message could have been changed on the mobile in the meantime
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment