1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-28 00:10:57 +01:00

[phabricator] Add mysql slave and read-only database connections

Summary:
Add ability to define mysql slaves and then use that connection on 'r'
connection modes. 'w' connections go to the master server.

Test Plan:
- php -l and checkModule
 - worked in my devbox

Reviewed By: jungejason
Reviewers: dpepper, tuomaspelkonen, jungejason
CC: jungejason, aran
Revert Plan:
sure

Differential Revision: 175
This commit is contained in:
gpatangay 2011-04-28 15:01:35 -07:00
parent 6fb24ba4a4
commit 4a2981252f
3 changed files with 18 additions and 9 deletions

View file

@ -111,6 +111,12 @@ return array(
// The MySQL server to connect to.
'mysql.host' => 'localhost',
// READ-ONLY database connection information
// If you have a read-only slave mysql server, then you can fill out the
// below fields. If not, duplicate the above information for the slave.
'mysql_slave.user' => 'root',
'mysql_slave.pass' => '',
'mysql_slave.host' => 'localhost',
// -- Email ----------------------------------------------------------------- //

View file

@ -20,11 +20,15 @@
abstract class PhabricatorLiskDAO extends LiskDAO {
public function establishConnection($mode) {
$mysql_key = 'mysql';
if ($mode == 'r') {
$mysql_key = 'mysql_slave';
}
return new AphrontMySQLDatabaseConnection(
array(
'user' => PhabricatorEnv::getEnvConfig('mysql.user'),
'pass' => PhabricatorEnv::getEnvConfig('mysql.pass'),
'host' => PhabricatorEnv::getEnvConfig('mysql.host'),
'user' => PhabricatorEnv::getEnvConfig($mysql_key.'.user'),
'pass' => PhabricatorEnv::getEnvConfig($mysql_key.'.pass'),
'host' => PhabricatorEnv::getEnvConfig($mysql_key.'.host'),
'database' => 'phabricator_'.$this->getApplicationName(),
));

View file

@ -159,6 +159,8 @@ abstract class LiskDAO {
const IDS_PHID = 'ids-phid';
const IDS_MANUAL = 'ids-manual';
private $__connections = array();
/**
* Build an empty object.
*
@ -601,14 +603,11 @@ abstract class LiskDAO {
throw new Exception("Unknown mode '{$mode}', should be 'r' or 'w'.");
}
// TODO: We don't do anything with the read/write mode right now, but
// should.
if (!isset($this->__connection)) {
$this->__connection = $this->establishConnection($mode);
if (!isset($this->__connections[$mode])) {
$this->__connections[$mode] = $this->establishConnection($mode);
}
return $this->__connection;
return $this->__connections[$mode];
}