From: Rafael Kitover Date: Sun, 26 Dec 2010 02:04:12 +0000 (-0500) Subject: Improve fallback-to-master/return-to-slave reporting in ::Replicated::Balancer X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8592e2d1;p=dbsrgits%2FDBIx-Class-Historic.git Improve fallback-to-master/return-to-slave reporting in ::Replicated::Balancer (patch from Bill Moseley) --- diff --git a/Changes b/Changes index 44430a5..3b67176 100644 --- a/Changes +++ b/Changes @@ -43,6 +43,8 @@ Revision history for DBIx::Class as it is possible that custom sql with comments was provided - Add forgotten attributes to Admin.pm - Fix incorrect 'having' attribute documentation (RT#64129) + - Improve fallback-to-master/return-to-slave reporting in + ::Replicated::Balancer * Misc - Add extra option groups to DBIC::Optional::Depencencies, to aid diff --git a/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm b/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm index 025048b..279ad51 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 :) =cut +my $on_master; + around 'next_storage' => sub { my ($next_storage, $self, @args) = @_; my $now = time; @@ -141,9 +143,13 @@ around 'next_storage' => sub { ## Get a replicant, or the master if none if(my $next = $self->$next_storage(@args)) { + $self->master->debugobj->print("Moved back to slave\n") if $on_master; + $on_master = 0; return $next; } else { - $self->master->debugobj->print("No Replicants validate, falling back to master reads. "); + $self->master->debugobj->print("No Replicants validate, falling back to master reads.\n") + unless $on_master++; + return $self->master; } };