From: John Napiorkowski Date: Thu, 9 Jul 2009 23:23:07 +0000 (+0000) Subject: some documention updates and changed the way we find paths for the sqlite dbfiles... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3da4f736201e0e4b0ee3f88411f74226e8f5ff84;p=dbsrgits%2FDBIx-Class-Historic.git some documention updates and changed the way we find paths for the sqlite dbfiles to use File::Spec, which I hope will solve some of the Win32 error messages --- diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index 22f6399..a625f82 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -48,11 +48,15 @@ The Following example shows how to change an existing $schema to a replicated storage type, add some replicated (readonly) databases, and perform reporting tasks. - ## Change storage_type in your schema class +You should set the 'storage_type attribute to a replicated type. You should +also defined you arguments, such as which balancer you want and any arguments +that the Pool object should get. + $schema->storage_type( ['::DBI::Replicated', {balancer=>'::Random'}] ); - ## Add some slaves. Basically this is an array of arrayrefs, where each - ## arrayref is database connect information +Next, you need to add in the Replicants. Basically this is an array of +arrayrefs, where each arrayref is database connect information. Think of these +arguments as what you'd pass to the 'normal' $schema->connect method. $schema->storage->connect_replicants( [$dsn1, $user, $pass, \%opts], @@ -60,20 +64,25 @@ tasks. [$dsn3, $user, $pass, \%opts], ); - ## Now, just use the $schema as normal +Now, just use the $schema as you normally would. Automatically all reads will +be delegated to the replicants, while writes to the master. + $schema->resultset('Source')->search({name=>'etc'}); - ## You can force a given query to use a particular storage using the search - ### attribute 'force_pool'. For example: +You can force a given query to use a particular storage using the search +attribute 'force_pool'. For example: my $RS = $schema->resultset('Source')->search(undef, {force_pool=>'master'}); - - ## Now $RS will force everything (both reads and writes) to use whatever was - ## setup as the master storage. 'master' is hardcoded to always point to the - ## Master, but you can also use any Replicant name. Please see: - ## L and the replicants attribute for - ## More. Also see transactions and L for alternative ways - ## to force read traffic to the master. + +Now $RS will force everything (both reads and writes) to use whatever was setup +as the master storage. 'master' is hardcoded to always point to the Master, +but you can also use any Replicant name. Please see: +L and the replicants attribute for more. + +Also see transactions and L for alternative ways to +force read traffic to the master. In general, you should wrap your statements +in a transaction when you are reading and writing to the same tables at the +same time, since your replicants will often lag a bit behind the master. =head1 DESCRIPTION diff --git a/t/93storage_replication.t b/t/93storage_replication.t index 1a6a3f3..f1743c5 100644 --- a/t/93storage_replication.t +++ b/t/93storage_replication.t @@ -6,6 +6,7 @@ use Test::Exception; use DBICTest; use List::Util 'first'; use Scalar::Util 'reftype'; +use File::Spec; use IO::Handle; BEGIN { @@ -142,9 +143,9 @@ TESTSCHEMACLASSES: { use File::Copy; use base 'DBIx::Class::DBI::Replicated::TestReplication'; - __PACKAGE__->mk_accessors( qw/master_path slave_paths/ ); + __PACKAGE__->mk_accessors(qw/master_path slave_paths/); - ## Set the mastep path from DBICTest + ## Set the master path from DBICTest sub new { my $class = shift @_; @@ -152,9 +153,9 @@ TESTSCHEMACLASSES: { $self->master_path( DBICTest->_sqlite_dbfilename ); $self->slave_paths([ - "t/var/DBIxClass_slave1.db", - "t/var/DBIxClass_slave2.db", - ]); + File::Spec->catfile(qw/t var DBIxClass_slave1.db/), + File::Spec->catfile(qw/t var DBIxClass_slave2.db/), + ]); return $self; } @@ -170,7 +171,10 @@ TESTSCHEMACLASSES: { my @connect_infos = map { [$_,'','',{AutoCommit=>1}] } @dsn; - # try a hashref too + ## Make sure nothing is left over from a failed test + $self->cleanup; + + ## try a hashref too my $c = $connect_infos[0]; $connect_infos[0] = { dsn => $c->[0], @@ -198,7 +202,9 @@ TESTSCHEMACLASSES: { sub cleanup { my $self = shift @_; foreach my $slave (@{$self->slave_paths}) { - unlink $slave; + if(-e $slave) { + unlink $slave; + } } }