Commit 6dff2378 authored by skummer's avatar skummer

ZP-551 #comment chunked foldersync

git-svn-id: https://z-push.org/svn/z-push/trunk@1908 b7dd7b3b-3a3c-0410-9da9-bee62a6cc5b5
parent a21f59c9
......@@ -67,6 +67,7 @@ class ASDevice extends StateObject {
'asversion' => false,
'ignoredmessages' => array(),
'announcedASversion' => false,
'foldersynccomplete' => true,
);
static private $loadedData;
......
......@@ -595,6 +595,11 @@ class DeviceManager {
* @return boolean
*/
public function IsHierarchyFullResyncRequired() {
// do not check for loop detection, if the foldersync is not yet complete
if ($this->GetFolderSyncComplete() === false) {
ZLog::Write(LOGLEVEL_INFO, "DeviceManager->IsHierarchyFullResyncRequired(): aborted, as exporting of folders has not yet completed");
return false;
}
// check for potential process loops like described in ZP-5
return $this->loopdetection->ProcessLoopDetectionIsHierarchyResyncRequired();
}
......@@ -695,6 +700,45 @@ class DeviceManager {
return true;
}
/**
* Returns the indicator if the FolderSync was completed successfully (all folders synchronized)
*
* @access public
* @return boolean
*/
public function GetFolderSyncComplete() {
return $this->device->GetFolderSyncComplete();
}
/**
* Sets if the FolderSync was completed successfully (all folders synchronized)
*
* @param boolean $complete indicating if all folders were sent
*
* @access public
* @return boolean
*/
public function SetFolderSyncComplete($complete, $user = false, $devid = false) {
$this->device->SetFolderSyncComplete($complete);
}
/**
* Removes the Loop detection data for a user & device
*
* @param string $user
* @param string $devid
*
* @access public
* @return boolean
*/
public function ClearLoopDetectionData($user, $devid) {
if ($user == false || $devid == false) {
return false;
}
ZLog::Write(LOGLEVEL_DEBUG, sprintf("DeviceManager->ClearLoopDetectionData(): clearing data for user '%s' and device '%s'", $user, $devid));
return $this->loopdetection->ClearData($user, $devid);
}
/**
* Indicates if the device needs an AS version update
*
......
......@@ -188,7 +188,34 @@ class FolderSync extends RequestProcessor {
$exporter->InitializeExporter($changesMem);
// Stream all changes to the ImportExportChangesMem
while(is_array($exporter->Synchronize()));
$totalChanges = $exporter->GetChangeCount();
$started = time();
$exported = 0;
$partial = false;
while(is_array($exporter->Synchronize())) {
$exported++;
if (time() % 4 ) {
self::$topCollector->AnnounceInformation(sprintf("Exported %d from %d folders", $exported, $totalChanges));
}
// stop if this takes more than 20 seconds
if ((time() - $started) > 200) {
ZLog::Write(LOGLEVEL_WARN, sprintf("Request->HandleFolderSync(): Exporting folders is too slow. In %d seconds only %d from %d changes were processed.",(time() - $started), $exported, $totalChanges));
self::$topCollector->AnnounceInformation(sprintf("Partial export of %d folders", $totalChanges), true);
self::$deviceManager->SetFolderSyncComplete(false);
$partial = true;
break;
}
}
// update the foldersync complete flag
if ($partial == false && self::$deviceManager->GetFolderSyncComplete() === false) {
// say that we are done with partial synching
self::$deviceManager->SetFolderSyncComplete(true);
// reset the loop data to prevent any loop detection to kick in now
self::$deviceManager->ClearLoopDetectionData(Request::GetAuthUser(), Request::GetDeviceId());
ZLog::Write(LOGLEVEL_INFO, "Request->HandleFolderSync(): Chunked exporting of folders completed successfully");
}
// get the new state from the backend
$newsyncstate = (isset($exporter))?$exporter->GetState():"";
......
......@@ -62,6 +62,16 @@ class Sync extends RequestProcessor {
$wbxmlproblem = false;
$emptysync = false;
// check if the hierarchySync was fully completed
if (self::$deviceManager->GetFolderSyncComplete() === false) {
ZLog::Write(LOGLEVEL_INFO, "Request->HandleSync(): Sync request aborted, as exporting of folders has not yet completed");
self::$topCollector->AnnounceInformation("Aborted due incomple folder sync", true);
$status = SYNC_STATUS_FOLDERHIERARCHYCHANGED;
}
else
ZLog::Write(LOGLEVEL_INFO, "Request->HandleSync(): FolderSync marked as complete");
// Start Synchronize
if(self::$decoder->getElementStartTag(SYNC_SYNCHRONIZE)) {
......
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