[Dbix-class] Patch for Replicated::Balancer
Bill Moseley
moseley at hank.org
Sat Dec 11 15:41:07 GMT 2010
It's expected that a slaves could be pulled out of service due to
maintenance or large lag delay.
This patch adds a new line and only reports it once per process. All of
this could be done in a custom debug class, of course. But, I'm not clear
how common it is for people to use their own debug object.
diff --git a/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm
b/lib/DBIx/Class/
index 025048b..e79cb39 100644
--- a/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm
+++ b/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm
@@ -127,6 +127,8 @@ or just just forgot to create them :)
=3Dcut
+my $on_master;
+
around 'next_storage' =3D> sub {
my ($next_storage, $self, @args) =3D @_;
my $now =3D time;
@@ -141,9 +143,13 @@ around 'next_storage' =3D> sub {
## Get a replicant, or the master if none
if(my $next =3D $self->$next_storage(@args)) {
+ $self->master->debugobj->print("$$ Moved back to slave\n") if
$on_master;
+ $on_master =3D 0;
return $next;
} else {
- $self->master->debugobj->print("No Replicants validate, falling back to
mas
+ $self->master->debugobj->print("No Replicants validate, falling back
to
+ unless $on_master++;
+
return $self->master;
}
};
-- =
Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20101211/366=
397c7/attachment.htm
More information about the DBIx-Class
mailing list