Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/cluster/search/PhabricatorSearchHost.php
<?php | <?php | ||||
abstract class PhabricatorSearchHost | abstract class PhabricatorSearchHost | ||||
extends Phobject { | extends Phobject { | ||||
const KEY_REFS = 'cluster.search.refs'; | const KEY_REFS = 'cluster.search.refs'; | ||||
const KEY_HEALTH = 'cluster.search.health'; | const KEY_HEALTH = 'cluster.search.health'; | ||||
protected $engine; | protected $engine; | ||||
protected $healthRecord; | protected $healthRecord; | ||||
protected $roles = array(); | protected $roles = array(); | ||||
protected $disabled; | protected $disabled; | ||||
protected $host; | protected $host; | ||||
protected $port; | protected $port; | ||||
protected $hostRefs = array(); | |||||
const STATUS_OKAY = 'okay'; | const STATUS_OKAY = 'okay'; | ||||
const STATUS_FAIL = 'fail'; | const STATUS_FAIL = 'fail'; | ||||
public function __construct(PhabricatorFulltextStorageEngine $engine) { | public function __construct(PhabricatorFulltextStorageEngine $engine) { | ||||
$this->engine = $engine; | $this->engine = $engine; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | */ | ||||
/** | /** | ||||
* @return string[] Get a list of fields to show in the status overview UI | * @return string[] Get a list of fields to show in the status overview UI | ||||
*/ | */ | ||||
abstract public function getStatusViewColumns(); | abstract public function getStatusViewColumns(); | ||||
abstract public function getConnectionStatus(); | abstract public function getConnectionStatus(); | ||||
public static function reindexAbstractDocument( | |||||
epriestley: Ah, good catch. | |||||
PhabricatorSearchAbstractDocument $doc) { | |||||
$services = self::getAllServices(); | |||||
$indexed = 0; | |||||
foreach (self::getWritableHostForEachService() as $host) { | |||||
$host->getEngine()->reindexAbstractDocument($doc); | |||||
$indexed++; | |||||
} | |||||
if ($indexed == 0) { | |||||
throw new PhabricatorClusterNoHostForRoleException('write'); | |||||
} | |||||
} | |||||
public static function executeSearch(PhabricatorSavedQuery $query) { | |||||
$services = self::getAllServices(); | |||||
foreach ($services as $service) { | |||||
$hosts = $service->getAllHostsForRole('read'); | |||||
// try all hosts until one succeeds | |||||
foreach ($hosts as $host) { | |||||
$last_exception = null; | |||||
try { | |||||
$res = $host->getEngine()->executeSearch($query); | |||||
// return immediately if we get results without an exception | |||||
$host->didHealthCheck(true); | |||||
return $res; | |||||
} catch (Exception $ex) { | |||||
// try each server in turn, only throw if none succeed | |||||
$last_exception = $ex; | |||||
$host->didHealthCheck(false); | |||||
} | |||||
} | |||||
} | |||||
if ($last_exception) { | |||||
throw $last_exception; | |||||
} | |||||
return $res; | |||||
} | |||||
} | } |
Ah, good catch.