NAME
DBIx::Class::Storage::DBI::Replicated - ALPHA Replicated database support
SYNOPSIS
The Following example shows how to change an existing $schema to a replicated storage type and update it's connection information to contain a master DSN and an array of slaves.
## Change storage_type in your schema class
$schema->storage_type( '::DBI::Replicated' );
## Set your connection.
$schema->connect(
$dsn, $user, $password, {
AutoCommit => 1,
## Other standard DBI connection or DBD custom attributes added as
## usual. Additionally, we have two custom attributes for defining
## slave information and controlling how the underlying DBD::Multi
slaves_connect_info => [
## Define each slave like a 'normal' DBI connection, but you add
## in a DBD::Multi custom attribute to define how the slave is
## prioritized. Please see DBD::Multi for more.
[$slave1dsn, $user, $password, {%slave1opts, priority=>10}],
[$slave2dsn, $user, $password, {%slave2opts, priority=>10}],
[$slave3dsn, $user, $password, {%slave3opts, priority=>20}],
## add in a preexisting database handle
[$dbh, '','', {priority=>30}],
## DBD::Multi will call this coderef for connects
[sub { DBI->connect(< DSN info >) }, '', '', {priority=>40}],
## If the last item is hashref, we use that for DBD::Multi's
## configuration information. Again, see DBD::Multi for more.
{timeout=>25, failed_max=>2},
],
},
);
## Now, just use the schema as normal
$schema->resultset('Table')->find(< unique >); ## Reads will use slaves
$schema->resultset('Table')->create(\%info); ## Writes will use master
DESCRIPTION
Warning: This class is marked ALPHA. We are using this in development and have some basic test coverage but the code hasn't yet been stressed by a variety of databases. Individual DB's may have quirks we are not aware of. Please use this in development and pass along your experiences/bug fixes.
This class implements replicated data store for DBI. Currently you can define one master and numerous slave database connections. All write-type queries (INSERT, UPDATE, DELETE and even LAST_INSERT_ID) are routed to master database, all read-type queries (SELECTs) go to the slave database.
For every slave database you can define a priority value, which controls data source usage pattern. It uses DBD::Multi, so first the lower priority data sources used (if they have the same priority, the are used randomized), than if all low priority data sources fail, higher ones tried in order.
CONFIGURATION
Please see DBD::Multi for most configuration information.
SEE ALSO
DBI::Class::Storage::DBI, DBD::Multi, DBI
AUTHOR
Norbert Csongrádi <bert@cpan.org>
Peter Siklósi <einon@einon.hu>
John Napiorkowski <john.napiorkowski@takkle.com>
LICENSE
You may distribute this code under the same terms as Perl itself.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 267:
Non-ASCII character seen before =encoding in 'Csongrádi'. Assuming CP1252