Manybubbles has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/86888


Change subject: Remove index named after alias.
......................................................................

Remove index named after alias.

If you pass --rebuild to updateSearchIndexConfig.php it'll remove any
index that exists with a name equal to the alias.

We could do this all the time but deleting things is kind of destructive
so I paired it with --rebuild which is very destructive.

Change-Id: Ie1bead3286d092b8548ac22c6f2afbbba13ca073
---
M updateOneSearchIndexConfig.php
1 file changed, 44 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch 
refs/changes/88/86888/1

diff --git a/updateOneSearchIndexConfig.php b/updateOneSearchIndexConfig.php
index 8a23fd5..a5a5ab5 100644
--- a/updateOneSearchIndexConfig.php
+++ b/updateOneSearchIndexConfig.php
@@ -77,7 +77,7 @@
                $maintenance->addOption( 'reindexAndRemoveOk', "If the alias is 
held by another index then " .
                        "reindex all documents from that index (via the alias) 
to this one, swing the " .
                        "alias to this index, and then remove other index.  
You'll have to redo all updates ".
-                       "performed during this operation manually.  Defaults to 
false.");
+                       "performed during this operation manually.  Defaults to 
false." );
        }
 
        public function execute() {
@@ -266,18 +266,34 @@
        private function validateSpecificAlias() {
                $this->output( $this->indent . "\tValidating $this->indexType 
alias..." );
                $otherIndeciesWithAlias = array();
-               foreach ( 
CirrusSearchConnection::getClient()->getStatus()->getIndicesWithAlias(
-                               $this->getIndexTypeName() ) as $index ) {
-                       if( $index->getName() === $this->getSpecificIndexName() 
) {
-                               $this->output( "ok\n" );
-                               return;
+               $specificAliasName = $this->getIndexTypeName();
+               $status = CirrusSearchConnection::getClient()->getStatus();
+               if ( $status->indexExists( $specificAliasName ) ) {
+                       $this->output( "is an index..." );
+                       if ( $this->rebuild ) {
+                               CirrusSearchConnection::getClient()->getIndex( 
$specificAliasName )->delete();
+                               $this->output( "index removed..." );
                        } else {
-                               $otherIndeciesWithAlias[] = $index->getName();
+                               $this->output( "cannot correct!\n" );
+                               $this->error(
+                                       "There is currently an index with the 
name of the alias.  Rerun this\n" .
+                                       "script with --rebuild and it'll remove 
the index and continue.\n" );
+                               $this->returnCode = 1;
+                               return;
+                       }
+               } else {
+                       foreach ( $status->getIndicesWithAlias( 
$specificAliasName ) as $index ) {
+                               if( $index->getName() === 
$this->getSpecificIndexName() ) {
+                                       $this->output( "ok\n" );
+                                       return;
+                               } else {
+                                       $otherIndeciesWithAlias[] = 
$index->getName();
+                               }
                        }
                }
                if ( !$otherIndeciesWithAlias ) {
                        $this->output( "alias is free..." );
-                       $this->getIndex()->addAlias( $this->getIndexTypeName(), 
false );
+                       $this->getIndex()->addAlias( $specificAliasName, false 
);
                        $this->output( "corrected\n" );
                        return;
                }
@@ -290,7 +306,7 @@
                        $this->reindex();
                        $this->indent = $saveIndent;
                        $this->output( $this->indent . "\tSwapping alias...");
-                       $this->getIndex()->addAlias( $this->getIndexTypeName(), 
true );
+                       $this->getIndex()->addAlias( $specificAliasName, true );
                        $this->output( "done\n" );
                        $this->removeIndecies = $otherIndeciesWithAlias;
                        return;
@@ -307,12 +323,27 @@
        public function validateAllAlias() {
                $this->output( $this->indent . "\tValidating all alias..." );
                $allAliasName = CirrusSearchConnection::getIndexName();
-               foreach ( CirrusSearchConnection::getClient()->getStatus()
-                               ->getIndicesWithAlias( $allAliasName ) as 
$index ) {
-                       if( $index->getName() === $this->getSpecificIndexName() 
) {
-                               $this->output( "ok\n" );
+               $status = CirrusSearchConnection::getClient()->getStatus();
+               if ( $status->indexExists( $allAliasName ) ) {
+                       $this->output( "is an index..." );
+                       if ( $this->rebuild ) {
+                               CirrusSearchConnection::getClient()->getIndex( 
$allAliasName )->delete();
+                               $this->output( "index removed..." );
+                       } else {
+                               $this->output( "cannot correct!\n" );
+                               $this->error(
+                                       "There is currently an index with the 
name of the alias.  Rerun this\n" .
+                                       "script with --rebuild and it'll remove 
the index and continue.\n" );
+                               $this->returnCode = 1;
                                return;
                        }
+               } else {
+                       foreach ( $status->getIndicesWithAlias( $allAliasName ) 
as $index ) {
+                               if( $index->getName() === 
$this->getSpecificIndexName() ) {
+                                       $this->output( "ok\n" );
+                                       return;
+                               }
+                       }
                }
                $this->output( "alias not already assigned to this index..." );
                // We'll remove the all alias from the indecies that we're 
about to delete while

-- 
To view, visit https://gerrit.wikimedia.org/r/86888
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie1bead3286d092b8548ac22c6f2afbbba13ca073
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to