Poor-man failover support

Categories

Component ID

1133708

Component name

Poor-man failover support

Component type

module

Maintenance status

Development status

Component security advisory coverage

not-covered

Component created

Component changed

Component body

This special database engine implementation handles failover between a set
of database connections. The current master is centrally stored in a
pluggeable failover agent.

Any type of database engine should work transparently, but this was designed
with MySQL double-master deployment strategy, where no better failover
mechanism is available.

Using this in any kind of serious production context is strongly discouraged.
The application (here Drupal) is the worst place to put the failover logic,
which is best handled by the platform. If your hosting company recommended
you to use this, consider switching to a more professional provider.

To use this engine, copy the whole "failover" directory to includes/database.
This engine is used as any other engine, by declaring the connection in
the settings.php file:

$databases['default']['default'] = array(
  'driver' => 'failover',

  // The name of the driver that will be used to establish the connections.
  'parent_driver' => 'mysql',

  // The servers. Each server is an associative array that can override any of
  // the values defined at the top-level.
  'servers' => array(
    array(
      'host' => 'master-1.local',
    ),
    array(
      'host' => 'master-2.local',
      'port' => '3304',
    ),
  ),

  // The agent. Used to store the current master server.
  'agent' => array('DatabaseFailoverAgent_fs', array('sites/default/.master')),

  // Other standard connection keys.
  'database' => 'mydb',
  'username' => 'myuser',
  'password' => 'mypass',
  'prefix' => '',

  // Optional settings.
  // The number of times to retry to connect to the master server before
  // failing over.
  'retries' => 3,
  // The wait time before retries, in microseconds.
  'wait_time' => 100000,
  // The number of times to multiply the wait time between retries.
  'wait_multiplier' => 2,
  // An array of transcient errors (from the native driver) on which not to
  // failover. It is recommended to ignore at least 1040 and 1203 (Too many
  // connections) on MySQL, as retrying on those would be catastrophic for
  // the infrastructure.
  'transcient_errors' => array(1040, 1203),
);