[MediaWiki-commits] [Gerrit] Better error handling for memc and some comments - change (mediawiki...Flow)

2013-10-03 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Better error handling for memc and some comments
..


Better error handling for memc and some comments

Change-Id: Ibdd49677c7eac6b8d601ea1d317c0a4d61e42943
---
M includes/Data/MultiDimArray.php
M includes/Data/ObjectManager.php
M includes/Data/RevisionStorage.php
M includes/Model/AbstractRevision.php
M includes/Repository/MultiGetList.php
M includes/Repository/TreeRepository.php
6 files changed, 128 insertions(+), 28 deletions(-)

Approvals:
  Matthias Mullie: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Data/MultiDimArray.php b/includes/Data/MultiDimArray.php
index 3a89928..9ed77db 100644
--- a/includes/Data/MultiDimArray.php
+++ b/includes/Data/MultiDimArray.php
@@ -2,6 +2,29 @@
 
 namespace Flow\Data;
 
+/**
+ * This object can be used to easily set keys in a multi-dimensional array.
+ *
+ * Usage:
+ *
+ *   $arr = new Flow\Data\MultiDimArray;
+ *   $arr[array(1,2,3)] = 4;
+ *   $arr[array(2,3,4)] = 5;
+ *   var_export( $arr-all() );
+ *
+ *   array (
+ * 1 = array (
+ *   2 = array (
+ * 3 = 4,
+ *   ),
+ * ),
+ * 2 = array (
+ *   3 = array (
+ * 4 = 5,
+ *   ),
+ * ),
+ *   )
+ */
 class MultiDimArray implements \ArrayAccess {
protected $data = array();
 
diff --git a/includes/Data/ObjectManager.php b/includes/Data/ObjectManager.php
index 8ac2e5b..dd19e56 100644
--- a/includes/Data/ObjectManager.php
+++ b/includes/Data/ObjectManager.php
@@ -76,36 +76,75 @@
function fromStorageRow( array $row, $object = null );
 }
 
-// An Index is just a store that receives updates via handler.
-// backing store's can be passed via constructor
+/**
+ * Indexes store one or more values bucketed by exact key/value combinations.
+ */
 interface Index extends LifecycleHandler {
-   /// Indexes accept no query options
+   /**
+* Find data models matching the provided equality condition.
+*
+* @param array $keys A map of k,v pairs to find via equality condition
+* @return array|false Cached subset of data model rows matching the
+* equality conditions provided in $keys.
+*/
function find( array $keys );
 
-   /// Indexes accept no query options
+   /**
+* Batch together multiple calls to self::find with minimal network 
round trips.
+*
+* @param array $queries An array of arrays in the form of $keys 
parameter of self::find
+* @return array|false Array of arrays in same order as $queries 
representing batched result set.
+*/
function findMulti( array $queries );
 
-   // Maximum number of items in a single index value
+   /**
+* @return integer Maximum number of items in a single index value
+*/
function getLimit();
 
-   // Can the index locate a result for this keys and options pair
+   /**
+* Query options are not supported at the query level, the index always
+* returns the same value for the same key/value combination.  
Depending on what
+* the query stores it may contain the answers to various options, 
which will require
+* post-processing by the caller.
+*
+* @return boolean Can the index locate a result for this keys and 
options pair
+*/
function canAnswer( array $keys, array $options );
 }
 
-// Compact rows before writing to memcache, expand when receiving back
-// Still returns arrays, just removes unneccessary values
+/**
+ * Compact rows before writing to memcache, expand when receiving back
+ * Still returns arrays, just removes unneccessary values
+ */
 interface Compactor {
-   // Return only the values in $row that will be written to the cache
+   /**
+* @param array $row A data model row to strip unnecessary data from
+* @return array Only the values in $row that will be written to the 
cache
+*/
public function compactRow( array $row );
-   // perform self::compactRow against an array of rows
+
+   /**
+* @param array $rows Multiple data model rows to strip unnecesssary 
data from
+* @return array The provided rows now containing only the values the 
will be written to cache
+*/
public function compactRows( array $rows );
-   // Repopulate BagOStuff::multiGet results with any values removed in 
self::compactRow
+
+   /**
+* Repopulate BagOStuff::multiGet results with any values removed in 
self::compactRow
+*
+* @param array $cached The multi-dimensional array results of 
BagOStuff::multiGet
+* @param array $keyToQuery An array mapping memcache-key to the values 
used to generate that cache key
+* @return array The cached content from memcache along with any data 
stripped in self::compactRow
+*/

[MediaWiki-commits] [Gerrit] Better error handling for memc and some comments - change (mediawiki...Flow)

2013-09-05 Thread EBernhardson (WMF) (Code Review)
EBernhardson (WMF) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/83030


Change subject: Better error handling for memc and some comments
..

Better error handling for memc and some comments

Change-Id: Ibdd49677c7eac6b8d601ea1d317c0a4d61e42943
---
M includes/Data/ObjectManager.php
M includes/Model/AbstractRevision.php
M includes/Repository/MultiGetList.php
M includes/Repository/TreeRepository.php
4 files changed, 34 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/30/83030/1

diff --git a/includes/Data/ObjectManager.php b/includes/Data/ObjectManager.php
index 04cd787..14c3e75 100644
--- a/includes/Data/ObjectManager.php
+++ b/includes/Data/ObjectManager.php
@@ -653,7 +653,7 @@
foreach ( $res as $row ) {
$result[] = (array) $row;
}
-   wfDebugLog( __CLASS__, __METHOD__ . ': ' . print_r( $result, 
true ) );
+   // wfDebugLog( __CLASS__, __METHOD__ . ': ' . print_r( $result, 
true ) );
return $result;
}
 
@@ -1292,6 +1292,11 @@
}
if ( $keys ) {
$flipped = array_flip( $keys );
+   $res = parent::getMulti( $keys );
+   if ( $res === false ) {
+   wfDebugLog( __CLASS__, __FUNCTION__ . ': 
Failure requesting data from memcache : ' . implode( ',', $keys ) );
+   return $found;
+   }
foreach ( parent::getMulti( $keys ) as $key = $value ) 
{
$this-internal[$key] = $found[$key] = $value;
unset( $keys[$flipped[$key]] );
diff --git a/includes/Model/AbstractRevision.php 
b/includes/Model/AbstractRevision.php
index e11b677..9d24a77 100644
--- a/includes/Model/AbstractRevision.php
+++ b/includes/Model/AbstractRevision.php
@@ -12,11 +12,18 @@
 
const MODERATED_CENSORED = 'censor';
 
+   /**
+* Possible moderation states of a revision.  These must be ordered from
+* least restrictive to most restrictive permission.
+*/
static private $perms = array(
self::MODERATED_NONE = array(
+   // The name of the permission checked with 
User::isAllowed
'perm' = null,
-   'usertext' = null,
-   'content' = null
+   // This is the bit of text rendered instead of the 
content
+   'content' = null,
+   // This is the revision comment stored when changing to 
this moderation state
+   'comment' = 'flow-comment-restored',
),
self::MODERATED_HIDDEN = array(
'perm' = 'flow-hide',
@@ -197,10 +204,11 @@
}
 
public function getUserText( $user = null ) {
-   if ( $this-isAllowed( $user ) ) {
-   return $this-getUserTextRaw();
+   // The text of *this* revision is only stripped when fully 
moderated
+   if ( $this-isCensored() ) {
+   return wfMessage( 'flow-comment-censored' );
} else {
-   return wfMessage( 
self::$perms[$this-moderationState]['usertext'] );
+   return $this-getUserTextRaw();
}
}
 
diff --git a/includes/Repository/MultiGetList.php 
b/includes/Repository/MultiGetList.php
index 61b860c..6b3a563 100644
--- a/includes/Repository/MultiGetList.php
+++ b/includes/Repository/MultiGetList.php
@@ -32,7 +32,13 @@
return array();
}
$result = array();
-   foreach ( $this-cache-getMulti( array_keys( $cacheKeys ) ) as 
$key = $value ) {
+   $multiRes = $this-cache-getMulti( array_keys( $cacheKeys ) );
+   if ( $multiRes === false ) {
+   wfDebugLog( __CLASS__, __FUNCTION__ . ': Failure 
querying memcache' );
+   return false;
+   }
+
+   foreach ( $multiRes as $key = $value ) {
if ( $cacheKeys[$key] instanceof UUID ) {
$idx = $cacheKeys[$key]-getBinary();
} else {
diff --git a/includes/Repository/TreeRepository.php 
b/includes/Repository/TreeRepository.php
index 105233f..2d6e98a 100644
--- a/includes/Repository/TreeRepository.php
+++ b/includes/Repository/TreeRepository.php
@@ -215,7 +215,10 @@
$roots,
array( $this, 'fetchSubtreeNodeListFromDb' )
);
-
+   if ( $res === false ) {
+   wfDebugLog( __CLASS__, __FUNCTION__ . ': Failure 
fetching node list from