X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FReplicated%2FIntroduction.pod;h=828793c621c8225ae626fce99eee2e01f43283d2;hb=7d8f64b992d1de9fd3eef9f1d5729ca74153922f;hp=c48f2a1bd3ea6bc558a391ebccfe5920374336b0;hpb=d4daee7b54e38e4b3d3d0a77759bddc1a4ede6e5;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Storage/DBI/Replicated/Introduction.pod b/lib/DBIx/Class/Storage/DBI/Replicated/Introduction.pod index c48f2a1..828793c 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated/Introduction.pod +++ b/lib/DBIx/Class/Storage/DBI/Replicated/Introduction.pod @@ -41,7 +41,7 @@ support for replication configuration options as well. By default, when you start L, your Schema (L) is assigned a storage_type, which when fully connected will reflect your -underlying storage engine as defined by your choosen database driver. For +underlying storage engine as defined by your chosen database driver. For example, if you connect to a MySQL database, your storage_type will be L Your storage type class will contain database specific code to help smooth over the differences between databases @@ -89,26 +89,25 @@ may wish to do this. Again, if you are using L, I strongly recommend you use (or upgrade to) the latest L, which makes this job even easier. -First, you need to connect your L. Let's assume you have -such a schema called, "MyApp::Schema". +First, you need to get a C<$schema> object and set the storage_type: - use MyApp::Schema; - my $schema = MyApp::Schema->connect($dsn, $user, $pass); + my $schema = MyApp::Schema->clone; + $schema->storage_type([ + '::DBI::Replicated' => { + balancer_type => '::Random', + balancer_args => { + auto_validate_every => 5, + master_read_weight => 1 + }, + pool_args => { + maximum_lag =>2, + }, + } + ]); -Next, you need to set the storage_type. +Then, you need to connect your L. - $schema->storage_type( - ::DBI::Replicated' => { - balancer_type => '::Random', - balancer_args => { - auto_validate_every => 5, - master_read_weight => 1 - }, - pool_args => { - maximum_lag =>2, - }, - } - ); + $schema->connection($dsn, $user, $pass); Let's break down the settings. The method L takes one mandatory parameter, a scalar value, and an option second value which @@ -133,7 +132,7 @@ one that makes sense. balancers have the 'auto_validate_every' option. This is the number of seconds we allow to pass between validation checks on a load balanced replicant. So the higher the number, the more possibility that your reads to the replicant -may be inconsistant with what's on the master. Setting this number too low +may be inconsistent with what's on the master. Setting this number too low will result in increased database loads, so choose a number with care. Our experience is that setting the number around 5 seconds results in a good performance / integrity balance. @@ -160,11 +159,11 @@ database. After you've configured the replicated storage, you need to add the connection information for the replicants: - $schema->storage->connect_replicants( - [$dsn1, $user, $pass, \%opts], - [$dsn2, $user, $pass, \%opts], - [$dsn3, $user, $pass, \%opts], - ); + $schema->storage->connect_replicants( + [$dsn1, $user, $pass, \%opts], + [$dsn2, $user, $pass, \%opts], + [$dsn3, $user, $pass, \%opts], + ); These replicants should be configured as slaves to the master using the instructions for MySQL native replication, or if you are just learning, you