Drupal 7 - Autoslave Master/Slave Failover Issue I am using Autoslave (https://drupal.org/project/autoslave) project for implementing mysql high performance and failover. I have successfully setup the mysql master/slave replication at the server and it is working perfectly. With the following settings taken from Autoslave documentation (https://drupal.org/node/1952990) for Master/Slave, I am trying to implement the following use cases:


If Master is up and slave is down, master should entertain all the traffic (working fine)
If Master is down and slave is up, slave should entertain all traffic in readonly mode (NOT WORKING).


With 2, what happens is as soon as the master db is down, the requests to slave also stops. The following are the contents of autoslave-invalidation-default.inc file after i take master db down:

&lt;?php
$databases["default"]["slave"][0]["status"] = FALSE;
$databases["default"]["master"][0]["status"] = FALSE;


Its showing that both servers are down, where as slave is up and running. I tried with manually changing this file and changing slave status to TRUE, and the traffic is then successfully routed to slave.

Following are the relative contents of my settings.php file:

$databases['default']['master'] = array (
  'database' =&gt; 'dbname',
  'username' =&gt; 'username',
  'password' =&gt; 'password',
  'host' =&gt; 'master.ip',
  'port' =&gt; '',
  'driver' =&gt; 'mysql',
  'prefix' =&gt; '',
);

$databases['default']['slave'][] = array (
  'database' =&gt; 'database',
  'username' =&gt; 'username',
  'password' =&gt; 'password',
  'host' =&gt; 'slave.ip',
  'port' =&gt; '',
  'driver' =&gt; 'mysql',
  'prefix' =&gt; '',
  'readonly' =&gt; TRUE
);

$databases['default']['default'] = array (
  'driver' =&gt; 'autoslave',
  'master' =&gt; array('master', 'slave'),
  'slave' =&gt; array('slave', 'master'),
  'invalidation path' =&gt; 'sites/default/files',
  'flag all tables' =&gt; TRUE
);


Following is the error shown:

Error
The website encountered an unexpected error. Please try again later.

Error message

The system is currently in read-only mode. Any changes you make will not be saved!
Warning: mt_rand(): max(0) is smaller than min(1) in DatabaseConnection_autoslave-&gt;rand_weighted() (line 1233 of /includes/database/autoslave/database.inc).
Warning: mt_rand(): max(0) is smaller than min(1) in DatabaseConnection_autoslave-&gt;rand_weighted() (line 1233 of /includes/database/autoslave/database.inc).
Exception: No master connection has been chosen in DatabaseConnection_autoslave-&gt;determineMasterTarget() (line 703 of /includes/database/autoslave/database.inc).


Kindly guide me of the any solutions/suggestions and/or possible reasons why is point 2 not working, where it's suppose to. 

Thanks.
For read-only mode to work properly you must apply the patch from https://drupal.org/node/1889328 (currently committed to 8.x but not backported yet).

The patch https://drupal.org/files/1889328-1-query-options_1.patch will work for 7.x, though it has not yet been cleaned up according to review comments.

I'm not sure I've mentioned this in the documentation, but you must ensure that you use a read-only user for the slave connection when utilising the read-only functionality. Otherwise you may end up writing to the slave-db which could cause inconsistencies and consequently the replication to fail.

The mt_rand() is possibly due to the result of no connections being available (both servers have status = FALSE in the invalidation file). Servers are only re-validated during cron. If you take down the slave to test that scenario, and then spin up the slave again and take down the master without running cron in between, you may end up with the kind of invalidation file you posted.