[Bast-commits] r4566 - in DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated: . Balancer

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Thu Jul 10 20:58:29 BST 2008


Author: jnapiorkowski
Date: 2008-07-10 20:58:28 +0100 (Thu, 10 Jul 2008)
New Revision: 4566

Modified:
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm
Log:
fixed regression in the random balancer that I created when I removed the shuffle dependency, changed the syntax for returning the next storage in the pool to make debugging easier

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm	2008-07-09 18:07:17 UTC (rev 4565)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm	2008-07-10 19:58:28 UTC (rev 4566)
@@ -1,6 +1,5 @@
 package DBIx::Class::Storage::DBI::Replicated::Balancer::Random;
 
-use List::Util qw(shuffle);
 use Moose;
 with 'DBIx::Class::Storage::DBI::Replicated::Balancer';
 
@@ -43,8 +42,9 @@
   my $self = shift @_;
   my @active_replicants = $self->pool->active_replicants;
   my $count_active_replicants = $#active_replicants +1;
+  my $random_replicant = int(rand($count_active_replicants));
   
-  return $active_replicants[int(rand($count_active_replicants +1))];
+  return $active_replicants[$random_replicant];
 }
 
 =head1 AUTHOR

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm	2008-07-09 18:07:17 UTC (rev 4565)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm	2008-07-10 19:58:28 UTC (rev 4566)
@@ -136,8 +136,11 @@
   }
     
   ## Get a replicant, or the master if none
-  my $next = $self->$next_storage(@args);
-  return $next ? $next:$self->master; 
+  if(my $next = $self->$next_storage(@args)) {
+    return $next;
+  } else {
+    return $self->master;
+  }
 };
 
 =head2 increment_storage
@@ -184,10 +187,10 @@
   my ($select_single, $self, @args) = @_;
   
   if (my $forced_pool = $args[-1]->{force_pool}) {
-  	delete $args[-1]->{force_pool};
-  	return $self->_get_forced_pool($forced_pool)->select_single(@args); 
+    delete $args[-1]->{force_pool};
+    return $self->_get_forced_pool($forced_pool)->select_single(@args); 
   } else {
-  	$self->increment_storage;
+    $self->increment_storage;
     return $self->$select_single(@args);
   }
 };




More information about the Bast-commits mailing list