Commit 5716e806 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #51 in ZP/z-push from bugfix/ZP-697-global-windowssize-not-working to develop

* commit '967a0c36':
  ZP-697 Honour global window size. Released under the Affero GNU General Public License (AGPL) version 3.
parents a386d254 967a0c36
...@@ -334,11 +334,11 @@ class SyncCollections implements Iterator { ...@@ -334,11 +334,11 @@ class SyncCollections implements Iterator {
* in a case of a heartbeat and/or partial sync * in a case of a heartbeat and/or partial sync
* *
* @access public * @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() { public function GetGlobalWindowSize() {
if (!isset($this->globalWindowSize)) if (!isset($this->globalWindowSize))
return false; return 512;
return $this->globalWindowSize; return $this->globalWindowSize;
} }
......
...@@ -61,6 +61,7 @@ class Sync extends RequestProcessor { ...@@ -61,6 +61,7 @@ class Sync extends RequestProcessor {
$status = SYNC_STATUS_SUCCESS; $status = SYNC_STATUS_SUCCESS;
$wbxmlproblem = false; $wbxmlproblem = false;
$emptysync = false; $emptysync = false;
$globallyExportedItems = 0;
// check if the hierarchySync was fully completed // check if the hierarchySync was fully completed
...@@ -525,6 +526,7 @@ class Sync extends RequestProcessor { ...@@ -525,6 +526,7 @@ class Sync extends RequestProcessor {
if (self::$decoder->getElementStartTag(SYNC_WINDOWSIZE)) { if (self::$decoder->getElementStartTag(SYNC_WINDOWSIZE)) {
$sc->SetGlobalWindowSize(self::$decoder->getElementContent()); $sc->SetGlobalWindowSize(self::$decoder->getElementContent());
ZLog::Write(LOGLEVEL_DEBUG, "Sync(): Global WindowSize requested: ". $sc->GetGlobalWindowSize());
if(!self::$decoder->getElementEndTag()) // SYNC_WINDOWSIZE if(!self::$decoder->getElementEndTag()) // SYNC_WINDOWSIZE
return false; return false;
} }
...@@ -573,10 +575,6 @@ class Sync extends RequestProcessor { ...@@ -573,10 +575,6 @@ class Sync extends RequestProcessor {
// manually set getchanges parameter for this collection // manually set getchanges parameter for this collection
$sc->AddParameter($spa, "getchanges", true); $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 // announce WindowSize to DeviceManager
self::$deviceManager->SetWindowSize($folderid, $spa->GetWindowSize()); self::$deviceManager->SetWindowSize($folderid, $spa->GetWindowSize());
} }
...@@ -755,12 +753,26 @@ class Sync extends RequestProcessor { ...@@ -755,12 +753,26 @@ class Sync extends RequestProcessor {
continue; 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"]) || if (!empty($actiondata["modifyids"]) ||
!empty($actiondata["clientids"]) || !empty($actiondata["clientids"]) ||
!empty($actiondata["removeids"]) || !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())); $spa->SetNewSyncKey(self::$deviceManager->GetStateManager()->GetNewSyncKey($spa->GetSyncKey()));
}
}
self::$encoder->startTag(SYNC_FOLDER); self::$encoder->startTag(SYNC_FOLDER);
...@@ -894,7 +906,14 @@ class Sync extends RequestProcessor { ...@@ -894,7 +906,14 @@ class Sync extends RequestProcessor {
if($sc->GetParameter($spa, "getchanges") && $spa->HasFolderId() && $spa->HasContentClass() && $spa->HasSyncKey()) { if($sc->GetParameter($spa, "getchanges") && $spa->HasFolderId() && $spa->HasContentClass() && $spa->HasSyncKey()) {
$windowSize = self::$deviceManager->GetWindowSize($spa->GetFolderId(), $spa->GetContentClass(), $spa->GetUuid(), $spa->GetUuidCounter(), $changecount); $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) { if($changecount > $windowSize) {
self::$encoder->startTag(SYNC_MOREAVAILABLE, false, true); self::$encoder->startTag(SYNC_MOREAVAILABLE, false, true);
} }
...@@ -915,6 +934,8 @@ class Sync extends RequestProcessor { ...@@ -915,6 +934,8 @@ class Sync extends RequestProcessor {
if(!is_array($progress)) if(!is_array($progress))
break; break;
$n++; $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) { catch (SyncObjectBrokenException $mbe) {
$brokenSO = $mbe->GetSyncObject(); $brokenSO = $mbe->GetSyncObject();
...@@ -953,6 +974,7 @@ class Sync extends RequestProcessor { ...@@ -953,6 +974,7 @@ class Sync extends RequestProcessor {
self::$encoder->endTag(); self::$encoder->endTag();
self::$topCollector->AnnounceInformation(sprintf("Outgoing %d objects%s", $n, ($n >= $windowSize)?" of ".$changecount:""), true); self::$topCollector->AnnounceInformation(sprintf("Outgoing %d objects%s", $n, ($n >= $windowSize)?" of ".$changecount:""), true);
$globallyExportedItems += $n;
// update folder status, if there is something set // update folder status, if there is something set
if ($spa->GetFolderSyncRemaining() && $changecount > 0) { 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