Commit 01032d9b authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-1054 Throw UnavailableException if the hash cannot be loaded.

Released under the Affero GNU General Public License (AGPL) version 3.
parent 1d2b977c
......@@ -143,7 +143,7 @@ class SqlStateMachine implements IStateMachine {
*
* @access public
* @return string
* @throws StateNotFoundException, StateInvalidException
* @throws StateNotFoundException, StateInvalidException, UnavailableException
*/
public function GetStateHash($devid, $type, $key = null, $counter = false) {
$hash = null;
......@@ -155,8 +155,12 @@ class SqlStateMachine implements IStateMachine {
$record = $sth->fetch(PDO::FETCH_ASSOC);
if (!$record) {
$errCode = $sth->errorCode();
$this->clearConnection($this->dbh, $sth, $record);
throw new StateNotFoundException("SqlStateMachine->GetStateHash(): Could not locate state");
if ($errCode == 'HY000') {
throw new UnavailableException("SqlStateMachine->GetStateHash(): Database not available", $errCode, null, LOGLEVEL_WARN);
}
throw new StateNotFoundException("SqlStateMachine->GetStateHash(): Could not locate state with error code: ". $errCode);
}
else {
// datetime->format("U") returns EPOCH
......
......@@ -1001,6 +1001,13 @@ class DeviceManager {
catch (StateNotFoundException $snfex) {
$this->hierarchySyncRequired = true;
}
catch (UnavailableException $uaex) {
// This is temporary and can be ignored e.g. in PING - see https://jira.z-hub.io/browse/ZP-1054
// If the hash was not available before we treat it like a StateNotFoundException.
if ($this->deviceHash === false) {
$this->hierarchySyncRequired = true;
}
}
return true;
}
......
......@@ -92,7 +92,7 @@ class FileStateMachine implements IStateMachine {
*
* @access public
* @return string
* @throws StateNotFoundException, StateInvalidException
* @throws StateNotFoundException, StateInvalidException, UnavailableException
*/
public function GetStateHash($devid, $type, $key = false, $counter = false) {
$filename = $this->getFullFilePath($devid, $type, $key, $counter);
......
......@@ -82,7 +82,7 @@ interface IStateMachine {
*
* @access public
* @return string
* @throws StateNotFoundException, StateInvalidException
* @throws StateNotFoundException, StateInvalidException, UnavailableException
*/
public function GetStateHash($devid, $type, $key = false, $counter = false);
......
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