Skip to content

Commit

Permalink
Merge branch '93-failsafe-state-is-not-cleaned-up-too-early' into 'ma…
Browse files Browse the repository at this point in the history
…ster'

Don't clean up the failsave state of the current (incoming) state, only...

Closes #93

See merge request grommunio/grommunio-sync!32
  • Loading branch information
gromandreas committed Mar 2, 2023
2 parents 6eeee6f + 762eb75 commit d0f860f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
10 changes: 5 additions & 5 deletions lib/core/statemanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function SetSyncState($synckey, $syncstate, $folderid = false) {
}

/**
* Gets the failsave sync state for the current synckey.
* Gets the failsafe sync state for the current synckey.
*
* @return array|bool false if not available
*/
Expand All @@ -230,15 +230,15 @@ public function GetSyncFailState() {
}

try {
return $this->statemachine->GetState($this->device->GetDeviceId(), IStateMachine::FAILSAVE, $this->uuid, $this->oldStateCounter, $this->deleteOldStates);
return $this->statemachine->GetState($this->device->GetDeviceId(), IStateMachine::FAILSAFE, $this->uuid, $this->oldStateCounter, $this->deleteOldStates);
}
catch (StateNotFoundException $snfex) {
return false;
}
}

/**
* Writes the failsave sync state for the current (old) synckey.
* Writes the failsafe sync state for the current (old) synckey.
*
* @param mixed $syncstate
*
Expand All @@ -249,7 +249,7 @@ public function SetSyncFailState($syncstate) {
return false;
}

return $this->statemachine->SetState($syncstate, $this->device->GetDeviceId(), IStateMachine::FAILSAVE, $this->uuid, $this->oldStateCounter);
return $this->statemachine->SetState($syncstate, $this->device->GetDeviceId(), IStateMachine::FAILSAFE, $this->uuid, $this->oldStateCounter);
}

/**
Expand Down Expand Up @@ -386,7 +386,7 @@ public static function UnLinkState(&$device, $folderid, $removeFromDevice = true
SLog::Write(LOGLEVEL_DEBUG, sprintf("StateManager::UnLinkState('%s'): saved state '%s' will be deleted.", $folderid, $savedUuid));
GSync::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::DEFTYPE, $savedUuid, self::FIXEDHIERARCHYCOUNTER * 2);
GSync::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::FOLDERDATA, $savedUuid, false, true); // CPO
GSync::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::FAILSAVE, $savedUuid, self::FIXEDHIERARCHYCOUNTER * 2);
GSync::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::FAILSAFE, $savedUuid, self::FIXEDHIERARCHYCOUNTER * 2);
GSync::GetStateMachine()->CleanStates($device->GetDeviceId(), IStateMachine::BACKENDSTORAGE, $savedUuid, self::FIXEDHIERARCHYCOUNTER * 2);

// remove all messages which could not be synched before
Expand Down
9 changes: 6 additions & 3 deletions lib/grommunio/grommunio.php
Original file line number Diff line number Diff line change
Expand Up @@ -1690,9 +1690,9 @@ public function GetStateHash($devid, $type, $key = false, $counter = false) {
public function GetState($devid, $type, $key = false, $counter = false, $cleanstates = true) {
if ($counter && $cleanstates) {
$this->CleanStates($devid, $type, $key, $counter);
// also clean Failsave state for previous counter
// also clean failsafe state for previous counter
if ($key == false) {
$this->CleanStates($devid, $type, IStateMachine::FAILSAVE, $counter);
$this->CleanStates($devid, $type, IStateMachine::FAILSAFE, $counter);
}
}
$stateMessage = $this->getStateMessage($devid, $type, $key, $counter);
Expand Down Expand Up @@ -1753,13 +1753,16 @@ public function CleanStates($devid, $type, $key, $counter = false, $thisCounterO
));
}
}
if ($type == IStateMachine::FAILSAFE && $counter && $counter > 1) {
$counter--;
}
$messageName = rtrim((($key !== false) ? $key . "-" : "") . (($type !== "") ? $type : ""), "-");
$restriction = $this->getStateMessageRestriction($messageName, $counter, $thisCounterOnly);
$stateFolderContents = mapi_folder_getcontentstable($this->stateFolder, MAPI_ASSOCIATED);
if ($stateFolderContents) {
mapi_table_restrict($stateFolderContents, $restriction);
$rowCnt = mapi_table_getrowcount($stateFolderContents);
SLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->CleanStates(): Found %d states to clean (%s)", $rowCnt, $messageName));
SLog::Write(LOGLEVEL_DEBUG, sprintf("Grommunio->CleanStates(): Found %d states to clean (%s) %s", $rowCnt, $messageName, Utils::PrintAsString($counter)));
if ($rowCnt > 0) {
$rows = mapi_table_queryallrows($stateFolderContents, [PR_ENTRYID]);
$entryids = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/interface/istatemachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface IStateMachine {
public const DEFTYPE = "";
public const DEVICEDATA = "devicedata";
public const FOLDERDATA = "fd";
public const FAILSAVE = "fs";
public const FAILSAFE = "fs";
public const HIERARCHY = "hc";
public const BACKENDSTORAGE = "bs";

Expand Down
12 changes: 6 additions & 6 deletions lib/request/sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ public function Handle($commandCode) {
}
}

// save the failsave state
// save the failsafe state
if (!empty($actiondata["statusids"])) {
unset($actiondata["failstate"]);
$actiondata["failedsyncstate"] = $sc->GetParameter($spa, "state");
Expand Down Expand Up @@ -1343,11 +1343,11 @@ private function syncFolder($sc, $spa, $exporter, $changecount, $streamimporter,
* @param SyncCollection $sc SyncCollection object
* @param SyncParameters $spa SyncParameters object
* @param array $actiondata Actiondata array
* @param bool $loadFailsave (opt) default false - indicates if the failsave states should be loaded
* @param bool $loadFailsafe (opt) default false - indicates if the failsafe states should be loaded
*
* @return status indicating if there were errors. If no errors, status is SYNC_STATUS_SUCCESS
*/
private function loadStates($sc, $spa, &$actiondata, $loadFailsave = false) {
private function loadStates($sc, $spa, &$actiondata, $loadFailsafe = false) {
$status = SYNC_STATUS_SUCCESS;

if ($sc->GetParameter($spa, "state") == null) {
Expand All @@ -1356,7 +1356,7 @@ private function loadStates($sc, $spa, &$actiondata, $loadFailsave = false) {
try {
$sc->AddParameter($spa, "state", self::$deviceManager->GetStateManager()->GetSyncState($spa->GetSyncKey()));

if ($loadFailsave) {
if ($loadFailsafe) {
// if this request was made before, there will be a failstate available
$actiondata["failstate"] = self::$deviceManager->GetStateManager()->GetSyncFailState();
}
Expand All @@ -1383,7 +1383,7 @@ private function loadStates($sc, $spa, &$actiondata, $loadFailsave = false) {

/**
* Initializes the importer for the SyncParameters folder, loads necessary
* states (incl. failsave states) and initializes the conflict detection.
* states (incl. failsafe states) and initializes the conflict detection.
*
* @param SyncCollection $sc SyncCollection object
* @param SyncParameters $spa SyncParameters object
Expand All @@ -1395,7 +1395,7 @@ private function getImporter($sc, $spa, &$actiondata) {
SLog::Write(LOGLEVEL_DEBUG, "Sync->getImporter(): initialize importer");
$status = SYNC_STATUS_SUCCESS;

// load the states with failsave data
// load the states with failsafe data
$status = $this->loadStates($sc, $spa, $actiondata, true);

try {
Expand Down

0 comments on commit d0f860f

Please sign in to comment.