EBernhardson has uploaded a new change for review. https://gerrit.wikimedia.org/r/247348
Change subject: Add support for connect timeout ...................................................................... Add support for connect timeout Allows admins to set a connection timeout per cluster. Useful to failfast if one of the cluster is unreachable. Requires I5c941c9 in Elastica extension. Change-Id: I62accd19e163047ac15a015e3d60878c8c42cb2f (cherry picked from commit 94d71cadffc43dd3e50f812bd39e9e2b281fbbb9) --- M CirrusSearch.php M includes/ClusterSettings.php M includes/Connection.php 3 files changed, 26 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch refs/changes/48/247348/1 diff --git a/CirrusSearch.php b/CirrusSearch.php index 28beb6b..2f6ce92 100644 --- a/CirrusSearch.php +++ b/CirrusSearch.php @@ -212,6 +212,16 @@ // delayed on the Elasticsearch node. $wgCirrusSearchClientSideUpdateTimeout = 120; +// Client side timeout when initializing connections. +// Useful to fail fast if elasticsearch is unreachable. +// Set to 0 to use Elastica defaults (300 sec) +// You can also set this setting for each cluster: +// $wgCirrusSearchClientSideConnectTimeout = array( +// 'cluster1' => 10, +// 'cluster2' => 5, +// ) +$wgCirrusSearchClientSideConnectTimeout = 5; + // The amount of time Elasticsearch will wait for search shard actions before // giving up on them and returning the results from the other shards. Defaults // to 20s for regular searches which is about twice the slowest queries we see. diff --git a/includes/ClusterSettings.php b/includes/ClusterSettings.php index f32a04d..72a2ca0 100644 --- a/includes/ClusterSettings.php +++ b/includes/ClusterSettings.php @@ -71,4 +71,19 @@ throw new \Exception( "If \$wgCirrusSearchDropDelayedJobsAfter is " . "an array it must contain all configured clusters." ); } + + /** + * @return integer Connect timeout to use when initializing connection. + * Fallback to 0 (300 sec) if not specified in cirrus config. + */ + public function getConnectTimeout() { + $timeout = $this->config->get( 'CirrusSearchClientSideConnectTimeout' ); + if ( is_int( $timeout ) ) { + return $timeout; + } elseif ( isset( $timeout[$this->cluster] ) ) { + return $timeout[$this->cluster]; + } + // 0 means no timeout (defaults to 300 sec) + return 0; + } } diff --git a/includes/Connection.php b/includes/Connection.php index 76aed8b..bce4633 100644 --- a/includes/Connection.php +++ b/includes/Connection.php @@ -112,6 +112,7 @@ } else { $this->cluster = $cluster; } + $this->setConnectTimeout( $this->getSettings()->getConnectTimeout() ); // overwrites previous connection if it exists, but these // seemed more centralized than having the entry points // all call a static method unnecessarily. -- To view, visit https://gerrit.wikimedia.org/r/247348 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I62accd19e163047ac15a015e3d60878c8c42cb2f Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CirrusSearch Gerrit-Branch: wmf/1.27.0-wmf.2 Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> Gerrit-Reviewer: DCausse <dcau...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits