From 4a474f4c63bd6dc6e2bac9212f08ea385698a2f8 Mon Sep 17 00:00:00 2001 From: pmishev Date: Tue, 9 Jul 2019 12:28:18 +0100 Subject: [PATCH] Catch any exception during IndexManager::rebuildIndex() Made IndexManager::getWriteIndices() public --- Manager/IndexManager.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Manager/IndexManager.php b/Manager/IndexManager.php index 921659a..8bb1e87 100644 --- a/Manager/IndexManager.php +++ b/Manager/IndexManager.php @@ -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; @@ -344,7 +345,7 @@ public function getReadIndices() * * @throws IndexOrAliasNotFoundException */ - protected function getWriteIndices() + public function getWriteIndices() { return $this->getIndicesForAlias($this->writeAlias); } @@ -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 = [ @@ -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()); } @@ -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'];