[Bast-commits] r6267 - in DBIx-Class/0.08/trunk: . lib/DBIx/Class/Storage/DBI lib/DBIx/Class/Storage/DBI/Replicated lib/DBIx/Class/Storage/DBI/Replicated/Balancer

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Fri May 15 02:04:12 GMT 2009


Author: caelum
Date: 2009-05-15 02:04:12 +0000 (Fri, 15 May 2009)
New Revision: 6267

Modified:
   DBIx-Class/0.08/trunk/Makefile.PL
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated.pm
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Types.pm
Log:
minor replication changes - use a real hash merge, clarify master_read_weight, really done with this now.

Modified: DBIx-Class/0.08/trunk/Makefile.PL
===================================================================
--- DBIx-Class/0.08/trunk/Makefile.PL	2009-05-14 15:26:42 UTC (rev 6266)
+++ DBIx-Class/0.08/trunk/Makefile.PL	2009-05-15 02:04:12 UTC (rev 6267)
@@ -81,6 +81,7 @@
   'MooseX::AttributeHelpers'      => 0.12,
   'MooseX::Types',                => 0.10,
   'namespace::clean'              => 0.11,
+  'Hash::Merge',                  => 0.11,
 
   # t/96_is_deteministic_value.t
   'DateTime::Format::Strptime' => 0,

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm	2009-05-14 15:26:42 UTC (rev 6266)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm	2009-05-15 02:04:12 UTC (rev 6267)
@@ -30,11 +30,17 @@
 
 =head2 master_read_weight
 
-A number from 0 to 1 that specifies what weight to give the master when choosing
-which backend to execute a read query on. A value of 0, which is the default,
-does no reads from master, while a value of 1 gives it the same priority as any
-single replicant.
+A number greater than 0 that specifies what weight to give the master when
+choosing which backend to execute a read query on. A value of 0, which is the
+default, does no reads from master, while a value of 1 gives it the same
+priority as any single replicant.
 
+For example: if you have 2 replicants, and a L</master_read_weight> of C<0.5>,
+the chance of reading from master will be C<20%>.
+
+You can set it to a value higher than 1, making master have higher weight than
+any single replicant, if for example you have a very powerful master.
+
 =cut
 
 has master_read_weight => (is => 'rw', isa => Weight, default => sub { 0 });

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Types.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Types.pm	2009-05-14 15:26:42 UTC (rev 6266)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Types.pm	2009-05-15 02:04:12 UTC (rev 6267)
@@ -31,8 +31,8 @@
 
 subtype Weight,
   as Num,
-  where { $_ >= 0 && $_ <= 1 },
-  message { 'weight must be a decimal between 0 and 1' };
+  where { $_ >= 0 },
+  message { 'weight must be a decimal greater than 0' };
 
 =head1 AUTHOR
 

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated.pm	2009-05-14 15:26:42 UTC (rev 6266)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated.pm	2009-05-15 02:04:12 UTC (rev 6267)
@@ -11,6 +11,7 @@
     MooseX::AttributeHelpers => '0.12',
     MooseX::Types => '0.10',
     namespace::clean => '0.11',
+    Hash::Merge => '0.11'
   );
 	
   my @didnt_load;
@@ -33,6 +34,7 @@
 use MooseX::Types::Moose qw/ClassName HashRef Object/;
 use Scalar::Util 'reftype';
 use Carp::Clan qw/^DBIx::Class/;
+use Hash::Merge 'merge';
 
 use namespace::clean -except => 'meta';
 
@@ -110,6 +112,7 @@
   MooseX::AttributeHelpers => 0.12 
   MooseX::Types => 0.10
   namespace::clean => 0.11
+  Hash::Merge => 0.11
   
 You will need to install these modules manually via CPAN or make them part of the
 Makefile for your distribution.
@@ -324,7 +327,7 @@
   my %opts;
   for my $arg (@$info) {
     next unless (reftype($arg)||'') eq 'HASH';
-    %opts = (%opts, %$arg);
+    %opts = %{ merge($arg, \%opts) };
   }
   delete $opts{dsn};
 
@@ -332,10 +335,9 @@
     $self->pool_type(delete $opts{pool_type})
       if $opts{pool_type};
 
-    $self->pool_args({
-      %{ $self->pool_args },
-      %{ delete $opts{pool_args} || {} }
-    });
+    $self->pool_args(
+      merge((delete $opts{pool_args} || {}), $self->pool_args)
+    );
 
     $self->pool($self->_build_pool)
 	if $self->pool;
@@ -345,10 +347,9 @@
     $self->balancer_type(delete $opts{balancer_type})
       if $opts{balancer_type};
 
-    $self->balancer_args({
-      %{ $self->balancer_args },
-      %{ delete $opts{balancer_args} || {} }
-    });
+    $self->balancer_args(
+      merge((delete $opts{balancer_args} || {}), $self->balancer_args)
+    );
 
     $self->balancer($self->_build_balancer)
 	if $self->balancer;
@@ -468,11 +469,21 @@
     $r->[$i] = {} unless $r->[$i];
 
 # merge if two hashes
-    my %opts = map %$_, @$r[$i .. $#{$r}];
+    my @hashes = @$r[$i .. $#{$r}];
+
+    croak "invalid connect_info options"
+      if (grep { reftype($_) eq 'HASH' } @hashes) != @hashes;
+
+    croak "too many hashrefs in connect_info"
+      if @hashes > 2;
+
+    my %opts = %{ merge(reverse @hashes) };
+
+# delete them
     splice @$r, $i+1, ($#{$r} - $i), ();
 
 # merge with master
-    %opts = (%{ $self->_master_connect_info_opts }, %opts);
+    %opts = %{ merge(\%opts, $self->_master_connect_info_opts) };
 
 # update
     $r->[$i] = \%opts;




More information about the Bast-commits mailing list