mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-09 16:32:39 +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:
parent
6fb24ba4a4
commit
4a2981252f
3 changed files with 18 additions and 9 deletions
|
@ -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 ----------------------------------------------------------------- //
|
||||
|
||||
|
|
|
@ -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(),
|
||||
));
|
||||
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue