Smalyshev has uploaded a new change for review.

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

Change subject: Use corrent idnexes/connections for old and new types.
......................................................................

Use corrent idnexes/connections for old and new types.

Bug: T113018
Change-Id: I4c5e9d9787adaaaa7f35e14b1432731bdd615611
---
M includes/Maintenance/Reindexer.php
M maintenance/updateOneSearchIndexConfig.php
2 files changed, 48 insertions(+), 30 deletions(-)


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

diff --git a/includes/Maintenance/Reindexer.php 
b/includes/Maintenance/Reindexer.php
index c1114bc..aa735e3 100644
--- a/includes/Maintenance/Reindexer.php
+++ b/includes/Maintenance/Reindexer.php
@@ -30,20 +30,29 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 class Reindexer {
+       /*** "From" portion ***/
+       /**
+        * @var Index
+        */
+       private $oldIndex;
+
+       /**
+        * @var Connection
+        */
+       private $oldConnection;
+
+       /*** "To" portion ***/
+
        /**
         * @var Index
         */
        private $index;
 
        /**
-        * @var \Elastica\Client
+        * @var Connection
         */
-       private $client;
+       private $connection;
 
-       /**
-        * @var string
-        */
-       private $specificIndexName;
 
        /**
         * @var Type[]
@@ -80,10 +89,6 @@
         */
        private $mappingConfig;
 
-       /**
-        * @var \ElasticaConnection
-        */
-       private $connection;
 
        /**
         * @var Maintenance
@@ -91,8 +96,6 @@
        private $out;
 
        /**
-        * @param Index $index
-        * @param \ElasticaConnection $connection
         * @param Type[] $types
         * @param Type[] $oldTypes
         * @param int $shardCount
@@ -102,12 +105,8 @@
         * @param array $mappingConfig
         * @param Maintenance $out
         */
-       public function __construct( Index $index, \ElasticaConnection 
$connection, array $types, array $oldTypes, $shardCount, $replicaCount, 
$connectionTimeout, array $mergeSettings, array $mappingConfig, Maintenance 
$out = null ) {
+       public function __construct( array $types, array $oldTypes, 
$shardCount, $replicaCount, $connectionTimeout, array $mergeSettings, array 
$mappingConfig, Maintenance $out = null ) {
                // @todo: this constructor has too many arguments - refactor!
-               $this->index = $index;
-               $this->client = $this->index->getClient();
-               $this->specificIndexName = $this->index->getName();
-               $this->connection = $connection;
                $this->types = $types;
                $this->oldTypes = $oldTypes;
                $this->shardCount = $shardCount;
@@ -116,6 +115,15 @@
                $this->mergeSettings = $mergeSettings;
                $this->mappingConfig = $mappingConfig;
                $this->out = $out;
+
+               if ( empty($types) || empty($oldTypes) ) {
+                       throw new \Exception( "Types list should be non-empty" 
);
+               }
+               $this->index = $types[0]->getIndex();
+               $this->oldIndex = $oldTypes[0]->getIndex();
+
+               $this->connection = $this->index->getClient()->getConnection();
+               $this->oldConnection = 
$this->oldIndex->getClient()->getConnection();
        }
 
        /**
@@ -155,9 +163,7 @@
                        $fork = new ForkController( $processes );
                        $forkResult = $fork->start();
                        // we don't want to share sockets between forks, so 
destroy the client.
-                       $this->connection->destroyClient();
-                       // destroying the client resets the timeout so we have 
to reinstate it.
-                       $this->setConnectionTimeout();
+                       $this->destroyClients();
 
                        switch ( $forkResult ) {
                                case 'child':
@@ -217,8 +223,7 @@
                        if ( $e->getMessage() === 'Operation timed out' ) {
                                $this->output( "Timed out...Continuing any 
way\n" );
                                // To continue without blowing up we need to 
reset the connection.
-                               $this->destroySingleton();
-                               $this->setConnectionTimeout();
+                               $this->destroyClients();
                        } else {
                                throw $e;
                        }
@@ -293,7 +298,7 @@
                        $operationStartTime = microtime( true );
                        $completed = 0;
                        $self = $this;
-                       Util::iterateOverScroll( $this->index, 
$result->getResponse()->getScrollId(), '1h',
+                       Util::iterateOverScroll( $this->oldIndex, 
$result->getResponse()->getScrollId(), '1h',
                                function( $results ) use ( $properties, 
$retryAttempts, $messagePrefix, $self, $type,
                                                &$completed, 
$totalDocsToReindex, $operationStartTime ) {
                                        $documents = array();
@@ -345,11 +350,15 @@
                return new Document( $result->getId(), $data );
        }
 
+       /**
+        * Get health information about the index
+        * @return array Response data array
+        */
        private function getHealth() {
                while ( true ) {
-                       $indexName = $this->specificIndexName;
+                       $indexName = $this->index->getName();
                        $path = "_cluster/health/$indexName";
-                       $response = $this->client->request( $path );
+                       $response = $this->index->getClient()->request( $path );
                        if ( $response->hasError() ) {
                                $this->error( 'Error fetching index health but 
going to retry.  Message: ' . $response->getError() );
                                sleep( 1 );
@@ -389,7 +398,6 @@
        /**
         * @param \Exception $e exception caught
         * @param int $errors number of errors
-        * @param Maintenance $out
         * @param string $messagePrefix
         * @param string $description
         */
@@ -403,7 +411,9 @@
        }
 
        /**
-        * This is really private.
+        * Send documents to type with retry.
+        * This is really private, marked as public for closure use.
+        * @access private
         */
        public function sendDocuments( Type $type, $messagePrefix, $documents ) 
{
                try {
@@ -419,12 +429,22 @@
                }
        }
 
+       /**
+        * Reset connection timeouts
+        */
        private function setConnectionTimeout() {
                $this->connection->setTimeout( $this->connectionTimeout );
+               $this->oldConnection->setTimeout( $this->connectionTimeout );
        }
 
-       private function destroySingleton() {
+       /**
+        * Destroy client connections
+        */
+       private function destroyClients() {
                $this->connection->destroyClient();
+               $this->oldConnection->destroyClient();
+               // Destroying connections resets timeouts, so we have to 
reinstate them
+               $this->setConnectionTimeout();
        }
 
        /**
diff --git a/maintenance/updateOneSearchIndexConfig.php 
b/maintenance/updateOneSearchIndexConfig.php
index a46e032..bf8a1ff 100644
--- a/maintenance/updateOneSearchIndexConfig.php
+++ b/maintenance/updateOneSearchIndexConfig.php
@@ -352,8 +352,6 @@
                global $wgCirrusSearchMaintenanceTimeout;
 
                $reindexer = new Reindexer(
-                       $this->getIndex(),
-                       $this->getConnection(),
                        array( $this->getPageType() ),
                        array( $this->getOldPageType() ),
                        $this->getShardCount(),

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

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

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

Reply via email to