Error-resilient Solr_Configure

Self-heals in case the solr data directory is missing,
by unloading and re-creating the core.
This commit is contained in:
Ingo Schommer 2013-09-27 17:12:25 +02:00
parent d9af3c1b43
commit 8486eebd0e
2 changed files with 22 additions and 9 deletions

View File

@ -159,17 +159,23 @@ class Solr_Configure extends BuildTask {
foreach ($indexes as $index => $instance) {
$indexName = $instance->getIndexName();
$instanceDir = $indexName;
if ($remote) $instanceDir = "$remote/$instanceDir";
if ($service->coreIsActive($indexName)) {
echo "Reloading configuration...";
$service->coreReload($indexName);
echo "done\n";
} else {
echo "Creating configuration...";
$instanceDir = $indexName;
if ($remote) {
$instanceDir = "$remote/$instanceDir";
try {
if ($service->coreIsActive($indexName)) {
echo "Reloading configuration...";
$service->coreReload($indexName);
echo "done\n";
} else {
echo "Creating configuration...";
$service->coreCreate($indexName, $instanceDir);
echo "done\n";
}
} catch(Apache_Solr_HttpTransportException $e) {
// Can happen when the directory is missing
echo "Failed reload, falling back to unloading and creating configuration...";
$service->coreUnload($indexName, $instanceDir);
$service->coreCreate($indexName, $instanceDir);
echo "done\n";
}

View File

@ -43,6 +43,13 @@ class SolrService extends Apache_Solr_Service {
return $this->coreCommand('RELOAD', $core);
}
/**
* @return Apache_Solr_Response
*/
public function coreUnload($core) {
return $this->coreCommand('UNLOAD', $core);
}
protected $_serviceCache = array();
public function serviceForCore($core) {