XF 2.1 master slave plugin for database??

It's supported in the core since XF 2.0:

Master/slave support in DB adapter
XF2 introduces master/slave replication via a new DB adapter which allows separate read and write connections to be made. By default, select statements will be sent to the read server and all other statements will be sent to the write server.

You can see a typical example of configuration below:

PHP:
$config['db']['adapterClass'] = 'XF\Db\Mysqli\ReplicationAdapter';
$config['db']['write'] = [
    'host' => '192.168.10.1',
    // ... username, password, dbname etc.
];
$config['db']['read'] = [
    'host' => '192.168.10.2',
    // ... username, password, dbname etc.
];
As well as inferring the correct connection to make from the type of query, you can also control the behavior by prefixing a query with a comment in the form of -- XFDB=modifier.

Where the modifier is one of:
  • fromWrite - forces a specific read query to come from the write server even if it normally wouldn't
  • forceAllWrite - forces this query and all subsequent queries to the write server
  • noForceAllWrite - if this query would normally force all subsequent queries to the write server, this option disables that (useful for a write you know won't be read back immediately or if it is, can tolerate lag)
 
Top Bottom