Update:Remora Database Replication: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
* Method | * Method | ||
** Cake determines which db to use by the $useDbConfig var in the Model, so in order to implement rw/ro we need to change that var to the correct database. We default to the read-only Shadow db, and change to the default db only when performing a write operation, ideally, though some models may need to read from the rw db because they can't tolerate any replication lag. | ** Cake determines which db to use by the $useDbConfig var in the Model, so in order to implement rw/ro we need to change that var to the correct database. We default to the read-only Shadow db, and change to the default db only when performing a write operation, ideally, though some models may need to read from the rw db because they can't tolerate any replication lag. | ||
** We set a variable to store the name of the ro config, and the rw config as well, var $DbReadConfig and $DbWriteConfig. | |||
** This is pretty simple for the Save and Del methods. | ** This is pretty simple for the Save and Del methods. | ||
<pre> | |||
function save($data = null, $validate = true, $fieldList = array()) { | |||
$this->useDbConfig=$this->useDbWriteConfig; | |||
$ret = parent::save($data, $validate, $fieldList); | |||
$this->useDbConfig=$this->useDbReadConfig; | |||
return $ret; | |||
} | |||
</pre> |
Revision as of 02:15, 21 February 2007
- Method
- Cake determines which db to use by the $useDbConfig var in the Model, so in order to implement rw/ro we need to change that var to the correct database. We default to the read-only Shadow db, and change to the default db only when performing a write operation, ideally, though some models may need to read from the rw db because they can't tolerate any replication lag.
- We set a variable to store the name of the ro config, and the rw config as well, var $DbReadConfig and $DbWriteConfig.
- This is pretty simple for the Save and Del methods.
function save($data = null, $validate = true, $fieldList = array()) { $this->useDbConfig=$this->useDbWriteConfig; $ret = parent::save($data, $validate, $fieldList); $this->useDbConfig=$this->useDbReadConfig; return $ret; }