Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/53284
Change subject: Added config to make memcached debug scripts proxy-aware.
......................................................................
Added config to make memcached debug scripts proxy-aware.
* This lets mcc.php and mctest.php choose to use or skip things like twemproxy.
Change-Id: Ibe33815fde2b70d86b755d6e8cb17dc362da40f6
---
M includes/objectcache/MemcachedBagOStuff.php
M includes/objectcache/MemcachedPeclBagOStuff.php
M includes/objectcache/MemcachedPhpBagOStuff.php
M maintenance/mcc.php
M maintenance/mctest.php
5 files changed, 51 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/84/53284/1
diff --git a/includes/objectcache/MemcachedBagOStuff.php
b/includes/objectcache/MemcachedBagOStuff.php
index 3f1fa3a..213dac7 100644
--- a/includes/objectcache/MemcachedBagOStuff.php
+++ b/includes/objectcache/MemcachedBagOStuff.php
@@ -29,6 +29,9 @@
class MemcachedBagOStuff extends BagOStuff {
protected $client;
+ protected $servers = array(); // servers this interfaces with (might be
proxies)
+ protected $internalServers = array(); // effective servers (behind any
proxies)
+
/**
* Fill in the defaults for any parameters missing from $params, using
the
* backwards-compatible global variables
@@ -36,6 +39,9 @@
protected function applyDefaultParams( $params ) {
if ( !isset( $params['servers'] ) ) {
$params['servers'] = $GLOBALS['wgMemCachedServers'];
+ }
+ if ( !isset( $params['internalServers'] ) ) {
+ $params['internalServers'] = $params['servers'];
}
if ( !isset( $params['debug'] ) ) {
$params['debug'] = $GLOBALS['wgMemCachedDebug'];
@@ -119,14 +125,28 @@
}
/**
- * Get the underlying client object. This is provided for debugging
- * purposes.
+ * Get the underlying client object. This is provided for debugging
purposes.
*/
public function getClient() {
return $this->client;
}
/**
+ * Get the server list. This is provided for debugging purposes.
+ */
+ public function getServers() {
+ return $this->servers;
+ }
+
+ /**
+ * Get the underlying server list, behind any proxies (like twemcache
servers).
+ * This is provided for debugging purposes.
+ */
+ public function getInternalServers() {
+ return $this->internalServers;
+ }
+
+ /**
* Encode a key for use on the wire inside the memcached protocol.
*
* We encode spaces and line breaks to avoid protocol errors. We encode
diff --git a/includes/objectcache/MemcachedPeclBagOStuff.php
b/includes/objectcache/MemcachedPeclBagOStuff.php
index 36f5ead..43e8df1 100644
--- a/includes/objectcache/MemcachedPeclBagOStuff.php
+++ b/includes/objectcache/MemcachedPeclBagOStuff.php
@@ -33,6 +33,8 @@
*
* Available parameters are:
* - servers: The list of IP:port combinations holding
the memcached servers.
+ * - internalServers: Set this to the list of internal servers if
'servers' are proxies.
+ * This is used by memcached debugging scripts.
* - persistent: Whether to use a persistent connection
* - compress_threshold: The minimum size an object must be before
it is compressed
* - timeout: The read timeout in microseconds
@@ -100,6 +102,9 @@
$servers[] = IP::splitHostAndPort( $host ); // (ip,
port)
}
$this->client->addServers( $servers );
+
+ $this->servers = $params['servers'];
+ $this->internalServers = $params['internalServers'];
}
/**
diff --git a/includes/objectcache/MemcachedPhpBagOStuff.php
b/includes/objectcache/MemcachedPhpBagOStuff.php
index 33a134c..7252bff 100644
--- a/includes/objectcache/MemcachedPhpBagOStuff.php
+++ b/includes/objectcache/MemcachedPhpBagOStuff.php
@@ -33,6 +33,8 @@
*
* Available parameters are:
* - servers: The list of IP:port combinations holding
the memcached servers.
+ * - internalServers: Set this to the list of internal servers if
'servers' are proxies.
+ * This is used by memcached debugging scripts.
* - debug: Whether to set the debug flag in the
underlying client.
* - persistent: Whether to use a persistent connection
* - compress_threshold: The minimum size an object must be before
it is compressed
@@ -47,6 +49,9 @@
$this->client = new MemCachedClientforWiki( $params );
$this->client->set_servers( $params['servers'] );
$this->client->set_debug( $params['debug'] );
+
+ $this->servers = $params['servers'];
+ $this->internalServers = $params['internalServers'];
}
/**
diff --git a/maintenance/mcc.php b/maintenance/mcc.php
index 4e0f291..3a478d5 100644
--- a/maintenance/mcc.php
+++ b/maintenance/mcc.php
@@ -26,25 +26,26 @@
require_once( __DIR__ . '/commandLine.inc' );
$debug = in_array( '--debug', $argv );
+$noproxy = in_array( '--noproxy', $argv );
$help = in_array( '--help', $argv );
if( $help ) {
mccShowUsage();
exit( 0 );
}
+
+$cache = wfGetMainCache();
+if ( !( $cache instanceof MemcachedBagOStuff ) ) {
+ print "MediaWiki isn't configured for Memcached usage\n";
+ exit( 1 );
+}
+$servers = $noproxy ? $cache->getInternalServers() : $cache->getServers();
+
$mcc = new MWMemcached( array(
'persistent' => true,
'debug' => $debug,
) );
-
-if ( $wgMainCacheType === CACHE_MEMCACHED ) {
- $mcc->set_servers( $wgMemCachedServers );
-} elseif( isset( $wgObjectCaches[$wgMainCacheType] ) ) {
- $mcc->set_servers( $wgObjectCaches[$wgMainCacheType]['servers'] );
-} else {
- print "MediaWiki isn't configured for Memcached usage\n";
- exit( 1 );
-}
+$mcc->set_servers( $servers );
/**
* Show this command line tool usage.
@@ -60,6 +61,7 @@
Options:
--debug Set debug mode on the memcached connection.
+ --noproxy Bypass proxy memcached servers
--help This help screen.
Interactive commands:
diff --git a/maintenance/mctest.php b/maintenance/mctest.php
index 42461c5..5e03f48 100644
--- a/maintenance/mctest.php
+++ b/maintenance/mctest.php
@@ -36,6 +36,7 @@
$this->mDescription = "Makes several 'set', 'incr' and 'get'
requests on every"
. " memcached server
and shows a report";
$this->addOption( 'i', 'Number of iterations', false, true );
+ $this->addOption( 'noproxy', 'Bypass proxy memcached servers',
false, true );
$this->addArg( 'server[:port]', 'Memcached server to test, with
optional port', false );
}
@@ -45,13 +46,14 @@
$iterations = $this->getOption( 'i', 100 );
if ( $this->hasArg() ) {
$servers = array( $this->getArg() );
- } elseif ( $wgMainCacheType === CACHE_MEMCACHED ) {
- global $wgMemCachedServers;
- $servers = $wgMemCachedServers ;
- } elseif( isset( $wgObjectCaches[$wgMainCacheType] ) ) {
- $servers = $wgObjectCaches[$wgMainCacheType]['servers'];
} else {
- $this->error( "MediaWiki isn't configured for Memcached
usage", 1 );
+ $cache = wfGetMainCache();
+ if ( !( $cache instanceof MemcachedBagOStuff ) ) {
+ $this->error( "MediaWiki isn't configured for
Memcached usage", 1 );
+ }
+ $servers = $this->hasOption( 'noproxy' )
+ ? $cache->getInternalServers()
+ : $cache->getServers();
}
foreach ( $servers as $server ) {
--
To view, visit https://gerrit.wikimedia.org/r/53284
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibe33815fde2b70d86b755d6e8cb17dc362da40f6
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits