Slave usage

= When/How to use a slave DB in Openstack =

The ability to use DB slaves/replicas was added into Openstack primarily to address scaling reads to the database. You should use a slave if your single mysql instance is getting overloaded. Setting up the slave is a common task and is left to the operator to figure out.

Configuration
You can add a slave connection by adding the following line in the [database] section of your service conf file:

... [database] connection=nova:nova@mysqlmaster slave_connection=nova:nova@mysqlslave ...

Assumptions/Best practices
The slave_connection is by default empty, when it is not empty we will try to use it. Code that makes use of slave_connection makes the following assumptions:


 * Slaves should be fairly current with the write master. At most, we would expect them to be 100ms behind the current master data.
 * OpenStack provides nothing to monitor the lag between slave and master, this is the operator's responsibility.
 * Code in which slave_connection is used to retrieve data will not cause harmful effects by using slightly older data.

When a slave is useful, when it is not
This is a very traditional application problem whenever we have replicas of a datastore, which one should we use and why. The answer to this question as it relates to Openstack is somewhat simplified but depends on the execution context surrounding the question itself. In general we should NOT use a slave to read from the database immediately after said data has been written, this means any sort of write and retrieve operation should use the master exclusively. In a general case I think this applies almost universally to any sort of customer facing API. Sections of code that just read from the DB then act upon it should in a general sense be safe to read from slaves.