Commit 6831daac authored by Robert Nix's avatar Robert Nix

Merge branch 'update/133/Elastica' into 'master'

Update Elastica for 1.33

See merge request !59
parents 4dbe7856 030cb8d5
<?php
$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
return $cfg;
The development of this software is covered by a [Code of Conduct](https://www.mediawiki.org/wiki/Special:MyLanguage/Code_of_Conduct).
<?php
/**
* Elasticsearch base extension. Used by other extensions to ease working with
* elasticsearch.
*
* 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
*/
if ( function_exists( 'wfLoadExtension' ) ) {
wfLoadExtension( 'Elastica' );
// Keep i18n globals so mergeMessageFileList.php doesn't break
$wgMessagesDirs['Elastica'] = __DIR__ . '/i18n';
/* wfWarn(
'Deprecated PHP entry point used for Elastica extension. Please use wfLoadExtension instead, ' .
'see https://www.mediawiki.org/wiki/Extension_registration for more details.'
); */
return true;
} else {
die( 'This version of the Elastica extension requires MediaWiki 1.25+' );
}
......@@ -16,15 +16,16 @@
"type": "package",
"package": {
"name": "ruflin/elastica",
"version": "5.3.0",
"description": "upstream requires PHP 7.0 hhvm exposes PHP 5 (it's fine to drop this repo once hhvm is completely replaced with php)",
"version": "6.0.2",
"dist": {
"url": "https://github.com/ruflin/Elastica/archive/5.3.0.zip",
"url": "https://github.com/ruflin/Elastica/archive/6.0.2.zip",
"type": "zip"
},
"source": {
"url": "https://github.com/ruflin/Elastica.git",
"type": "git",
"reference": "tags/5.3.0"
"reference": "tags/6.0.2"
},
"autoload": {
"psr-4": {
......@@ -32,8 +33,7 @@
}
},
"require": {
"php": ">=5.5.0",
"elasticsearch/elasticsearch": "5.3.0"
"elasticsearch/elasticsearch": "^6.0"
}
}
},
......@@ -41,18 +41,22 @@
"type": "package",
"package": {
"name": "elasticsearch/elasticsearch",
"version": "5.3.0",
"description": "Forked version on my own github.com/nomoa repo because upstream uses declare(strict_types=1), PHP 7.0 and ext-json >= 1.3.7 but hhvm exposes PHP 5 & ext-json 1.2.1 (it's fine to drop this repo once hhvm is completely replaced with php)",
"version": "v6.0.1",
"version_normalized": "6.0.1.0",
"dist": {
"url": "https://api.github.com/repos/elastic/elasticsearch-php/zipball/50e5b1c63db68839b8acc1f4766769570a27a448",
"type": "zip"
"type": "zip",
"url": "https://codeload.github.com/nomoa/elasticsearch-php/zip/bc9e8674d7df3b9d4d1fb1241b299a82ec63911a",
"reference": "bc9e8674d7df3b9d4d1fb1241b299a82ec63911a"
},
"source": {
"url": "https://github.com/elastic/elasticsearch-php.git",
"url": "https://github.com/nomoa/elasticsearch-php.git",
"type": "git",
"reference": "tags/v5.3.0"
"reference": "bc9e8674d7df3b9d4d1fb1241b299a82ec63911a"
},
"require": {
"php": ">=5.5.0"
"guzzlehttp/ringphp": "~1.0",
"psr/log": "~1.0"
},
"autoload": {
"psr-4": {
......@@ -63,15 +67,15 @@
}
],
"require": {
"php": ">=5.5.9",
"ruflin/elastica": "5.3.0",
"ruflin/elastica": "6.0.2",
"ext-curl": "*"
},
"require-dev": {
"jakub-onderka/php-parallel-lint": "1.0.0",
"jakub-onderka/php-console-highlighter": "0.3.2",
"mediawiki/mediawiki-codesniffer": "18.0.0",
"mediawiki/minus-x": "0.3.1"
"mediawiki/mediawiki-codesniffer": "24.0.0",
"mediawiki/minus-x": "0.3.1",
"mediawiki/mediawiki-phan-config": "0.5.0"
},
"scripts": {
"fix": [
......@@ -83,5 +87,8 @@
"phpcs -p -s",
"minus-x check ."
]
},
"extra": {
"phan-taint-check-plugin": "1.5.0"
}
}
{"headSHA1": "7019d967a36ecaa41c6c7c775467a5ecabbcc074\n", "head": "7019d967a36ecaa41c6c7c775467a5ecabbcc074\n", "remoteURL": "https://gerrit.wikimedia.org/r/mediawiki/extensions/Elastica", "branch": "7019d967a36ecaa41c6c7c775467a5ecabbcc074\n", "headCommitDate": "1523666965"}
\ No newline at end of file
{"head": "cb92585f199c93c8fc9f07c262b48a0eae4bfb32\n", "remoteURL": "https://gerrit.wikimedia.org/r/mediawiki/extensions/Elastica", "headCommitDate": "1552272473", "branch": "cb92585f199c93c8fc9f07c262b48a0eae4bfb32\n", "headSHA1": "cb92585f199c93c8fc9f07c262b48a0eae4bfb32\n"}
\ No newline at end of file
{
"@metadata": {
"authors": [
"Railfail536"
]
},
"elastica-desc": "Podstawowa funkcjonalność [https://www.elasticsearch.org/ Elasticsearch] dla innych rozszerzeń poprzez dostarczanie biblioteki [http://elastica.io/ Elastica]"
}
<?php
use MediaWiki\Logger\LoggerFactory;
/**
* Forms and caches connection to Elasticsearch as well as client objects
* that contain connection information like \Elastica\Index and \Elastica\Type.
......@@ -88,16 +91,16 @@ abstract class ElasticaConnection {
/**
* Callback for \Elastica\Client on request failures.
* @param \Elastica\Connection $connection The current connection to elasticasearch
* @param \Elastica\Exception $e Exception to be thrown if we don't do anything
* @param \Exception $e Exception to be thrown if we don't do anything
*/
function ( $connection, $e ) {
// We only want to try to reconnect on http connection errors
// Beyond that we want to give up fast. Configuring a single connection
// through LVS accomplishes this.
if ( !( $e instanceof \Elastica\Exception\Connection\HttpException ) ) {
wfLogWarning( 'Unknown connection exception communicating with Elasticsearch: ' .
get_class( $e ) );
// This leaves the connection disabled.
LoggerFactory::getInstance( 'Elastica' )
->error( 'Unknown connection exception communicating with Elasticsearch: {class_name}',
[ 'class_name' => get_class( $e ) ] );
return;
}
if ( $e->getError() === CURLE_OPERATION_TIMEOUTED ) {
......@@ -108,8 +111,9 @@ abstract class ElasticaConnection {
throw $e;
}
if ( $e->getError() !== CURLE_COULDNT_CONNECT ) {
wfLogWarning( 'Unexpected connection error communicating with Elasticsearch. Curl code: ' .
$e->getError() );
LoggerFactory::getInstance( 'Elastica' )
->error( 'Unexpected connection error communicating with Elasticsearch. ' .
'Curl code: {curl_code}', [ 'curl_code' => $e->getError() ] );
// This also leaves the connection disabled but at least we have a log of
// what happened.
return;
......@@ -122,8 +126,12 @@ abstract class ElasticaConnection {
// Check if we've hit the host the max # of times. If not, try again
if ( $connectionAttempts[ $host ] < $this->getMaxConnectionAttempts() ) {
wfLogWarning( "Retrying connection to $host after " . $connectionAttempts[ $host ] .
' attempts.' );
LoggerFactory::getInstance( 'Elastica' )
->info( "Retrying connection to {elastic_host} after {attempts} attempts",
[
'elastic_host' => $host,
'attempts' => $connectionAttempts[ $host ],
] );
$connection->setEnabled( true );
}
}
......@@ -165,41 +173,4 @@ abstract class ElasticaConnection {
$this->client = null;
ElasticaHttpTransportCloser::destroySingleton();
}
/**
* @deprecated
*/
public function setTimeout2( $timeout ) {
$this->setTimeout( $timeout );
}
/**
* @deprecated
*/
public function getClient2() {
// This method used to have an optional argument $options, which was
// unused and confusing
return $this->getClient();
}
/**
* @deprecated
*/
public function getIndex2( $name, $type = false, $identifier = false ) {
return $this->getIndex( $name, $type, $identifier );
}
/**
* @deprecated
*/
public function getIndexName2( $name, $type = false, $identifier = false ) {
return $this->getIndexName2( $name, $type, $identifier );
}
/**
* @deprecated
*/
public function destroySingleton() {
$this->destroyClient();
}
}
<?php
use Elastica\Client;
/**
* 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
......@@ -31,7 +34,7 @@ class MWElasticUtils {
*
* @param int $attempts the number of times we retry
* @param callable $func
* @param callable $beforeRetry function called before each retry
* @param callable|null $beforeRetry function called before each retry
* @return mixed
*/
public static function withRetry( $attempts, $func, $beforeRetry = null ) {
......@@ -65,4 +68,105 @@ class MWElasticUtils {
public static function backoffDelay( $errorCount ) {
return rand( 1, (int)pow( 2, 3 + $errorCount ) );
}
/**
* Get index health
*
* @param Client $client
* @param string $indexName
* @return array the index health status
*/
public static function getIndexHealth( Client $client, $indexName ) {
$endpoint = new \Elasticsearch\Endpoints\Cluster\Health;
$endpoint->setIndex( $indexName );
$response = $client->requestEndpoint( $endpoint );
if ( $response->hasError() ) {
throw new \Exception( "Error while fetching index health status: " . $response->getError() );
}
return $response->getData();
}
/**
* Wait for the index to go green
*
* @param Client $client
* @param string $indexName Name of index to wait for
* @param int $timeout In seconds
* @return \Generator|string[]|bool Returns a generator. Generator yields
* string status messages. Generator return value is true if the index is
* green false otherwise.
*/
public static function waitForGreen( Client $client, $indexName, $timeout ) {
$startTime = time();
while ( ( $startTime + $timeout ) > time() ) {
try {
$response = self::getIndexHealth( $client, $indexName );
$status = $response['status'] ?? 'unknown';
if ( $status === 'green' ) {
yield "\tGreen!";
return true;
}
yield "\tIndex is $status retrying...";
sleep( 5 );
} catch ( \Exception $e ) {
yield "Error while waiting for green ({$e->getMessage()}), retrying...";
}
}
return false;
}
/**
* Delete docs by query and wait for it to complete
* via tasks api.
*
* @param \Elastica\Index $index the source index
* @param \Elastica\Query $query the query
* @return \Generator|array[]|\Elastica\Task Returns a generator. Generator yields
* arrays containing task status responses. Generator returns the Task instance
* on completion.
* @throws Exception when task reports failures
*/
public static function deleteByQuery( \Elastica\Index $index, \Elastica\Query $query ) {
$response = $index->deleteByQuery( $query, [
'wait_for_completion' => 'false',
'scroll' => '15m',
] )->getData();
if ( !isset( $response['task'] ) ) {
throw new \Exception( 'No task returned: ' . var_export( $response, true ) );
}
$task = new \Elastica\Task(
$index->getClient(),
$response['task'] );
while ( !$task->isCompleted() ) {
yield $task->getData();
sleep( 5 );
$task->refresh();
}
$response = $task->getData()['response'];
if ( $response['failures'] ) {
throw new \Exception( implode( ', ', $response['failures'] ) );
}
return $task;
}
const METASTORE_INDEX_NAME = 'mw_cirrus_metastore';
const ALL_INDEXES_FROZEN_NAME = 'freeze-everything';
/**
* @param Client $client
* @return bool True when no writes should be sent via $client
*/
public static function isFrozen( Client $client ) {
// TODO: This should be a hook that cirrus implements to tell
// others to not try to write to a cluster.
$ids = ( new \Elastica\Query\Ids() )
->addId( self::ALL_INDEXES_FROZEN_NAME );
$resp = $client
->getIndex( self::METASTORE_INDEX_NAME )
->search( \Elastica\Query::create( $ids ) );
return $resp->count() > 0;
}
}
{
"name": "elastica",
"version": "0.0.0",
"private": true,
"description": "Build tools for the Elastica extension.",
"scripts": {
"test": "grunt test"
},
"devDependencies": {
"grunt": "1.0.2",
"grunt-banana-checker": "0.6.0",
"grunt-contrib-jshint": "1.1.0",
"grunt-jsonlint": "1.1.0"
}
"name": "elastica",
"version": "0.0.0",
"private": true,
"description": "Build tools for the Elastica extension.",
"scripts": {
"test": "grunt test"
},
"devDependencies": {
"grunt": "1.0.3",
"grunt-banana-checker": "0.6.0",
"grunt-contrib-jshint": "1.1.0",
"grunt-jsonlint": "1.1.0"
}
}
Elastica: REL1_31
2018-04-17T22:13:08
Elastica: REL1_33
2019-06-17T19:08:06
7019d96
cb92585
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment