From 1f9850057b7eb8704026881d6fec052f61239e0f Mon Sep 17 00:00:00 2001 From: Andrew Kostka Date: Wed, 20 Mar 2024 11:49:42 +0100 Subject: [PATCH 1/2] Revert "Support sharing Elasticsearch indices across multiple wikis (#430)" (#432) This reverts commit 1199a8a6ff1420a860b2f97c06ae387420d53b28. --- .../wbstack/src/Settings/LocalSettings.php | 1 - dist/extensions/CirrusSearch/extension.json | 3 - .../CirrusSearch/includes/SearchConfig.php | 1 - .../UpdateOneSearchIndexConfig.php | 84 ++----------------- dist/wbstack/src/Settings/LocalSettings.php | 1 - pacman.yaml | 2 - 6 files changed, 8 insertions(+), 84 deletions(-) diff --git a/dist-persist/wbstack/src/Settings/LocalSettings.php b/dist-persist/wbstack/src/Settings/LocalSettings.php index 162aa62c9..d069081db 100644 --- a/dist-persist/wbstack/src/Settings/LocalSettings.php +++ b/dist-persist/wbstack/src/Settings/LocalSettings.php @@ -672,7 +672,6 @@ function onSkinTemplateNavigationUniversal( SkinTemplate $skin, array &$links ) // prepends indices with database name $wgCirrusSearchIndexBaseName = $wgDBname; - $wgCirrusSearchIndexSharedName = getenv( 'MW_ELASTICSEARCH_SHARED_INDEX_NAME' ); $wgSearchType = 'CirrusSearch'; $wgCirrusSearchDefaultCluster = 'default'; diff --git a/dist/extensions/CirrusSearch/extension.json b/dist/extensions/CirrusSearch/extension.json index 3ae7afdca..a34fdde7c 100644 --- a/dist/extensions/CirrusSearch/extension.json +++ b/dist/extensions/CirrusSearch/extension.json @@ -609,9 +609,6 @@ "CirrusSearchIndexBaseName": { "value": "__wikiid__" }, - "CirrusSearchIndexSharedName": { - "value": null - }, "CirrusSearchStripQuestionMarks": { "value": "all" }, diff --git a/dist/extensions/CirrusSearch/includes/SearchConfig.php b/dist/extensions/CirrusSearch/includes/SearchConfig.php index 1e308c1c4..35cc6f8c3 100644 --- a/dist/extensions/CirrusSearch/includes/SearchConfig.php +++ b/dist/extensions/CirrusSearch/includes/SearchConfig.php @@ -18,7 +18,6 @@ class SearchConfig implements \Config { // Constants for referring to various config values. Helps prevent fat-fingers public const INDEX_BASE_NAME = 'CirrusSearchIndexBaseName'; - public const INDEX_SHARED_NAME = 'CirrusSearchIndexSharedName'; private const PREFIX_IDS = 'CirrusSearchPrefixIds'; private const CIRRUS_VAR_PREFIX = 'wgCirrus'; diff --git a/dist/extensions/CirrusSearch/maintenance/UpdateOneSearchIndexConfig.php b/dist/extensions/CirrusSearch/maintenance/UpdateOneSearchIndexConfig.php index 494562d0e..4df5d1c7d 100644 --- a/dist/extensions/CirrusSearch/maintenance/UpdateOneSearchIndexConfig.php +++ b/dist/extensions/CirrusSearch/maintenance/UpdateOneSearchIndexConfig.php @@ -38,11 +38,6 @@ * Update the elasticsearch configuration for this index. */ class UpdateOneSearchIndexConfig extends Maintenance { - /** - * @var string - */ - private $indexSharedName; - /** * @var string */ @@ -211,8 +206,6 @@ public function execute() { $this->indexSuffix = $this->getBackCompatOption( 'indexSuffix', 'indexType' ); $this->startOver = $this->getOption( 'startOver', false ); - $this->indexSharedName = $this->getOption( 'sharedName', - $this->getSearchConfig()->get( SearchConfig::INDEX_SHARED_NAME ) ); $this->indexBaseName = $this->getOption( 'baseName', $this->getSearchConfig()->get( SearchConfig::INDEX_BASE_NAME ) ); $this->reindexAndRemoveOk = $this->getOption( 'reindexAndRemoveOk', false ); @@ -312,36 +305,24 @@ private function updateVersions() { } private function validateIndex() { - $this->outputIndented( "Using shared index..." . var_export( (bool)$this->indexSharedName, true ) . "\n" ); - $this->outputIndented( "Real index name..." . $this->getNotAliasedIndex()->getName() . "\n" ); - if ( $this->startOver ) { - if ( $this->indexSharedName ) { - $this->fatalError( "Blowing away index is not supported when using a shared index." ); - } else { - $this->createIndex( $this->getNotAliasedIndex(), true, "Blowing away index to start over..." ); - } - } elseif ( !$this->getNotAliasedIndex()->exists() ) { - $this->createIndex( $this->getNotAliasedIndex(), false, "Creating index..." ); - } - - if ( $this->indexSharedName ) { - $this->createAliases( $this->getSharedIndex() ); + $this->createIndex( true, "Blowing away index to start over..." ); + } elseif ( !$this->getIndex()->exists() ) { + $this->createIndex( false, "Creating index..." ); } $this->validateIndexSettings(); } /** - * @param \Elastica\Index $index * @param bool $rebuild * @param string $msg */ - private function createIndex( $index, $rebuild, $msg ) { + private function createIndex( $rebuild, $msg ) { global $wgCirrusSearchAllFields, $wgCirrusSearchExtraIndexSettings; $indexCreator = new \CirrusSearch\Maintenance\IndexCreator( - $index, + $this->getIndex(), $this->analysisConfig, $this->similarityConfig ); @@ -366,39 +347,6 @@ private function createIndex( $index, $rebuild, $msg ) { } } - /** - * @param \Elastica\Index $index - */ - private function createAliases( $index ) { - $this->outputIndented( "Creating aliases...\n" ); - - $aliases = [ - $this->indexBaseName, - $this->indexBaseName . '_' . $this->indexSuffix, - $this->indexBaseName . '_' . $this->indexSuffix . '_' . $this->indexIdentifier - ]; - - foreach ( $aliases as $alias ) { - $this->outputIndented( "\tMapping " . $alias . " to " . $index->getName() . "..." ); - - $wiki = $this->indexBaseName . '-'; - $status = $this->getConnection()->getClient()->request( - $index->getName() . '/_alias/' . $alias, - 'PUT', - [ - 'routing' => $alias, - 'filter' => [ 'prefix' => [ 'wiki' => $wiki ] ] - ] - ); - - if ( !$status->isOk() ) { - $this->fatalError( $status->getError() ); - } else { - $this->output( "done\n" ); - } - } - } - /** * @return \CirrusSearch\Maintenance\Validators\Validator[] */ @@ -415,7 +363,6 @@ private function getIndexSettingsValidators() { } private function validateIndexSettings() { - $this->outputIndented( "Validating settings...\n" ); $validators = $this->getIndexSettingsValidators(); foreach ( $validators as $validator ) { $status = $validator->validate(); @@ -473,7 +420,7 @@ private function validateSpecificAlias() { $this->getSearchConfig(), $connection, $connection, - $this->getNotAliasedIndex(), + $this->getIndex(), $this->getOldIndex(), $this, array_filter( explode( ',', $this->getOption( 'fieldsToDelete', '' ) ) ) @@ -482,7 +429,7 @@ private function validateSpecificAlias() { $validator = new \CirrusSearch\Maintenance\Validators\SpecificAliasValidator( $this->getConnection()->getClient(), $this->getIndexAliasName(), - $this->getNotAliasedIndex()->getName(), + $this->getSpecificIndexName(), $this->startOver, $reindexer, [ @@ -504,7 +451,7 @@ public function validateAllAlias() { $validator = new \CirrusSearch\Maintenance\Validators\IndexAllAliasValidator( $this->getConnection()->getClient(), $this->getIndexName(), - $this->getNotAliasedIndex()->getName(), + $this->getSpecificIndexName(), $this->startOver, $this->getIndexAliasName(), $this @@ -576,21 +523,6 @@ public function getIndex() { $this->indexBaseName, $this->indexSuffix, $this->indexIdentifier ); } - /** - * @return \Elastica\Index being updated - */ - private function getSharedIndex() { - return $this->getConnection()->getIndex( - $this->indexSharedName, $this->indexSuffix, $this->indexIdentifier ); - } - - /** - * @return \Elastica\Index being updated - */ - private function getNotAliasedIndex() { - return $this->indexSharedName ? $this->getSharedIndex() : $this->getIndex(); - } - /** * @return string name of the index being updated */ diff --git a/dist/wbstack/src/Settings/LocalSettings.php b/dist/wbstack/src/Settings/LocalSettings.php index 162aa62c9..d069081db 100644 --- a/dist/wbstack/src/Settings/LocalSettings.php +++ b/dist/wbstack/src/Settings/LocalSettings.php @@ -672,7 +672,6 @@ function onSkinTemplateNavigationUniversal( SkinTemplate $skin, array &$links ) // prepends indices with database name $wgCirrusSearchIndexBaseName = $wgDBname; - $wgCirrusSearchIndexSharedName = getenv( 'MW_ELASTICSEARCH_SHARED_INDEX_NAME' ); $wgSearchType = 'CirrusSearch'; $wgCirrusSearchDefaultCluster = 'default'; diff --git a/pacman.yaml b/pacman.yaml index 23581948e..64210764b 100644 --- a/pacman.yaml +++ b/pacman.yaml @@ -243,8 +243,6 @@ - .rubocop_todo.yml - Gruntfile.js - Doxyfile - patchUrls: - - https://gerrit.wikimedia.org/r/changes/mediawiki%2Fextensions%2FCirrusSearch~1010190/revisions/4/patch?download - name: WikibaseCirrusSearch artifactUrl: https://codeload.github.com/wikimedia/mediawiki-extensions-WikibaseCirrusSearch/zip/c4e1e83ee231652375a43d1558b4122278cdcb22 artifactLevel: 1 From 697045abff19c48a7cae6b1bb576c4ed240e385b Mon Sep 17 00:00:00 2001 From: Andrew Kostka Date: Wed, 20 Mar 2024 11:56:42 +0100 Subject: [PATCH 2/2] Add ability to override CirrusSearch's base index name (#433) --- dist-persist/wbstack/src/Settings/LocalSettings.php | 2 +- dist/wbstack/src/Settings/LocalSettings.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist-persist/wbstack/src/Settings/LocalSettings.php b/dist-persist/wbstack/src/Settings/LocalSettings.php index d069081db..2f470e782 100644 --- a/dist-persist/wbstack/src/Settings/LocalSettings.php +++ b/dist-persist/wbstack/src/Settings/LocalSettings.php @@ -671,7 +671,7 @@ function onSkinTemplateNavigationUniversal( SkinTemplate $skin, array &$links ) } // prepends indices with database name - $wgCirrusSearchIndexBaseName = $wgDBname; + $wgCirrusSearchIndexBaseName = getenv( 'MW_CIRRUSSEARCH_INDEX_BASE_NAME' ) ?: $wgDBname; $wgSearchType = 'CirrusSearch'; $wgCirrusSearchDefaultCluster = 'default'; diff --git a/dist/wbstack/src/Settings/LocalSettings.php b/dist/wbstack/src/Settings/LocalSettings.php index d069081db..2f470e782 100644 --- a/dist/wbstack/src/Settings/LocalSettings.php +++ b/dist/wbstack/src/Settings/LocalSettings.php @@ -671,7 +671,7 @@ function onSkinTemplateNavigationUniversal( SkinTemplate $skin, array &$links ) } // prepends indices with database name - $wgCirrusSearchIndexBaseName = $wgDBname; + $wgCirrusSearchIndexBaseName = getenv( 'MW_CIRRUSSEARCH_INDEX_BASE_NAME' ) ?: $wgDBname; $wgSearchType = 'CirrusSearch'; $wgCirrusSearchDefaultCluster = 'default';