r48875 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48874‎ | r48875 | r48876 >
Date:13:28, 26 March 2009
Author:werdna
Status:ok
Tags:
Comment:
Allow storage of blobs to ES on foreign wikis, by calling ExternalStore::storeToForeignDefault, related changes including adding an associative array parameter to the ExternalStore constructor. Currently this parameter is just used to specify on which wiki the external store is wanted, but could be expanded in future.
Modified paths:
  • /trunk/phase3/includes/ExternalStore.php (modified) (history)
  • /trunk/phase3/includes/ExternalStoreDB.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ExternalStore.php
@@ -13,8 +13,14 @@
1414 * @ingroup ExternalStorage
1515 */
1616 class ExternalStore {
 17+ var $mParams;
 18+
 19+ function __construct( $params = array() ) {
 20+ $this->mParams = $params;
 21+ }
 22+
1723 /* Fetch data from given URL */
18 - static function fetchFromURL( $url ) {
 24+ static function fetchFromURL( $url, $params = array() ) {
1925 global $wgExternalStores;
2026
2127 if( !$wgExternalStores )
@@ -25,16 +31,16 @@
2632 if( $path == '' )
2733 return false;
2834
29 - $store = self::getStoreObject( $proto );
 35+ $store = self::getStoreObject( $proto, $params );
3036 if ( $store === false )
3137 return false;
3238 return $store->fetchFromURL( $url );
3339 }
3440
3541 /**
36 - * Get an external store object of the given type
 42+ * Get an external store object of the given type, with the given parameters
3743 */
38 - static function getStoreObject( $proto ) {
 44+ static function getStoreObject( $proto, $params = array() ) {
3945 global $wgExternalStores;
4046 if( !$wgExternalStores )
4147 return false;
@@ -48,7 +54,7 @@
4955 return false;
5056 }
5157
52 - return new $class();
 58+ return new $class($params);
5359 }
5460
5561 /**
@@ -57,9 +63,9 @@
5864 * class itself as a parameter.
5965 * Returns the URL of the stored data item, or false on error
6066 */
61 - static function insert( $url, $data ) {
 67+ static function insert( $url, $data, $params = array() ) {
6268 list( $proto, $params ) = explode( '://', $url, 2 );
63 - $store = self::getStoreObject( $proto );
 69+ $store = self::getStoreObject( $proto, $params );
6470 if ( $store === false ) {
6571 return false;
6672 } else {
@@ -73,9 +79,10 @@
7480 * itself. It also fails-over to the next possible clusters.
7581 *
7682 * @param string $data
 83+ * @param array $params Associative array of parameters for the ExternalStore object.
7784 * Returns the URL of the stored data item, or false on error
7885 */
79 - public static function insertToDefault( $data ) {
 86+ public static function insertToDefault( $data, $storageParams = array() ) {
8087 global $wgDefaultExternalStore;
8188 $tryStores = (array)$wgDefaultExternalStore;
8289 $error = false;
@@ -84,7 +91,7 @@
8592 $storeUrl = $tryStores[$index];
8693 wfDebug( __METHOD__.": trying $storeUrl\n" );
8794 list( $proto, $params ) = explode( '://', $storeUrl, 2 );
88 - $store = self::getStoreObject( $proto );
 95+ $store = self::getStoreObject( $proto, $storageParams );
8996 if ( $store === false ) {
9097 throw new MWException( "Invalid external storage protocol - $storeUrl" );
9198 }
@@ -111,4 +118,9 @@
112119 throw new MWException( "Unable to store text to external storage" );
113120 }
114121 }
 122+
 123+ /** Like insertToDefault, but inserts on another wiki */
 124+ public static function insertToForeignDefault( $data, $wiki ) {
 125+ return self::insertToDefault( $data, array( 'wiki' => $wiki ) );
 126+ }
115127 }
Index: trunk/phase3/includes/ExternalStoreDB.php
@@ -26,21 +26,29 @@
2727 */
2828 class ExternalStoreDB {
2929
 30+ function __construct( $params = array() ) {
 31+ $this->mParams = $params;
 32+ }
 33+
3034 /** @todo Document.*/
3135 function &getLoadBalancer( $cluster ) {
32 - return wfGetLBFactory()->getExternalLB( $cluster );
 36+ $wiki = isset($this->mParams['wiki']) ? $this->mParams['wiki'] : false;
 37+
 38+ return wfGetLBFactory()->getExternalLB( $cluster, $wiki );
3339 }
3440
3541 /** @todo Document.*/
3642 function &getSlave( $cluster ) {
 43+ $wiki = isset($this->mParams['wiki']) ? $this->mParams['wiki'] : false;
3744 $lb =& $this->getLoadBalancer( $cluster );
38 - return $lb->getConnection( DB_SLAVE );
 45+ return $lb->getConnection( DB_SLAVE, array(), $wiki );
3946 }
4047
4148 /** @todo Document.*/
4249 function &getMaster( $cluster ) {
 50+ $wiki = isset($this->mParams['wiki']) ? $this->mParams['wiki'] : false;
4351 $lb =& $this->getLoadBalancer( $cluster );
44 - return $lb->getConnection( DB_MASTER );
 52+ return $lb->getConnection( DB_MASTER, array(), $wiki );
4553 }
4654
4755 /** @todo Document.*/

Status & tagging log