[Bast-commits] r4313 - in DBIx-Class/0.08/branches/replication_dedux: lib/DBIx/Class/Storage/DBI lib/DBIx/Class/Storage/DBI/Replicated t

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Wed Apr 30 23:50:09 BST 2008


Author: jnapiorkowski
Date: 2008-04-30 23:50:09 +0100 (Wed, 30 Apr 2008)
New Revision: 4313

Modified:
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm
   DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t
Log:
cleanup of some docs, got the default shuffling balancer to work properly.  Don't fall in love with this behavior, since I'm probably going to change the default to balancer to just return the first replicant in the list, since this is optimised for the common case of a single replicant

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm	2008-04-30 22:30:47 UTC (rev 4312)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm	2008-04-30 22:50:09 UTC (rev 4313)
@@ -101,7 +101,7 @@
 
 This class defines the following methods.
 
-=head2 create_replicants ($schema, Array[$connect_info])
+=head2 connect_replicants ($schema, Array[$connect_info])
 
 Given an array of $dsn suitable for connected to a database, create an
 L<DBIx::Class::Storage::DBI::Replicated::Replicant> object and store it in the
@@ -109,7 +109,7 @@
 
 =cut
 
-sub create_replicants {
+sub connect_replicants {
 	my $self = shift @_;
 	my $schema = shift @_;
 	

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm	2008-04-30 22:30:47 UTC (rev 4312)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm	2008-04-30 22:50:09 UTC (rev 4313)
@@ -16,7 +16,7 @@
 
 The Following example shows how to change an existing $schema to a replicated
 storage type, add some replicated (readonly) databases, and perform reporting
-tasks
+tasks.
 
     ## Change storage_type in your schema class
     $schema->storage_type( '::DBI::Replicated' );
@@ -24,16 +24,11 @@
     ## Add some slaves.  Basically this is an array of arrayrefs, where each
     ## arrayref is database connect information
     
-    $schema->storage->create_replicants(
+    $schema->storage->connect_replicants(
         [$dsn1, $user, $pass, \%opts],
         [$dsn1, $user, $pass, \%opts],
         [$dsn1, $user, $pass, \%opts],
-        ## This is just going to use the standard DBIC connect method, so it
-        ## supports everything that method supports, such as connecting to an
-        ## existing database handle.
-        [$dbh],
     );
-
     
 =head1 DESCRIPTION
 
@@ -114,20 +109,6 @@
 attribute has methods to help you shuffle through all the available replicants
 via it's balancer object.
 
-This attribute defines the following reader/writer methods
-
-=over 4
-
-=item get_current_replicant
-
-Returns the contained L<DBIx::Class::Storage::DBI> replicant
-
-=item set_current_replicant
-
-Set the attribute to a given L<DBIx::Class::Storage::DBI> (or subclass) object.
-
-=back
-
 We split the reader/writer to make it easier to selectively override how the
 replicant is altered.
 
@@ -135,8 +116,6 @@
 
 has 'current_replicant' => (
     is=> 'rw',
-    reader=>'get_current_replicant',
-    writer=>'set_current_replicant',
     isa=>'DBIx::Class::Storage::DBI',
     lazy_build=>1,
     handles=>[qw/
@@ -199,7 +178,7 @@
     handles=>[qw/
         replicants
         has_replicants
-        create_replicants
+        connect_replicants
         num_replicants
         delete_replicant
     /],
@@ -278,13 +257,13 @@
 
 =cut
 
-around 'create_replicants' => sub {
+around 'connect_replicants' => sub {
 	my ($method, $self, @args) = @_;
 	$self->$method($self->schema, @args);
 };
 
 
-=head2 after: get_current_replicant_storage
+=head2 after: select, select_single, columns_info_for
 
 Advice on the current_replicant_storage attribute.  Each time we use a replicant
 we need to change it via the storage pool algorithm.  That way we are spreading
@@ -292,15 +271,27 @@
 
 =cut
 
-after 'current_replicant' => sub {
+after 'select' => sub {
     my $self = shift @_;
     my $next_replicant = $self->next_storage($self->pool);
 
-warn '......................';
-    $self->set_current_replicant($next_replicant);
+    $self->current_replicant($next_replicant);
 };
 
+after 'select_single' => sub {
+    my $self = shift @_;
+    my $next_replicant = $self->next_storage($self->pool);
 
+    $self->current_replicant($next_replicant);
+};
+
+after 'columns_info_for' => sub {
+    my $self = shift @_;
+    my $next_replicant = $self->next_storage($self->pool);
+
+    $self->current_replicant($next_replicant);
+};
+
 =head2 all_storages
 
 Returns an array of of all the connected storage backends.  The first element
@@ -534,20 +525,13 @@
         	## 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 => [
+        	connect_replicants => [
         	   ## 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},      	   
+        	   [$slave1dsn, $user, $password, {%slave1opts}],
+               [$slave2dsn, $user, $password, {%slave2opts}],
+               [$slave3dsn, $user, $password, {%slave3opts}],
         	],
         },
     );

Modified: DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t	2008-04-30 22:30:47 UTC (rev 4312)
+++ DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t	2008-04-30 22:50:09 UTC (rev 4313)
@@ -120,7 +120,7 @@
 ok my @replicant_connects = $replicated->generate_replicant_connect_info
     => 'got replication connect information';
 
-ok my @replicated_storages = $replicated->schema->storage->create_replicants(@replicant_connects)
+ok my @replicated_storages = $replicated->schema->storage->connect_replicants(@replicant_connects)
     => 'Created some storages suitable for replicants';
     
 isa_ok $replicated->schema->storage->current_replicant




More information about the Bast-commits mailing list