[Bast-commits] r7019 - in
DBIx-Class/0.08/branches/new_replication_transaction_fixup:
lib/DBIx/Class/Storage/DBI t
jnapiorkowski at dev.catalyst.perl.org
jnapiorkowski at dev.catalyst.perl.org
Thu Jul 9 23:23:08 GMT 2009
Author: jnapiorkowski
Date: 2009-07-09 23:23:07 +0000 (Thu, 09 Jul 2009)
New Revision: 7019
Modified:
DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated.pm
DBIx-Class/0.08/branches/new_replication_transaction_fixup/t/93storage_replication.t
Log:
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
Modified: DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated.pm
===================================================================
--- DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated.pm 2009-07-09 21:52:22 UTC (rev 7018)
+++ DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated.pm 2009-07-09 23:23:07 UTC (rev 7019)
@@ -48,11 +48,15 @@
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,21 +64,26 @@
[$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<DBIx::Class::Storage::Replicated::Pool> and the replicants attribute for more.
+
+Also see transactions and L</execute_reliably> 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.
- ## 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<DBIx::Class::Storage::Replicated::Pool> and the replicants attribute for
- ## More. Also see transactions and L</execute_reliably> for alternative ways
- ## to force read traffic to the master.
-
=head1 DESCRIPTION
Warning: This class is marked BETA. This has been running a production
Modified: DBIx-Class/0.08/branches/new_replication_transaction_fixup/t/93storage_replication.t
===================================================================
--- DBIx-Class/0.08/branches/new_replication_transaction_fixup/t/93storage_replication.t 2009-07-09 21:52:22 UTC (rev 7018)
+++ DBIx-Class/0.08/branches/new_replication_transaction_fixup/t/93storage_replication.t 2009-07-09 23:23:07 UTC (rev 7019)
@@ -6,6 +6,7 @@
use DBICTest;
use List::Util 'first';
use Scalar::Util 'reftype';
+use File::Spec;
use IO::Handle;
BEGIN {
@@ -142,9 +143,9 @@
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 @@
$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 @@
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 @@
sub cleanup {
my $self = shift @_;
foreach my $slave (@{$self->slave_paths}) {
- unlink $slave;
+ if(-e $slave) {
+ unlink $slave;
+ }
}
}
More information about the Bast-commits
mailing list