Skip to content

Commit 4a474f4

Browse files
committed
Catch any exception during IndexManager::rebuildIndex()
Made IndexManager::getWriteIndices() public
1 parent fdbf542 commit 4a474f4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Manager/IndexManager.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Sineflow\ElasticsearchBundle\Manager;
44

5+
use Elasticsearch\Common\Exceptions\ElasticsearchException;
56
use Elasticsearch\Common\Exceptions\Missing404Exception;
67
use Sineflow\ElasticsearchBundle\Document\DocumentInterface;
78
use Sineflow\ElasticsearchBundle\Document\Provider\ProviderInterface;
@@ -344,7 +345,7 @@ public function getReadIndices()
344345
*
345346
* @throws IndexOrAliasNotFoundException
346347
*/
347-
protected function getWriteIndices()
348+
public function getWriteIndices()
348349
{
349350
return $this->getIndicesForAlias($this->writeAlias);
350351
}
@@ -477,7 +478,7 @@ public function rebuildIndex($deleteOld = false, $cancelExistingRebuild = false)
477478
];
478479
$this->getConnection()->getClient()->indices()->updateAliases($setAliasParams);
479480

480-
$this->copyDataFromOldToNewIndex($newIndex);
481+
$this->copyDataFromOldToNewIndex($newIndex, $oldIndex);
481482

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

@@ -682,8 +684,9 @@ protected function createNewIndexWithUniqueName()
682684
* Retrieves all documents from the index's data provider and populates them in a new index
683685
*
684686
* @param string $newIndex
687+
* @param string $oldIndex
685688
*/
686-
protected function copyDataFromOldToNewIndex(string $newIndex)
689+
protected function copyDataFromOldToNewIndex(string $newIndex, string $oldIndex)
687690
{
688691
$batchSize = $this->connection->getConnectionSettings()['bulk_batch_size'];
689692

0 commit comments

Comments
 (0)