Gilles has submitted this change and it was merged.

Change subject: Ensure memcached keys are valid ASCII
......................................................................


Ensure memcached keys are valid ASCII

Stop the flood of memcached key errors of the form:

memcached ERROR: Memcached error for key
"flowdb:flow_ref:url:by-source:v3:0:ruwiki:Сталинская_премия_за_выдающиеся_изобретения_и_коренные_усовершенствования_методов_производственной_работы_(1951):4.7"
on server ":": A BAD KEY WAS PROVIDED/CHARACTERS OUT OF RANGE

Change-Id: I26e531f63ff9abf6794b27c8d2c39633f0846c1e
(cherry picked from commit 7c244e7c340012daa4c2fd09f9cc07b63212b467)
---
M includes/Data/Index/FeatureIndex.php
M tests/phpunit/Data/Index/FeatureIndexTest.php
M tests/phpunit/Data/IndexTest.php
M tests/phpunit/Data/Pager/PagerTest.php
4 files changed, 14 insertions(+), 14 deletions(-)

Approvals:
  Ori.livneh: Verified; Looks good to me, approved



diff --git a/includes/Data/Index/FeatureIndex.php 
b/includes/Data/Index/FeatureIndex.php
index 52a3600..6eec95e 100644
--- a/includes/Data/Index/FeatureIndex.php
+++ b/includes/Data/Index/FeatureIndex.php
@@ -693,7 +693,7 @@
                // which would lead to differences in cache key if we don't 
force that
                sort( $attributes );
 
-               return wfForeignMemcKey( self::cachedDbId(), '', $this->prefix, 
implode( ':', $attributes ), Container::get( 'cache.version' ) );
+               return wfForeignMemcKey( self::cachedDbId(), '', $this->prefix, 
md5( implode( ':', $attributes ) ), Container::get( 'cache.version' ) );
        }
 
        /**
diff --git a/tests/phpunit/Data/Index/FeatureIndexTest.php 
b/tests/phpunit/Data/Index/FeatureIndexTest.php
index faa8b26..11eb0f6 100644
--- a/tests/phpunit/Data/Index/FeatureIndexTest.php
+++ b/tests/phpunit/Data/Index/FeatureIndexTest.php
@@ -30,7 +30,7 @@
                $cache->expects( $this->any() )
                        ->method( 'getMulti' )
                        ->will( $this->returnValue( array(
-                               "$dbId:foo:5:$wgFlowCacheVersion" => array(
+                               "$dbId:foo:" . md5( '5' ) . 
":$wgFlowCacheVersion" => array(
                                        array( 'some_row' => 40 ),
                                        array( 'some_row' => 41 ),
                                        array( 'some_row' => 42 ),
@@ -71,7 +71,7 @@
                $cache->expects( $this->any() )
                        ->method( 'getMulti' )
                        ->will( $this->returnValue( array(
-                               "$dbId:foo:5:$wgFlowCacheVersion" => array(
+                               "$dbId:foo:" . md5 ( '5' ) . 
":$wgFlowCacheVersion" => array(
                                        array( 'some_row' => 40 ),
                                        array( 'some_row' => 41 ),
                                        array( 'some_row' => 42 ),
diff --git a/tests/phpunit/Data/IndexTest.php b/tests/phpunit/Data/IndexTest.php
index d9665fc..23f3c56 100644
--- a/tests/phpunit/Data/IndexTest.php
+++ b/tests/phpunit/Data/IndexTest.php
@@ -49,12 +49,12 @@
 
                $db = FeatureIndex::cachedDbId();
                $v = Container::get( 'cache.version' );
-               $bag->set( "$db:unique:1:$v", array( array( 'id' => 1, 'name' 
=> 'foo', 'other' => 'ppp' ) ) );
-               $bag->set( "$db:unique:2:$v", array( array( 'id' => 2, 'name' 
=> 'foo', 'other' => 'qqq' ) ) );
-               $bag->set( "$db:unique:3:$v", array( array( 'id' => 3, 'name' 
=> 'baz', 'other' => 'lll' ) ) );
+               $bag->set( "$db:unique:" . md5( '1' ) . ":$v", array( array( 
'id' => 1, 'name' => 'foo', 'other' => 'ppp' ) ) );
+               $bag->set( "$db:unique:" . md5( '2' ) . ":$v", array( array( 
'id' => 2, 'name' => 'foo', 'other' => 'qqq' ) ) );
+               $bag->set( "$db:unique:" . md5( '3' ) . ":$v", array( array( 
'id' => 3, 'name' => 'baz', 'other' => 'lll' ) ) );
 
-               $bag->set( "$db:secondary:foo:$v", array( array( 'id' => 1 ), 
array( 'id' => 2 ) ) );
-               $bag->set( "$db:secondary:baz:$v", array( array( 'id' => 3 ) ) 
);
+               $bag->set( "$db:secondary:" . md5( 'foo' ) . ":$v", array( 
array( 'id' => 1 ), array( 'id' => 2 ) ) );
+               $bag->set( "$db:secondary:" . md5( 'baz' ) . ":$v", array( 
array( 'id' => 3 ) ) );
 
                $expect = array(
                        array( 'id' => 1, 'name' => 'foo', 'other' => 'ppp', ),
@@ -101,15 +101,15 @@
                // even though, due to uniqueness, there is only one value per 
set of keys
                $db = FeatureIndex::cachedDbId();
                $v = Container::get( 'cache.version' );
-               $bag->set( "$db:unique:1:9:$v", array( array( 'id' => 1, 'ot' 
=> 9, 'name' => 'foo' ) ) );
-               $bag->set( "$db:unique:1:8:$v", array( array( 'id' => 1, 'ot' 
=> 8, 'name' => 'foo' ) ) );
-               $bag->set( "$db:unique:3:7:$v", array( array( 'id' => 3, 'ot' 
=> 7, 'name' => 'baz' ) ) );
+               $bag->set( "$db:unique:" . md5( '1:9' ) . ":$v", array( array( 
'id' => 1, 'ot' => 9, 'name' => 'foo' ) ) );
+               $bag->set( "$db:unique:" . md5( '1:8' ) . ":$v", array( array( 
'id' => 1, 'ot' => 8, 'name' => 'foo' ) ) );
+               $bag->set( "$db:unique:" . md5( '3:7' ) . ":$v", array( array( 
'id' => 3, 'ot' => 7, 'name' => 'baz' ) ) );
 
-               $bag->set( "$db:secondary:foo:$v", array(
+               $bag->set( "$db:secondary:" . md5( 'foo' ) . ":$v", array(
                        array( 'id' => 1, 'ot' => 9 ),
                        array( 'id' => 1, 'ot' => 8 ),
                ) );
-               $bag->set( "$db:secondary:baz:$v", array(
+               $bag->set( "$db:secondary:" . md5( 'baz' ). ":$v", array(
                        array( 'id' => 3, 'ot' => 7 ),
                ) );
 
diff --git a/tests/phpunit/Data/Pager/PagerTest.php 
b/tests/phpunit/Data/Pager/PagerTest.php
index b24f436..0717521 100644
--- a/tests/phpunit/Data/Pager/PagerTest.php
+++ b/tests/phpunit/Data/Pager/PagerTest.php
@@ -447,7 +447,7 @@
                $cache = new BufferedCache( $innerCache );
 
                // preload our answer
-               $bag->set( wfWikiId() . ":prefix:1:$wgFlowCacheVersion", array(
+               $bag->set( wfWikiId() . ":prefix:" . md5( '1' ) . 
":$wgFlowCacheVersion", array(
                        array( 'foo' => 1, 'bar' => 9 ),
                        array( 'foo' => 1, 'bar' => 8 ),
                        array( 'foo' => 1, 'bar' => 7 ),

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I26e531f63ff9abf6794b27c8d2c39633f0846c1e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: wmf/1.27.0-wmf.2
Gerrit-Owner: Ori.livneh <o...@wikimedia.org>
Gerrit-Reviewer: Gilles <gdu...@wikimedia.org>
Gerrit-Reviewer: Ori.livneh <o...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to