jenkins-bot has submitted this change and it was merged.

Change subject: Allow Flow to connect to separate DB cluster
......................................................................


Allow Flow to connect to separate DB cluster

This should be backwards compatible: default cluster value of false should load
the core database (where we currently only write data to)

With this, we can now setup Flow data on a separate database.
1 known caveat: update.php will for now always apply patches to core DB, so it
can't be used to patch Flow queries if the data lives somewhere else. We should
get that addressed some time.

Change-Id: I5ec7f3252903a54f82ee9ca4c8aada3ccf0e70c1
---
M Flow.php
M container.php
M includes/DbFactory.php
3 files changed, 44 insertions(+), 8 deletions(-)

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



diff --git a/Flow.php b/Flow.php
index dedc634..16d8777 100755
--- a/Flow.php
+++ b/Flow.php
@@ -177,6 +177,13 @@
 // URL for more information about the Flow notification system
 $wgFlowHelpPage = 
'//www.mediawiki.org/wiki/Special:MyLanguage/Help:Extension:Flow';
 
+// $wgFlowCluster will define what external DB server should be used.
+// If set to false, the current database (wfGetDB) will be used to read/write
+// data from/to. If Flow data is supposed to be stored on an external database,
+// set the value of this variable to the $wgExternalServers key representing
+// that external connection.
+$wgFlowCluster = false;
+
 // Database to use for Flow metadata.  Set to false to use the wiki db.  Any 
number of wikis can
 // and should share the same Flow database.
 $wgFlowDefaultWikiDb = false;
diff --git a/container.php b/container.php
index 0a590f1..40e61cb 100644
--- a/container.php
+++ b/container.php
@@ -17,8 +17,8 @@
 
 // Always returns the correct database for flow storage
 $c['db.factory'] = $c->share( function( $c ) {
-       global $wgFlowDefaultWikiDb;
-       return new Flow\DbFactory( $wgFlowDefaultWikiDb );
+       global $wgFlowDefaultWikiDb, $wgFlowCluster;
+       return new Flow\DbFactory( $wgFlowDefaultWikiDb, $wgFlowCluster );
 } );
 
 // Database Access Layer external from main implementation
diff --git a/includes/DbFactory.php b/includes/DbFactory.php
index b48bc69..3ce6680 100644
--- a/includes/DbFactory.php
+++ b/includes/DbFactory.php
@@ -3,20 +3,49 @@
 namespace Flow;
 
 /**
- * Super simple class,  provide the name of the "wiki" used for flow
- * data.  All classes within flow that need to access the db will go through
- * here
+ * All classes within Flow that need to access the Flow db will go through 
here.
+ *
+ * To access core tables, use wfGetDB() etc. This is solely for Flow-specific
+ * data, which may live on a separate database.
  */
 class DbFactory {
-       public function __construct( $wiki = false ) {
+       /**
+        * @var string|bool Wiki ID, or false for the current wiki
+        */
+       protected $wiki;
+
+       /**
+        * @var string|bool External storage cluster, or false for core
+        */
+       protected $cluster;
+
+       /**
+        * @var string|bool[optional] $wiki Wiki ID, or false for the current 
wiki
+        * @var string|bool[optional] $cluster External storage cluster, or 
false for core
+        */
+       public function __construct( $wiki = false, $cluster = false ) {
                $this->wiki = $wiki;
+               $this->cluster = $cluster;
        }
 
+       /**
+        * @param int $db Index of the connection to get (DB_MASTER, DB_SLAVE or
+        * specific server index)
+        * @param mixed $groups Query groups
+        * @return \DatabaseBase
+        */
        public function getDB( $db, $groups = array() ) {
-               return wfGetDB( $db, $groups, $this->wiki );
+               return $this->getLB()->getConnection( $db, $groups, $this->wiki 
);
        }
 
+       /**
+        * @return \LoadBalancer
+        */
        public function getLB() {
-               return wfGetLB( $this->wiki );
+               if ( $this->cluster !== false ) {
+                       return wfGetLBFactory()->getExternalLB( $this->cluster, 
$this->wiki );
+               } else {
+                       return wfGetLB( $this->wiki );
+               }
        }
 }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I5ec7f3252903a54f82ee9ca4c8aada3ccf0e70c1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org>
Gerrit-Reviewer: Bsitu <bs...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to