EBernhardson has uploaded a new change for review.

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

Change subject: [WIP] refactor out connection singleton
......................................................................

[WIP] refactor out connection singleton

Change-Id: Ib6132f87641c4df83b476deb77f4926cc21b0b14
---
M includes/Api/FreezeWritesToCluster.php
M includes/Api/MappingDump.php
M includes/Api/SettingsDump.php
M includes/BuildDocument/RedirectsAndIncomingLinks.php
M includes/Connection.php
M includes/DataSender.php
M includes/ElasticsearchIntermediary.php
M includes/Hooks.php
M includes/Job/ElasticaWrite.php
D includes/Maintenance/ReindexForkController.php
M includes/Maintenance/Reindexer.php
M includes/OtherIndexes.php
M includes/Sanity/Checker.php
M includes/Searcher.php
M includes/Updater.php
M includes/Version.php
M maintenance/freezeWritesToCluster.php
17 files changed, 102 insertions(+), 102 deletions(-)


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

diff --git a/includes/Api/FreezeWritesToCluster.php 
b/includes/Api/FreezeWritesToCluster.php
index 8284c21..a527849 100644
--- a/includes/Api/FreezeWritesToCluster.php
+++ b/includes/Api/FreezeWritesToCluster.php
@@ -26,7 +26,9 @@
  */
 class FreezeWritesToCluster extends ApiBase {
        public function execute() {
-               $sender = new DataSender();
+               $config = ConfigFactory::getDefaultInstance()->makeConfig( 
'CirrusSearch' );
+               $conn = new Connection( $config );
+               $sender = new DataSender( $conn );
                if ( $this->getParameter( 'thaw' ) ) {
                        $sender->thawIndexes();
                } else {
diff --git a/includes/Api/MappingDump.php b/includes/Api/MappingDump.php
index 453a3c9..a465139 100644
--- a/includes/Api/MappingDump.php
+++ b/includes/Api/MappingDump.php
@@ -25,9 +25,11 @@
  */
 class MappingDump extends ApiBase {
        public function execute() {
-               foreach( Connection::getAllIndexTypes() as $index ) {
-                       $this->getResult()->addValue( null, $index,
-                               Connection::getPageType( wfWikiId(), $index 
)->getMapping() );
+               $config = ConfigFactory::getDefaultInstance()->makeConfig( 
'CirrusSearch' );
+               $conn = new Connection( $config );
+               foreach( $conn->getAllIndexTypes() as $index ) {
+                       $mapping = $conn->getPageType( wfWikiId(), $index 
)->getMapping();
+                       $this->getResult()->addValue( null, $index, $mapping );
                        $this->getResult()->addPreserveKeysList( array( $index, 
'page' ), '_all' );
                }
        }
diff --git a/includes/Api/SettingsDump.php b/includes/Api/SettingsDump.php
index 5977b81..232cad2 100644
--- a/includes/Api/SettingsDump.php
+++ b/includes/Api/SettingsDump.php
@@ -25,9 +25,11 @@
  */
 class SettingsDump extends ApiBase {
        public function execute() {
-               foreach( Connection::getAllIndexTypes() as $index ) {
+               $config = ConfigFactory::getDefaultInstance()->makeConfig( 
'CirrusSearch' );
+               $conn = new Connection( $config );
+               foreach( $conn->getAllIndexTypes() as $index ) {
                        $this->getResult()->addValue( array( $index, 'page' ), 
'index',
-                               Connection::getIndex( wfWikiId(), $index 
)->getSettings()->get() );
+                               $conn->getIndex( wfWikiId(), $index 
)->getSettings()->get() );
                }
        }
 
diff --git a/includes/BuildDocument/RedirectsAndIncomingLinks.php 
b/includes/BuildDocument/RedirectsAndIncomingLinks.php
index c673ab3..fed6dc8 100644
--- a/includes/BuildDocument/RedirectsAndIncomingLinks.php
+++ b/includes/BuildDocument/RedirectsAndIncomingLinks.php
@@ -57,7 +57,7 @@
 
        protected function __construct() {
                parent::__construct( null, null );
-               $this->linkCountMultiSearch = new \Elastica\Multi\Search( 
Connection::getClient() );
+               $this->linkCountMultiSearch = new \Elastica\Multi\Search( 
$this->connection->getClient() );
                $this->linkCountClosures = array();
        }
 
@@ -132,7 +132,7 @@
        private function buildCount( $titles ) {
                $filter = new Terms( 'outgoing_link', $titles );
                $filter->setCached( false ); // We're not going to be redoing 
this any time soon.
-               $type = Connection::getPageType( wfWikiId() );
+               $type = $this->connection->getPageType( wfWikiId() );
                $search = new Search( $type->getIndex()->getClient() );
                $search->addIndex( $type->getIndex() );
                $search->addType( $type );
diff --git a/includes/Connection.php b/includes/Connection.php
index 730f92d..f40d3b4 100644
--- a/includes/Connection.php
+++ b/includes/Connection.php
@@ -61,11 +61,19 @@
        const TITLE_SUGGEST_TYPE_NAME = 'titlesuggest';
 
        /**
+        * @var Config
+        */
+       protected $config;
+
+       public function __construct( Config $config ) {
+               $this->config = $config;
+       }
+
+       /**
         * @return array(string)
         */
        public function getServerList() {
-               global $wgCirrusSearchServers;
-               return $wgCirrusSearchServers;
+               return $this->config->get( 'CirrusSearchServers' );
        }
 
        /**
@@ -74,8 +82,7 @@
         * @return int
         */
        public function getMaxConnectionAttempts() {
-               global $wgCirrusSearchConnectionAttempts;
-               return $wgCirrusSearchConnectionAttempts;
+               return $this->config->get( 'CirrusSearchConnectionAttempts' );
        }
 
        /**
@@ -83,8 +90,8 @@
         * frozen indexes that should not be written to.
         * @return \Elastica\Index
         */
-       public static function getFrozenIndex() {
-               $index = self::getIndex( 
'mediawiki_cirrussearch_frozen_indexes' );
+       public function getFrozenIndex() {
+               $index = $this->getIndex( 
'mediawiki_cirrussearch_frozen_indexes' );
                if ( !$index->exists() ) {
                        $options = array(
                                'number_of_shards' => 1,
@@ -98,8 +105,8 @@
        /**
         * @return \Elastica\Type
         */
-       public static function getFrozenIndexNameType() {
-               return self::getFrozenIndex()->getType( 'name' );
+       public function getFrozenIndexNameType() {
+               return $this->getFrozenIndex()->getType( 'name' );
        }
 
        /**
@@ -108,8 +115,8 @@
         * @param mixed $type type of index (content or general or false to get 
all)
         * @return \Elastica\Type
         */
-       public static function getPageType( $name, $type = false ) {
-               return self::getIndex( $name, $type )->getType( 
self::PAGE_TYPE_NAME );
+       public function getPageType( $name, $type = false ) {
+               return $this->getIndex( $name, $type )->getType( 
self::PAGE_TYPE_NAME );
        }
 
        /**
@@ -117,9 +124,9 @@
         * @param mixed $name basename of index
         * @return \Elastica\Type
         */
-       public static function getNamespaceType( $name ) {
+       public function getNamespaceType( $name ) {
                $type = 'general'; // Namespaces are always stored in the 
'general' index.
-               return self::getIndex( $name, $type )->getType( 
self::NAMESPACE_TYPE_NAME );
+               return $this->getIndex( $name, $type )->getType( 
self::NAMESPACE_TYPE_NAME );
        }
 
        /**
@@ -127,9 +134,8 @@
         *
         * @return array(string)
         */
-       public static function getAllIndexTypes() {
-               global $wgCirrusSearchNamespaceMappings;
-               return array_merge( array_values( 
$wgCirrusSearchNamespaceMappings ),
+       public function getAllIndexTypes() {
+               return array_merge( array_values( $this->config->get( 
'CirrusSearchNamespaceMappings' ) ),
                        array( self::CONTENT_INDEX_TYPE, 
self::GENERAL_INDEX_TYPE ) );
        }
 
@@ -141,8 +147,8 @@
         * @param \Elastica\Index[] $indexes
         * @return string[]
         */
-       public static function indexToIndexTypes( array $indexes ) {
-               $allowed = self::getAllIndexTypes();
+       public function indexToIndexTypes( array $indexes ) {
+               $allowed = $this->getAllIndexTypes();
                return array_map( function( $type ) use ( $allowed ) {
                        $fullName = $type->getIndex()->getName();
                        $parts = explode( '_', $fullName );
@@ -176,10 +182,10 @@
         * @param int $namespace A namespace id
         * @return string
         */
-       public static function getIndexSuffixForNamespace( $namespace ) {
-               global $wgCirrusSearchNamespaceMappings;
-               if ( isset( $wgCirrusSearchNamespaceMappings[$namespace] ) ) {
-                       return $wgCirrusSearchNamespaceMappings[$namespace];
+       public function getIndexSuffixForNamespace( $namespace ) {
+               $mappings = $this->config->get( 'CirrusSearchNamespaceMappings' 
);
+               if ( isset( $mappings[$namespace] ) ) {
+                       return $mappings[$namespace];
                }
 
                return MWNamespace::isContent( $namespace ) ?
@@ -191,19 +197,18 @@
         * @var string $indexType an index type
         * @return false|integer false if the number of indexes is unknown, an 
integer if it is known
         */
-       public static function namespacesInIndexType( $indexType ) {
-               global $wgCirrusSearchNamespaceMappings,
-                       $wgContentNamespaces;
-
+       public function namespacesInIndexType( $indexType ) {
                if ( $indexType === self::GENERAL_INDEX_TYPE ) {
                        return false;
                }
 
-               $count = count( array_keys( $wgCirrusSearchNamespaceMappings, 
$indexType ) );
+               $mappings = $this->config->get( 'CirrusSearchNamespaceMappings' 
);
+               $count = count( array_keys( $mappings, $indexType ) );
                if ( $indexType === self::CONTENT_INDEX_TYPE ) {
                        // The content namespace includes everything set in the 
mappings to content (count right now)
                        // Plus everything in wgContentNamespaces that isn't 
already in namespace mappings
-                       $count += count( array_diff( $wgContentNamespaces, 
array_keys( $wgCirrusSearchNamespaceMappings ) ) );
+                       $contentNamespaces = $this->config->get( 
'ContentNamespaces' );
+                       $count += count( array_diff( $contentNamespaces, 
array_keys( $mappings ) ) );
                }
                return $count;
        }
diff --git a/includes/DataSender.php b/includes/DataSender.php
index de88333..aa409a2 100644
--- a/includes/DataSender.php
+++ b/includes/DataSender.php
@@ -29,8 +29,12 @@
 class DataSender extends ElasticsearchIntermediary {
        const ALL_INDEXES_FROZEN_NAME = 'freeze_everything';
 
-       public function __construct() {
+       /**
+        * @var Connection
+        */
+       public function __construct( Connection $connection ) {
                parent::__construct( null, null );
+               $this->connection = $connection;
                $this->log = LoggerFactory::getInstance( 'CirrusSearch' );
                $this->failedLog = LoggerFactory::getInstance( 
'CirrusSearchChangeFailed' );
        }
@@ -64,8 +68,8 @@
                        $documents[] = $doc;
                }
 
-               $client = Connection::getClient();
-               $type = Connection::getFrozenIndexNameType();
+               $client = $this->connection->getClient();
+               $type = $this->connection->getFrozenIndexNameType();
                // Elasticsearch has a queue capacity of 50 so if $data
                // contains 50 documents it could bump up against the max.  So
                // we chunk it and do them sequentially.
@@ -99,7 +103,7 @@
 
                $this->log->info( "Thawing writes to " . implode( ',', $names ) 
);
 
-               Connection::getFrozenIndexNameType()->deleteIds( $names );
+               $this->connection->getFrozenIndexNameType()->deleteIds( $names 
);
        }
 
        /**
@@ -122,7 +126,7 @@
 
                $ids = new \Elastica\Query\Ids( null, $indexes );
                $ids->addId( self::ALL_INDEXES_FROZEN_NAME );
-               $resp = Connection::getFrozenIndexNameType()->search( $ids );
+               $resp = $this->connection->getFrozenIndexNameType()->search( 
$ids );
 
                if ( $resp->count() === 0 ) {
                        $this->log->debug( "Allowed writes to " . implode( ',', 
$indexes ) );
@@ -154,12 +158,12 @@
 
                $exception = null;
                try {
-                       $pageType = Connection::getPageType( wfWikiId(), 
$indexType );
+                       $pageType = $this->connection->getPageType( wfWikiId(), 
$indexType );
                        $this->start( "sending {numBulk} documents to the 
{indexType} index", array(
                                'numBulk' => $documentCount,
                                'indexType' => $indexType,
                        ) );
-                       $bulk = new \Elastica\Bulk( Connection::getClient() );
+                       $bulk = new \Elastica\Bulk( 
$this->connection->getClient() );
                        if ( $shardTimeout ) {
                                $bulk->setShardTimeout( $shardTimeout );
                        }
@@ -207,7 +211,7 @@
         */
        public function sendDeletes( $ids, $indexType = null ) {
                if ( $indexType === null ) {
-                       $indexes = Connection::getAllIndexTypes();
+                       $indexes = $this->connection->getAllIndexTypes();
                } else {
                        $indexes = array( $indexType );
                }
@@ -224,7 +228,7 @@
                                                'numIds' => $idCount,
                                                'indexType' => $indexType,
                                        ) );
-                                       Connection::getPageType( wfWikiId(), 
$indexType )->deleteIds( $ids );
+                                       $this->connection->getPageType( 
wfWikiId(), $indexType )->deleteIds( $ids );
                                        $this->success();
                                }
                        } catch ( \Elastica\Exception\ExceptionInterface $e ) {
@@ -251,7 +255,7 @@
                        return Status::newFatal( 'cirrussearch-indexes-frozen' 
);
                }
 
-               $client = Connection::getClient();
+               $client = $this->connection->getClient();
                $status = Status::newGood();
                foreach ( array_chunk( $otherActions, 30 ) as $updates ) {
                        $bulk = new \Elastica\Bulk( $client );
@@ -357,7 +361,7 @@
                $names = array();
                $wikiId = wfWikiId();
                foreach ( $indexes as $indexType ) {
-                       $names[] = Connection::getIndexName( $wikiId, 
$indexType );
+                       $names[] = $this->connection->getIndexName( $wikiId, 
$indexType );
                }
                return $names;
        }
diff --git a/includes/ElasticsearchIntermediary.php 
b/includes/ElasticsearchIntermediary.php
index 10701d4..f7fe673 100644
--- a/includes/ElasticsearchIntermediary.php
+++ b/includes/ElasticsearchIntermediary.php
@@ -31,6 +31,10 @@
  */
 class ElasticsearchIntermediary {
        /**
+        * @var Connection
+        */
+       protected $connection;
+       /**
         * @var User|null user for which we're performing this search or null 
in the case of
         * requests kicked off by jobs
         */
@@ -87,6 +91,8 @@
                $this->user = $user;
                $this->slowMillis = round( 1000 * $slowSeconds );
                $this->ut = UserTesting::getInstance();
+               $config = ConfigFactory::getDefaultInstance()->makeConfig( 
'CirrusSearch' );
+               $this->connection = new Connection( $config );
        }
 
        /**
@@ -366,7 +372,7 @@
         * @return array
         */
        private function buildLogContext( $took ) {
-               $client = Connection::getClient();
+               $client = $this->connection->getClient();
                $query = $client->getLastRequest();
                $result = $client->getLastResponse();
 
diff --git a/includes/Hooks.php b/includes/Hooks.php
index 6251554..30a2145 100644
--- a/includes/Hooks.php
+++ b/includes/Hooks.php
@@ -795,7 +795,9 @@
                // almost everything.  The only thing they miss is if a page 
moves from one
                // index to another.  That only happens if it switches 
namespace.
                if ( $title->getNamespace() !== $newTitle->getNamespace() ) {
-                       $oldIndexType = Connection::getIndexSuffixForNamespace( 
$title->getNamespace() );
+                       $config = 
ConfigFactory::getDefaultInstance()->makeConfig( 'CirrusSearch' );
+                       $conn = new Connection( $config );
+                       $oldIndexType = $conn->getIndexSuffixForNamespace( 
$title->getNamespace() );
                        JobQueueGroup::singleton()->push( new Job\DeletePages( 
$title, array(
                                'indexType' => $oldIndexType,
                                'id' => $oldId
diff --git a/includes/Job/ElasticaWrite.php b/includes/Job/ElasticaWrite.php
index b38c17c..20e08f0 100644
--- a/includes/Job/ElasticaWrite.php
+++ b/includes/Job/ElasticaWrite.php
@@ -37,14 +37,16 @@
        protected function doJob() {
                global $wgCirrusSearchDropDelayedJobsAfter;
 
+               $config = ConfigFactory::getDefaultInstance()->makeConfig( 
'CirrusSearch' );
+               $conn = new Connection( $config );
                if ( $this->params['clientSideTimeout'] ) {
-                       Connection::setTimeout( 
$this->params['clientSideTimeout'] );
+                       $conn->setTimeout( $this->params['clientSideTimeout'] );
                }
 
                LoggerFactory::getInstance( 'CirrusSearch' )->debug(
                        "Running {$this->params['method']} for " . json_encode( 
$this->params['arguments'] )
                );
-               $sender = new DataSender();
+               $sender = new DataSender( $conn );
                $status = call_user_func_array(
                        array( $sender, $this->params['method'] ),
                        $this->params['arguments']
diff --git a/includes/Maintenance/ReindexForkController.php 
b/includes/Maintenance/ReindexForkController.php
deleted file mode 100644
index cb8cd92..0000000
--- a/includes/Maintenance/ReindexForkController.php
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-
-namespace CirrusSearch\Maintenance;
-use \ForkController;
-
-/**
- * Extensions to ForkController to prepare Elastica and to tell the child
- * process which one it is.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- */
-class ReindexForkController extends ForkController {
-       protected function prepareEnvironment() {
-               parent::prepareEnvironment();
-               \CirrusSearch\Connection::destroySingleton();
-       }
-}
diff --git a/includes/Maintenance/Reindexer.php 
b/includes/Maintenance/Reindexer.php
index ff5e9dc..810c814 100644
--- a/includes/Maintenance/Reindexer.php
+++ b/includes/Maintenance/Reindexer.php
@@ -142,8 +142,8 @@
                        'routing.allocation.total_shards_per_node' => 
$maxShardsPerNode,
                ) );
 
-               $sender = new DataSender();
-               $frozenIndexes = Connection::indexToIndexTypes( $this->types );
+               $sender = new DataSender( $this->connection );
+               $frozenIndexes = $conn->indexToIndexTypes( $this->types );
                $sender->freezeIndexes( $frozenIndexes );
                if ( $processes > 1 ) {
                        if ( !isset( $wgCirrusSearchWikimediaExtraPlugin[ 
'id_hash_mod_filter' ] ) ||
diff --git a/includes/OtherIndexes.php b/includes/OtherIndexes.php
index 12a5bd4..d9e932e 100644
--- a/includes/OtherIndexes.php
+++ b/includes/OtherIndexes.php
@@ -81,14 +81,14 @@
                $updates = array();
 
                // Build multisearch to find ids to update
-               $findIdsMultiSearch = new \Elastica\Multi\Search( 
Connection::getClient() );
+               $findIdsMultiSearch = new \Elastica\Multi\Search( 
$this->connection->getClient() );
                $findIdsClosures = array();
                foreach ( $titles as $title ) {
                        foreach ( OtherIndexes::getExternalIndexes( $title ) as 
$otherIndex ) {
                                if ( $otherIndex === null ) {
                                        continue;
                                }
-                               $type = Connection::getPageType( $otherIndex );
+                               $type = $this->connection->getPageType( 
$otherIndex );
                                $bool = new \Elastica\Filter\Bool();
                                // Note that we need to use the keyword 
indexing of title so the analyzer gets out of the way.
                                $bool->addMust( new \Elastica\Filter\Term( 
array( 'title.keyword' => $title->getText() ) ) );
diff --git a/includes/Sanity/Checker.php b/includes/Sanity/Checker.php
index 00ee595..fe61e66 100644
--- a/includes/Sanity/Checker.php
+++ b/includes/Sanity/Checker.php
@@ -69,7 +69,8 @@
                        } else {
                                if ( $inIndex ) {
                                        $foundInsanityInIndex = false;
-                                       $expectedType = 
Connection::getIndexSuffixForNamespace( $page->getTitle()->getNamespace() );
+                                       $conn = new Connectino;
+                                       $expectedType = 
$conn->getIndexSuffixForNamespace( $page->getTitle()->getNamespace() );
                                        foreach ( $fromIndex as $indexInfo ) {
                                                $matches = array();
                                                if ( !preg_match( 
'/_(.+)_.+$/', $indexInfo->getIndex(), $matches ) ) {
diff --git a/includes/Searcher.php b/includes/Searcher.php
index 2c9af86..cc8ae50 100644
--- a/includes/Searcher.php
+++ b/includes/Searcher.php
@@ -809,9 +809,9 @@
 
                $queryOptions = array();
                $queryOptions[ 'timeout' ] = $this->config->getElement( 
'CirrusSearchSearchShardTimeout', 'default' );
-               Connection::setTimeout( $queryOptions[ 'timeout' ] );
+               $this->connection->setTimeout( $queryOptions[ 'timeout' ] );
 
-               $index = Connection::getIndex( $this->indexBaseName, 
Connection::TITLE_SUGGEST_TYPE );
+               $index = $this->connection->getIndex( $this->indexBaseName, 
Connection::TITLE_SUGGEST_TYPE );
                $logContext = array(
                        'query' => $text,
                        'queryType' => 'comp_suggest'
@@ -949,7 +949,7 @@
                        // very big index...
 
                        // XXX: we support only the content index
-                       $type = Connection::getPageType( $this->indexBaseName, 
Connection::CONTENT_INDEX_TYPE );
+                       $type = $this->connection->getPageType( 
$this->indexBaseName, Connection::CONTENT_INDEX_TYPE );
                        // NOTE: we are already in a poolCounterWork
                        // Multi get is not supported by elastica
                        $redirResponse = null;
@@ -1131,18 +1131,19 @@
                $indexType = $this->pickIndexTypeFromNamespaces();
                $searcher = $this;
                $indexBaseName = $this->indexBaseName;
+               $conn = $this->connection;
                return Util::doPoolCounterWork(
                        'CirrusSearch-Search',
                        $this->user,
-                       function() use ( $searcher, $pageIds, $sourceFiltering, 
$indexType, $indexBaseName ) {
+                       function() use ( $searcher, $pageIds, $sourceFiltering, 
$indexType, $indexBaseName, $conn ) {
                                try {
                                        $searcher->start( "get of 
{indexType}.{pageIds}", array(
                                                'indexType' => $indexType,
                                                'pageIds' => array_map( 
'intval', $pageIds ),
                                        ) );
                                        // Shard timeout not supported on get 
requests so we just use the client side timeout
-                                       Connection::setTimeout( 
$this->config->getElement( 'CirrusSearchClientSideSearchTimeout', 'default' ) );
-                                       $pageType = Connection::getPageType( 
$indexBaseName, $indexType );
+                                       $conn->setTimeout( 
$this->config->getElement( 'CirrusSearchClientSideSearchTimeout', 'default' ) );
+                                       $pageType = $conn->getPageType( 
$indexBaseName, $indexType );
                                        $query = new \Elastica\Query( new 
\Elastica\Query\Ids( null, $pageIds ) );
                                        $query->setParam( '_source', 
$sourceFiltering );
                                        $query->addParam( 'stats', 'get' );
@@ -1161,15 +1162,16 @@
        public function findNamespace( $name ) {
                $searcher = $this;
                $indexBaseName = $this->indexBaseName;
+               $conn = $this->connection;
                return Util::doPoolCounterWork(
                        'CirrusSearch-NamespaceLookup',
                        $this->user,
-                       function() use ( $searcher, $name, $indexBaseName ) {
+                       function() use ( $searcher, $name, $indexBaseName, 
$conn ) {
                                try {
                                        $searcher->start( "lookup namespace for 
{namespaceName}", array(
                                                'namespaceName' => $name,
                                        ) );
-                                       $pageType = 
Connection::getNamespaceType( $indexBaseName );
+                                       $pageType = $conn->getNamespaceType( 
$indexBaseName );
                                        $match = new \Elastica\Query\Match();
                                        $match->setField( 'name', $name );
                                        $query = new \Elastica\Query( $match );
@@ -1402,10 +1404,10 @@
                        $poolCounterType = 'CirrusSearch-Search';
                        $queryOptions[ 'timeout' ] = $this->config->getElement( 
'CirrusSearchSearchShardTimeout', 'default' );
                }
-               Connection::setTimeout( $queryOptions[ 'timeout' ] );
+               $this->connection->setTimeout( $queryOptions[ 'timeout' ] );
 
                // Setup the search
-               $pageType = Connection::getPageType( $this->indexBaseName, 
$indexType );
+               $pageType = $this->connection->getPageType( 
$this->indexBaseName, $indexType );
                $search = $pageType->createSearch( $query, $queryOptions );
                foreach ( $extraIndexes as $i ) {
                        $search->addIndex( $i );
@@ -1520,7 +1522,7 @@
                        // We're searching less than everything but we're going 
across indexes.  Back to the defensive.
                        return true;
                }
-               $namespacesInIndexType = Connection::namespacesInIndexType( 
$indexType );
+               $namespacesInIndexType = 
$this->connection->namespacesInIndexType( $indexType );
                return $nsCount !== $namespacesInIndexType;
        }
 
@@ -1746,7 +1748,7 @@
                $indexTypes = array();
                foreach ( $this->namespaces as $namespace ) {
                        $indexTypes[] =
-                               Connection::getIndexSuffixForNamespace( 
$namespace );
+                               $this->connection->getIndexSuffixForNamespace( 
$namespace );
                }
                $indexTypes = array_unique( $indexTypes );
                return count( $indexTypes ) > 1 ? false : $indexTypes[0];
diff --git a/includes/Updater.php b/includes/Updater.php
index 5b672d3..eae1214 100644
--- a/includes/Updater.php
+++ b/includes/Updater.php
@@ -190,9 +190,9 @@
                $titles = $this->pagesToTitles( $pages );
                Job\OtherIndex::queueIfRequired( $titles );
 
-               $allData = array_fill_keys( Connection::getAllIndexTypes(), 
array() );
+               $allData = array_fill_keys( 
$this->connection->getAllIndexTypes(), array() );
                foreach ( $this->buildDocumentsForPages( $pages, $flags ) as 
$document ) {
-                       $suffix = Connection::getIndexSuffixForNamespace( 
$document->get( 'namespace' ) );
+                       $suffix = 
$this->connection->getIndexSuffixForNamespace( $document->get( 'namespace' ) );
                        if ( isset( $wgCirrusSearchWikimediaExtraPlugin[ 
'super_detect_noop' ] ) &&
                                        $wgCirrusSearchWikimediaExtraPlugin[ 
'super_detect_noop' ] ) {
                                $document = $this->docToSuperDetectNoopScript( 
$document );
diff --git a/includes/Version.php b/includes/Version.php
index fe57bcb..5e19b8c 100644
--- a/includes/Version.php
+++ b/includes/Version.php
@@ -44,8 +44,8 @@
                                $this->start( 'fetching elasticsearch version' 
);
                                // If this times out the cluster is in really 
bad shape but we should still
                                // check it.
-                               Connection::setTimeout( 
$wgCirrusSearchClientSideSearchTimeout[ 'default' ] );
-                               $result = Connection::getClient()->request( '' 
);
+                               $this->connection->setTimeout( 
$wgCirrusSearchClientSideSearchTimeout[ 'default' ] );
+                               $result = 
$this->connection->getClient()->request( '' );
                                $this->success();
                        } catch ( \Elastica\Exception\ExceptionInterface $e ) {
                                return $this->failure( $e );
diff --git a/maintenance/freezeWritesToCluster.php 
b/maintenance/freezeWritesToCluster.php
index 51a4240..251ab45 100644
--- a/maintenance/freezeWritesToCluster.php
+++ b/maintenance/freezeWritesToCluster.php
@@ -40,7 +40,9 @@
        }
 
        public function execute() {
-               $sender = new DataSender;
+               $config = ConfigFactory::getDefaultInstance()->makeConfig( 
'CirrusSearch' );
+               $conn = new Connection( $config );
+               $sender = new DataSender( $conn );
                if ( $this->hasOption( 'thaw' ) ) {
                        $sender->thawIndexes();
                        $this->output( "Thawed any existing cluster-wide 
freeze\n\n" );

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

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

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

Reply via email to