Skip to content

Commit

Permalink
Catch any exception during IndexManager::rebuildIndex()
Browse files Browse the repository at this point in the history
Made IndexManager::getWriteIndices() public
  • Loading branch information
pmishev committed Jul 9, 2019
1 parent fdbf542 commit 4a474f4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Manager/IndexManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sineflow\ElasticsearchBundle\Manager;

use Elasticsearch\Common\Exceptions\ElasticsearchException;
use Elasticsearch\Common\Exceptions\Missing404Exception;
use Sineflow\ElasticsearchBundle\Document\DocumentInterface;
use Sineflow\ElasticsearchBundle\Document\Provider\ProviderInterface;
Expand Down Expand Up @@ -344,7 +345,7 @@ public function getReadIndices()
*
* @throws IndexOrAliasNotFoundException
*/
protected function getWriteIndices()
public function getWriteIndices()
{
return $this->getIndicesForAlias($this->writeAlias);
}
Expand Down Expand Up @@ -477,7 +478,7 @@ public function rebuildIndex($deleteOld = false, $cancelExistingRebuild = false)
];
$this->getConnection()->getClient()->indices()->updateAliases($setAliasParams);

$this->copyDataFromOldToNewIndex($newIndex);
$this->copyDataFromOldToNewIndex($newIndex, $oldIndex);

// Point both aliases to the new index and remove them from the old
$setAliasParams = [
Expand All @@ -496,9 +497,10 @@ public function rebuildIndex($deleteOld = false, $cancelExistingRebuild = false)
$this->getConnection()->getClient()->indices()->delete(['index' => $oldIndex]);
$this->getConnection()->getLogger()->notice(sprintf('Deleted old index %s', $oldIndex));
}
} catch (Exception $e) {
// Bulk exceptions are logged in the connection manager, so only log other exceptions here
if (!($e instanceof BulkRequestException)) {
} catch (\Exception $e) {
// Do not log BulkRequestException here as they are logged in the connection manager
// Do not log ElasticsearchException either, as they are logged inside the elasticsearch bundle
if (!($e instanceof BulkRequestException) && !($e instanceof ElasticsearchException)) {
$this->getConnection()->getLogger()->error($e->getMessage());
}

Expand Down Expand Up @@ -682,8 +684,9 @@ protected function createNewIndexWithUniqueName()
* Retrieves all documents from the index's data provider and populates them in a new index
*
* @param string $newIndex
* @param string $oldIndex
*/
protected function copyDataFromOldToNewIndex(string $newIndex)
protected function copyDataFromOldToNewIndex(string $newIndex, string $oldIndex)
{
$batchSize = $this->connection->getConnectionSettings()['bulk_batch_size'];

Expand Down

0 comments on commit 4a474f4

Please sign in to comment.