DCausse has uploaded a new change for review.

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

Change subject: Defer SearchConfig instantiation when it's actually needed
......................................................................

Defer SearchConfig instantiation when it's actually needed

I think something changed in maint scripts, SearchConfig was
instantiated in Maintenance::finalSetup() and copied in
to the new maint script in runChild.
I suppose it's not working anymore (still unclear to me) and
searchConfig remains null when a cirrus maint script is called
via runChild from a non cirrus maint script.
Another problem is related to wfLoadExtension, apparently MediaWikiServices
is not fully configured when finalSetup() is called resulting in:

Fatal error: Uncaught exception 'ConfigException' with message 'No registered 
builder available for CirrusSearch.' in 
/vagrant/mediawiki/includes/config/ConfigFactory.php on line 131

Switching to getter that will lazy load SearchConfig seems to fix
the issue.

Bug: T142153
Bug: T142652
Change-Id: I7f0108c350215eea545170915e7d5abb85f33ad2
---
M includes/Maintenance/Maintenance.php
M maintenance/cirrusNeedsToBeBuilt.php
M maintenance/copySearchIndex.php
M maintenance/dumpIndex.php
M maintenance/forceSearchIndex.php
M maintenance/freezeWritesToCluster.php
M maintenance/indexNamespaces.php
M maintenance/metastore.php
M maintenance/runSearch.php
M maintenance/saneitizeJobs.php
M maintenance/updateOneSearchIndexConfig.php
M maintenance/updateSuggesterIndex.php
M maintenance/updateVersionIndex.php
13 files changed, 39 insertions(+), 33 deletions(-)


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

diff --git a/includes/Maintenance/Maintenance.php 
b/includes/Maintenance/Maintenance.php
index a42eb9c..86c22d9 100644
--- a/includes/Maintenance/Maintenance.php
+++ b/includes/Maintenance/Maintenance.php
@@ -38,7 +38,7 @@
        /**
         * @var SearchConfig
         */
-       protected $searchConfig;
+       private $searchConfig;
 
        public function __construct() {
                parent::__construct();
@@ -47,9 +47,6 @@
 
        public function finalSetup() {
                parent::finalSetup();
-               $this->searchConfig = MediaWikiServices::getInstance()
-                       ->getConfigFactory()
-                       ->makeConfig( 'CirrusSearch' );
        }
 
        /**
@@ -72,22 +69,31 @@
         */
        public function getConnection( $cluster = null ) {
                if( $cluster ) {
-                       if ( $this->searchConfig instanceof SearchConfig ) {
-                               if (!$this->searchConfig->getElement( 
'CirrusSearchClusters', $cluster ) ) {
+                       if ( $this->getSearchConfig() instanceof SearchConfig ) 
{
+                               if (!$this->getSearchConfig()->getElement( 
'CirrusSearchClusters', $cluster ) ) {
                                        $this->error( 'Unknown cluster.', 1 );
                                }
-                               return Connection::getPool( 
$this->searchConfig, $cluster );
+                               return Connection::getPool( 
$this->getSearchConfig(), $cluster );
                        } else {
                                // We shouldn't ever get here ... but the 
makeConfig type signature returns the parent class of SearchConfig
                                // so just being extra careful...
-                               throw new \RuntimeException( 'Expected 
instanceof CirrusSearch\SearchConfig, but received ' . get_class( 
$this->searchConfig ) );
+                               throw new \RuntimeException( 'Expected 
instanceof CirrusSearch\SearchConfig, but received ' . get_class( 
$this->getSearchConfig() ) );
                        }
                }
                if ( $this->connection === null ) {
                        $cluster = $this->decideCluster();
-                       $this->connection = Connection::getPool( 
$this->searchConfig, $cluster );
+                       $this->connection = Connection::getPool( 
$this->getSearchConfig(), $cluster );
                }
                return $this->connection;
+       }
+
+       public function getSearchConfig() {
+               if ( $this->searchConfig == null ) {
+                       $this->searchConfig = MediaWikiServices::getInstance()
+                               ->getConfigFactory()
+                               ->makeConfig( 'CirrusSearch' );
+               }
+               return $this->searchConfig;
        }
 
        /**
@@ -98,10 +104,10 @@
                if ( $cluster === null ) {
                        return null;
                }
-               if ( $this->searchConfig->has( 'CirrusSearchServers' ) ) {
+               if ( $this->getSearchConfig()->has( 'CirrusSearchServers' ) ) {
                        $this->error( 'Not configured for cluster operations.', 
1 );
                }
-               $hosts = $this->searchConfig->getElement( 
'CirrusSearchClusters', $cluster );
+               $hosts = $this->getSearchConfig()->getElement( 
'CirrusSearchClusters', $cluster );
                if ( $hosts === null ) {
                        $this->error( 'Unknown cluster.', 1 );
                }
diff --git a/maintenance/cirrusNeedsToBeBuilt.php 
b/maintenance/cirrusNeedsToBeBuilt.php
index ed985b0..142ea5e 100644
--- a/maintenance/cirrusNeedsToBeBuilt.php
+++ b/maintenance/cirrusNeedsToBeBuilt.php
@@ -66,7 +66,7 @@
                foreach ( $this->getConnection()->getAllIndexTypes() as 
$indexType ) {
                        try {
                                $count = $this->getConnection()
-                                       ->getPageType( 
$this->searchConfig->get( SearchConfig::INDEX_BASE_NAME ), $indexType )
+                                       ->getPageType( 
$this->getSearchConfig()->get( SearchConfig::INDEX_BASE_NAME ), $indexType )
                                        ->count();
                        } catch ( \Elastica\Exception\ResponseException $e ) {
                                $this->output( "$indexType doesn't exist.\n" );
diff --git a/maintenance/copySearchIndex.php b/maintenance/copySearchIndex.php
index 33289c3..e6cbcdb 100644
--- a/maintenance/copySearchIndex.php
+++ b/maintenance/copySearchIndex.php
@@ -72,7 +72,7 @@
                global $wgCirrusSearchMaintenanceTimeout;
 
                $this->indexType = $this->getOption( 'indexType' );
-               $this->indexBaseName = $this->getOption( 'baseName', 
$this->searchConfig->get( SearchConfig::INDEX_BASE_NAME ) );
+               $this->indexBaseName = $this->getOption( 'baseName', 
$this->getSearchConfig()->get( SearchConfig::INDEX_BASE_NAME ) );
 
                $reindexChunkSize = $this->getOption( 'reindexChunkSize', 100 );
                $reindexRetryAttempts = $this->getOption( 
'reindexRetryAttempts', 5 );
diff --git a/maintenance/dumpIndex.php b/maintenance/dumpIndex.php
index 5259681..f581f1d 100644
--- a/maintenance/dumpIndex.php
+++ b/maintenance/dumpIndex.php
@@ -108,7 +108,7 @@
                $this->setConnectionTimeout();
 
                $this->indexType = $this->getOption( 'indexType' );
-               $this->indexBaseName = $this->getOption( 'baseName', 
$this->searchConfig->get( SearchConfig::INDEX_BASE_NAME ) );
+               $this->indexBaseName = $this->getOption( 'baseName', 
$this->getSearchConfig()->get( SearchConfig::INDEX_BASE_NAME ) );
 
                $indexTypes = $this->getConnection()->getAllIndexTypes();
                if ( !in_array( $this->indexType, $indexTypes ) ) {
diff --git a/maintenance/forceSearchIndex.php b/maintenance/forceSearchIndex.php
index 1b93b93..d30707f 100644
--- a/maintenance/forceSearchIndex.php
+++ b/maintenance/forceSearchIndex.php
@@ -324,7 +324,7 @@
         * @return bool
         */
        private function simpleCheckIndexes() {
-               $indexBaseName = $this->searchConfig->get( 
SearchConfig::INDEX_BASE_NAME );
+               $indexBaseName = $this->getSearchConfig()->get( 
SearchConfig::INDEX_BASE_NAME );
 
                // Top-level alias needs to exist
                if ( !$this->getConnection()->getIndex( $indexBaseName 
)->exists() ) {
diff --git a/maintenance/freezeWritesToCluster.php 
b/maintenance/freezeWritesToCluster.php
index 929a1af..8f43e50 100644
--- a/maintenance/freezeWritesToCluster.php
+++ b/maintenance/freezeWritesToCluster.php
@@ -40,7 +40,7 @@
        }
 
        public function execute() {
-               $sender = new DataSender( $this->getConnection(), 
$this->searchConfig );
+               $sender = new DataSender( $this->getConnection(), 
$this->getSearchConfig() );
                if ( $this->hasOption( 'thaw' ) ) {
                        $sender->thawIndexes();
                        $this->output( "Thawed any existing cluster-wide 
freeze\n\n" );
diff --git a/maintenance/indexNamespaces.php b/maintenance/indexNamespaces.php
index 7298590..d57bf87 100644
--- a/maintenance/indexNamespaces.php
+++ b/maintenance/indexNamespaces.php
@@ -36,7 +36,7 @@
        public function execute() {
                global $wgContLang;
 
-               $type = $this->getConnection()->getNamespaceType( 
$this->searchConfig->get( SearchConfig::INDEX_BASE_NAME ) );
+               $type = $this->getConnection()->getNamespaceType( 
$this->getSearchConfig()->get( SearchConfig::INDEX_BASE_NAME ) );
 
                $this->outputIndented( "Deleting namespaces..." );
                $type->deleteByQuery( new MatchAll() );
@@ -53,7 +53,7 @@
                foreach ( $namesById as $id => $names ) {
                        $documents[] = new Document( $id, array(
                                'name' => $names,
-                               'wiki' => $this->searchConfig->getWikiId(),
+                               'wiki' => $this->getSearchConfig()->getWikiId(),
                        ) );
                }
                $type->addDocuments( $documents );
diff --git a/maintenance/metastore.php b/maintenance/metastore.php
index c1c4c58..ebd5fd4 100644
--- a/maintenance/metastore.php
+++ b/maintenance/metastore.php
@@ -87,10 +87,10 @@
                } elseif( $this->hasOption( 'show-all-index-versions' ) ) {
                        $this->showIndexVersions();
                } elseif ( $this->hasOption( 'update-index-version' ) ) {
-                       $baseName = $this->getOption( 'index-version-basename', 
$this->searchConfig->get( SearchConfig::INDEX_BASE_NAME ) );
+                       $baseName = $this->getOption( 'index-version-basename', 
$this->getSearchConfig()->get( SearchConfig::INDEX_BASE_NAME ) );
                        $this->updateIndexVersion( $baseName );
                } elseif ( $this->hasOption( 'show-index-version' ) ) {
-                       $baseName = $this->getOption( 'index-version-basename', 
$this->searchConfig->get( SearchConfig::INDEX_BASE_NAME ) );
+                       $baseName = $this->getOption( 'index-version-basename', 
$this->getSearchConfig()->get( SearchConfig::INDEX_BASE_NAME ) );
                        $filter = new \Elastica\Query\BoolQuery();
                        $ids = new \Elastica\Query\Ids();
                        foreach ( $this->getConnection()->getAllIndexTypes() as 
$type ) {
diff --git a/maintenance/runSearch.php b/maintenance/runSearch.php
index f63abef..47292a7 100644
--- a/maintenance/runSearch.php
+++ b/maintenance/runSearch.php
@@ -61,7 +61,7 @@
 
        public function execute() {
                $this->disablePoolCountersAndLogging();
-               $this->indexBaseName = $this->getOption( 'baseName', 
$this->searchConfig->get( SearchConfig::INDEX_BASE_NAME ) );
+               $this->indexBaseName = $this->getOption( 'baseName', 
$this->getSearchConfig()->get( SearchConfig::INDEX_BASE_NAME ) );
 
                $this->applyGlobals();
                $callback = array( $this, 'consume' );
diff --git a/maintenance/saneitizeJobs.php b/maintenance/saneitizeJobs.php
index c1d3009..6adaab6 100644
--- a/maintenance/saneitizeJobs.php
+++ b/maintenance/saneitizeJobs.php
@@ -107,7 +107,7 @@
                $this->minId = $row->min_id;
                /** @suppress PhanUndeclaredProperty */
                $this->maxId = $row->max_id;
-               $profiles = $this->searchConfig->get( 
'CirrusSearchSanitizationProfiles' );
+               $profiles = $this->getSearchConfig()->get( 
'CirrusSearchSanitizationProfiles' );
                uasort( $profiles, function( $a, $b ) {
                        return $a['max_wiki_size'] < $b['max_wiki_size'] ? -1 : 
1;
                } );
@@ -160,7 +160,7 @@
                if ( !MetaStoreIndex::cirrusReady( $this->getConnection() ) ) {
                        $this->error( "Metastore unavailable, please index some 
data first.\n", 1 );
                }
-               $profile = $this->searchConfig->getElement( 
'CirrusSearchSanitizationProfiles', $this->profileName );
+               $profile = $this->getSearchConfig()->getElement( 
'CirrusSearchSanitizationProfiles', $this->profileName );
                $minLoopDuration = $profile['min_loop_duration'];
                $maxJobs = $profile['max_checker_jobs'];
                $maxUpdates = $profile['update_jobs_max_pressure'];
@@ -241,10 +241,10 @@
 
        private function pushJobs() {
                $pushJobFreq = $this->getOption( 'refresh-freq', 2*3600 );
-               if ( !$this->searchConfig->get( 'CirrusSearchSanityCheck' ) ) {
+               if ( !$this->getSearchConfig()->get( 'CirrusSearchSanityCheck' 
) ) {
                        $this->error( "Sanity check disabled, 
abandonning...\n", 1 );
                }
-               $profile = $this->searchConfig->getElement( 
'CirrusSearchSanitizationProfiles', $this->profileName );
+               $profile = $this->getSearchConfig()->getElement( 
'CirrusSearchSanitizationProfiles', $this->profileName );
                $chunkSize = $profile['jobs_chunk_size'];
                $maxJobs = $profile['max_checker_jobs'];
                if ( !$maxJobs || $maxJobs <= 0 ) {
@@ -342,15 +342,15 @@
                $connections = array();
                if ( $this->hasOption( 'cluster' ) ) {
                        $cluster = $this->getOption( 'cluster' );
-                       if ( !$this->searchConfig->clusterExists( $cluster ) ) {
+                       if ( !$this->getSearchConfig()->clusterExists( $cluster 
) ) {
                                $this->error( "Unknown cluster $cluster\n", 1 );
                        }
-                       if ( $this->searchConfig->canWriteToCluster( $cluster ) 
) {
+                       if ( $this->getSearchConfig()->canWriteToCluster( 
$cluster ) ) {
                                $this->error( "$cluster is not writable\n", 1 );
                        }
-                       $connections[$cluster] = Connection::getPool( 
$this->searchConfig, $cluster );
+                       $connections[$cluster] = Connection::getPool( 
$this->getSearchConfig(), $cluster );
                } else {
-                       $connections = 
Connection::getWritableClusterConnections( $this->searchConfig );
+                       $connections = 
Connection::getWritableClusterConnections( $this->getSearchConfig() );
                }
 
                if ( empty( $connections ) ) {
diff --git a/maintenance/updateOneSearchIndexConfig.php 
b/maintenance/updateOneSearchIndexConfig.php
index 8e4f5da..10f344a 100644
--- a/maintenance/updateOneSearchIndexConfig.php
+++ b/maintenance/updateOneSearchIndexConfig.php
@@ -216,7 +216,7 @@
 
                $this->indexType = $this->getOption( 'indexType' );
                $this->startOver = $this->getOption( 'startOver', false );
-               $this->indexBaseName = $this->getOption( 'baseName', 
$this->searchConfig->get( SearchConfig::INDEX_BASE_NAME ) );
+               $this->indexBaseName = $this->getOption( 'baseName', 
$this->getSearchConfig()->get( SearchConfig::INDEX_BASE_NAME ) );
                $this->reindexAndRemoveOk = $this->getOption( 
'reindexAndRemoveOk', false );
                $this->reindexProcesses = $this->getOption( 'reindexProcesses', 
wfIsWindows() ? 1 : 5 );
                $this->reindexAcceptableCountDeviation = 
Util::parsePotentialPercent(
diff --git a/maintenance/updateSuggesterIndex.php 
b/maintenance/updateSuggesterIndex.php
index bfd86c7..0e393c0 100644
--- a/maintenance/updateSuggesterIndex.php
+++ b/maintenance/updateSuggesterIndex.php
@@ -199,7 +199,7 @@
                // Set the timeout for maintenance actions
                $this->setConnectionTimeout();
 
-               $this->indexBaseName = $this->getOption( 'baseName', 
$this->searchConfig->get( SearchConfig::INDEX_BASE_NAME ) );
+               $this->indexBaseName = $this->getOption( 'baseName', 
$this->getSearchConfig()->get( SearchConfig::INDEX_BASE_NAME ) );
                $this->indexChunkSize = $this->getOption( 'indexChunkSize', 100 
);
                $this->indexRetryAttempts = $this->getOption( 
'reindexRetryAttempts', 5 );
 
@@ -263,7 +263,7 @@
         */
        private function canWrite() {
                // Reuse DataSender even if we don't send anything with it.
-               $sender = new DataSender( $this->getConnection(), 
$this->searchConfig );
+               $sender = new DataSender( $this->getConnection(), 
$this->getSearchConfig() );
                return $sender->areIndexesAvailableForWrites( array( 
$this->getIndexTypeName() ) );
        }
 
diff --git a/maintenance/updateVersionIndex.php 
b/maintenance/updateVersionIndex.php
index d8dc78c..a557eed 100644
--- a/maintenance/updateVersionIndex.php
+++ b/maintenance/updateVersionIndex.php
@@ -51,7 +51,7 @@
         *  maint class is being created
         */
        public function execute() {
-               $baseName = $this->getOption( 'baseName', 
$this->searchConfig->get( SearchConfig::INDEX_BASE_NAME ) );
+               $baseName = $this->getOption( 'baseName', 
$this->getSearchConfig()->get( SearchConfig::INDEX_BASE_NAME ) );
                if( $this->hasOption( 'show-all' ) ) {
                        $this->output( "*** updateVersionIndex.php is 
deprecated use metastore.php --show-all-index-versions instead.\n" );
                        $child = $this->runChild( Metastore::class );

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

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

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

Reply via email to