/** * @param array $add * @param array $remove * @return Status */ protected function updateIndices(array $add, array $remove) { if (!$remove) { return $this->updateFreeIndices($add); } if (!$this->reindexAndRemoveOk) { $this->output("cannot correct!\n"); return Status::newFatal(new RawMessage("The alias is held by another index which means it might be actively serving\n" . "queries. You can solve this problem by running this program again with\n" . "--reindexAndRemoveOk. Make sure you understand the consequences of either\n" . "choice.")); } try { $this->output("is taken...\n"); $this->outputIndented("\tReindexing...\n"); call_user_func_array(array($this->reindexer, 'reindex'), $this->reindexParams); if ($this->tooFewReplicas) { $this->reindexer->optimize(); foreach ($this->reindexValidators as $validator) { $status = $validator->validate(); if (!$status->isOK()) { return $status; } } $this->reindexer->waitForShards(); } } catch (\Exception $e) { return Status::newFatal(new RawMessage($e->getMessage())); } // now add alias & remove indices for real $status = Status::newGood(); $status->merge($this->swapAliases($add)); $status->merge(parent::updateIndices(array(), $remove)); return $status; }
public function execute() { global $wgCirrusSearchMaintenanceTimeout; $this->indexType = $this->getOption('indexType'); $this->indexBaseName = $this->getOption('baseName', wfWikiId()); $reindexChunkSize = $this->getOption('reindexChunkSize', 100); $reindexRetryAttempts = $this->getOption('reindexRetryAttempts', 5); $targetCluster = $this->getOption('targetCluster'); $processes = $this->getOption('processes', 1); $sourceConnection = $this->getConnection(); $targetConnection = $this->getConnection($targetCluster); if ($sourceConnection->getClusterName() == $targetConnection->getClusterName()) { $this->error("Target cluster should be different from current cluster.", 1); } $config = ConfigFactory::getDefaultInstance()->makeConfig('CirrusSearch'); $clusterSettings = new ClusterSettings($config, $targetConnection->getClusterName()); $targetIndexName = $targetConnection->getIndexName($this->indexBaseName, $this->indexType); $utils = new ConfigUtils($targetConnection->getClient(), $this); $indexIdentifier = $utils->pickIndexIdentifierFromOption($this->getOption('indexIdentifier', 'current'), $targetIndexName); $reindexer = new Reindexer($sourceConnection, $targetConnection, array($targetConnection->getIndex($this->indexBaseName, $this->indexType, $indexIdentifier)->getType(Connection::PAGE_TYPE_NAME)), array($this->getConnection()->getPageType($this->indexBaseName, $this->indexType)), $clusterSettings->getShardCount($this->indexType), $clusterSettings->getReplicaCount($this->indexType), $wgCirrusSearchMaintenanceTimeout, $this->getMergeSettings(), $this->getMappingConfig(), $this); $reindexer->reindex($processes, 1, $reindexRetryAttempts, $reindexChunkSize); $reindexer->optimize(); $reindexer->waitForShards(); }