jenkins-bot has submitted this change and it was merged.

Change subject: More efficient alias maintenance.
......................................................................


More efficient alias maintenance.

Elastica's method to fetch which index has an alias is very slow.  We
work around it and see a significant speed improvement on clusters with
lots of indecies.

Bug: 54505
Change-Id: Iaa25accfb6c83f36455bf15af66c08233dcdd31c
---
M updateOneSearchIndexConfig.php
1 file changed, 22 insertions(+), 2 deletions(-)

Approvals:
  Chad: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/updateOneSearchIndexConfig.php b/updateOneSearchIndexConfig.php
index a5a5ab5..065228e 100644
--- a/updateOneSearchIndexConfig.php
+++ b/updateOneSearchIndexConfig.php
@@ -283,7 +283,7 @@
                        }
                } else {
                        foreach ( $status->getIndicesWithAlias( 
$specificAliasName ) as $index ) {
-                               if( $index->getName() === 
$this->getSpecificIndexName() ) {
+                               if( $this->getName() === 
$this->getSpecificIndexName() ) {
                                        $this->output( "ok\n" );
                                        return;
                                } else {
@@ -338,7 +338,7 @@
                                return;
                        }
                } else {
-                       foreach ( $status->getIndicesWithAlias( $allAliasName ) 
as $index ) {
+                       foreach ( $this->getIndicesWithAlias( $allAliasName ) 
as $index ) {
                                if( $index->getName() === 
$this->getSpecificIndexName() ) {
                                        $this->output( "ok\n" );
                                        return;
@@ -530,6 +530,26 @@
                global $wgCirrusSearchContentReplicaCount;
                return $wgCirrusSearchContentReplicaCount[ $this->indexType ];
        }
+
+       /**
+        * Get indecies with the named alias.  Doesn't use Elastica's 
status->getIndicesWithAlias because
+        * that feches index status from _every_ index.
+        *
+        * @var $alias string alias name
+        * @return array(\Elastica\Index) of index names
+        */
+       private function getIndicesWithAlias( $alias ) {
+               $client = CirrusSearchConnection::getClient();
+               $response = $client->request( "/_alias/$alias" );
+               if ( $response->hasError() ) {
+                       $this->error( 'Error fetching indecies with alias:  ' . 
$response->getError() );
+               }
+               $result = array();
+               foreach ( $response->getData() as $name => $info ) {
+                       $result[] = new \Elastica\Index($client, $name);
+               }
+               return $result;
+       }
 }
 
 $maintClass = "UpdateOneSearchIndexConfig";

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iaa25accfb6c83f36455bf15af66c08233dcdd31c
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to