=head1 SYNOPSIS
This role is used internally by L<DBIx::Class::Storage::DBI::Replicated>.
-
+
=head1 DESCRIPTION
Given a pool (L<DBIx::Class::Storage::DBI::Replicated::Pool>) of replicated
This attribute returns the next slave to handle a read request. Your L</pool>
attribute has methods to help you shuffle through all the available replicants
-via it's balancer object.
+via its balancer object.
=cut
This method should be defined in the class which consumes this role.
Given a pool object, return the next replicant that will serve queries. The
-default behavior is to grap the first replicant it finds but you can write
+default behavior is to grab the first replicant it finds but you can write
your own subclasses of L<DBIx::Class::Storage::DBI::Replicated::Balancer> to
support other balance systems.
=cut
+my $on_master;
+
around 'next_storage' => sub {
my ($next_storage, $self, @args) = @_;
my $now = time;
## 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;
}
};