Commit 967a0c36 authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-697 Honour global window size. Released under the Affero GNU General

Public License (AGPL) version 3.
parent 0dbd04af
......@@ -334,11 +334,11 @@ class SyncCollections implements Iterator {
* in a case of a heartbeat and/or partial sync
*
* @access public
* @return int/boolean returns false if not set or not available
* @return int/boolean returns 512 (max) if not set or not available
*/
public function GetGlobalWindowSize() {
if (!isset($this->globalWindowSize))
return false;
return 512;
return $this->globalWindowSize;
}
......
......@@ -61,6 +61,7 @@ class Sync extends RequestProcessor {
$status = SYNC_STATUS_SUCCESS;
$wbxmlproblem = false;
$emptysync = false;
$globallyExportedItems = 0;
// check if the hierarchySync was fully completed
......@@ -522,6 +523,7 @@ class Sync extends RequestProcessor {
if (self::$decoder->getElementStartTag(SYNC_WINDOWSIZE)) {
$sc->SetGlobalWindowSize(self::$decoder->getElementContent());
ZLog::Write(LOGLEVEL_DEBUG, "Sync(): Global WindowSize requested: ". $sc->GetGlobalWindowSize());
if(!self::$decoder->getElementEndTag()) // SYNC_WINDOWSIZE
return false;
}
......@@ -570,10 +572,6 @@ class Sync extends RequestProcessor {
// manually set getchanges parameter for this collection
$sc->AddParameter($spa, "getchanges", true);
// set new global windowsize without marking the SPA as changed
if ($sc->GetGlobalWindowSize())
$spa->SetWindowSize($sc->GetGlobalWindowSize(), false);
// announce WindowSize to DeviceManager
self::$deviceManager->SetWindowSize($folderid, $spa->GetWindowSize());
}
......@@ -752,12 +750,26 @@ class Sync extends RequestProcessor {
continue;
}
// Get a new sync key to output to the client if any changes have been send or will are available
// Get a new sync key to output to the client if any changes have been send by the mobile or a new synckey is to be sent
if (!empty($actiondata["modifyids"]) ||
!empty($actiondata["clientids"]) ||
!empty($actiondata["removeids"]) ||
$changecount > 0 || (! $spa->HasSyncKey() && $status == SYNC_STATUS_SUCCESS))
(! $spa->HasSyncKey() && $status == SYNC_STATUS_SUCCESS)) {
$spa->SetNewSyncKey(self::$deviceManager->GetStateManager()->GetNewSyncKey($spa->GetSyncKey()));
}
// get a new synckey only if we did not reach the global limit yet
else {
// when reaching the global limit for changes of all collections, stop processing other collections (ZP-697)
if ($sc->GetGlobalWindowSize() <= $globallyExportedItems) {
ZLog::Write(LOGLEVEL_DEBUG, "Global WindowSize for amount of exported changes reached, omitting output for collection.");
continue;
}
// get a new synckey if there are changes are we did not reach the limit yet
if ($changecount > 0) {
$spa->SetNewSyncKey(self::$deviceManager->GetStateManager()->GetNewSyncKey($spa->GetSyncKey()));
}
}
self::$encoder->startTag(SYNC_FOLDER);
......@@ -891,7 +903,14 @@ class Sync extends RequestProcessor {
if($sc->GetParameter($spa, "getchanges") && $spa->HasFolderId() && $spa->HasContentClass() && $spa->HasSyncKey()) {
$windowSize = self::$deviceManager->GetWindowSize($spa->GetFolderId(), $spa->GetContentClass(), $spa->GetUuid(), $spa->GetUuidCounter(), $changecount);
// limit windowSize to the max available limit of the global window size left
$globallyAvailable = $sc->GetGlobalWindowSize() - $globallyExportedItems;
if ($changecount > $globallyAvailable) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleSync(): Limit window size to %d as the global window size limit will be reached", $globallyAvailable));
$windowSize = $globallyAvailable;
}
// send <MoreAvailable/> if there are more changes than fit in the folder windowsize
if($changecount > $windowSize) {
self::$encoder->startTag(SYNC_MOREAVAILABLE, false, true);
}
......@@ -911,6 +930,8 @@ class Sync extends RequestProcessor {
if(!is_array($progress))
break;
$n++;
if ($n % 10 == 0)
self::$topCollector->AnnounceInformation(sprintf("Streamed data of %d objects out of %d", $n, (($changecount > $windowSize)?$windowSize:$changecount)));
}
catch (SyncObjectBrokenException $mbe) {
$brokenSO = $mbe->GetSyncObject();
......@@ -949,6 +970,7 @@ class Sync extends RequestProcessor {
self::$encoder->endTag();
self::$topCollector->AnnounceInformation(sprintf("Outgoing %d objects%s", $n, ($n >= $windowSize)?" of ".$changecount:""), true);
$globallyExportedItems += $n;
// update folder status, if there is something set
if ($spa->GetFolderSyncRemaining() && $changecount > 0) {
......
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