Update:Remora Database Replication
From MozillaWiki
- 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; }
- For query, use preg_match to detect a write query type(insert, update, replace) and do the right thing.
- Tests
- Tests need to account for replication lag...
- How long to delay? Some way to detect it?
- We need to test everything that writes to the db, some things already have tests for this that need to be modified to deal with replication lag.
- Writes to the /test db/ won't replicate to the real db, obviously, so we probably need to have a replicated real db and a replicated test db.
- For this to work, we need to make the site read from the test db when called by the web tests, user agent detection?
- Tests need to account for replication lag...