Deploy multiple slaves to your MySQL database on dotCloud
This is an experimental recipe to have more than 1 slave on your MySQL database on dotCloud.
It works like this:
- Deploy one MySQL master/slave service (as usual).
- Add a bunch of separate MySQL standalone (non scaled) services.
- Reconfigure those separate services as slaves of the first one.
- Manually tweak your code to connect either to the master/slave service (for write ops) or to one of the standalone slaves (for read-only things).
This is alpha, and can probably break in many ways. If the main master/slave service does a failover, you might have to manually resync the slaves. The procedure is not complex, but it can take some time if you have a big database.
How to use it
Add the content of the provided dotcloud.yml file to your dotcloud.yml
build file. You don't have to include the
dbwrite section if you
want to use an existing database. You can add more
if you need to.
dbmanager directory to your code.
If you changed the name of the
dbwrite service, or if you added more
slaves, you need to edit
dbmanager/startsync to set
SLAVES environment variables.
dotcloud run myapp.dbmanager ./startsync.
Important note about credentials
After runing the
startsync script, the slave DB credentials
will be wiped out, and replaced with those of the master DB.
So, when connecting to the slave DB
dbread1, remember to use the
host and port shown by
dotcloud info myapp.dbread1, but the
login and password shown by
dotcloud info myapp.dbwrite!
Just to make it clear:
dotcloud info myapp.dbread1 will
still show the old, invalid credentials for the slave databases.
dotcloud info in that case: it does not
know that you have changed the MySQL root password (by setting
up synchronization with another database).
- guess dbwrite and dbread services by parsing
startsyncso it waits for all servers to be ready
- write a crude HTTP service to expose replication status
- add a long running process to check replication status, and optionally force a full resync
- add a mysql proxy service to automate query routing