From: John Napiorkowski Date: Fri, 9 May 2008 00:31:58 +0000 (+0000) Subject: fixed up the relicant status tests to exclude them if the database is not a real... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4a607d7a92908915aa427a3c9c73a31943b0bb1e;p=dbsrgits%2FDBIx-Class-Historic.git fixed up the relicant status tests to exclude them if the database is not a real replicating setup, removed some debug code, got the lag_behind_master and is_replicating methods working properly. --- diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index 6408cb4..4514e08 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -73,6 +73,18 @@ has 'pool_type' => ( }, ); +=head2 pool_args + +Contains a hashref of initialized information to pass to the Pool object. See +L for available arguments. + +=cut + +has 'pool_args' => ( + is=>'ro', + isa=>'HashRef', +); + =head2 balancer_type The replication pool requires a balance class to provider the methods for @@ -258,7 +270,8 @@ Lazy builder for the L attribute. =cut sub _build_pool { - shift->create_pool; + my $self = shift @_; + $self->create_pool($self->pool_args); } =head2 _build_balancer_type diff --git a/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm b/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm index 1d65b85..8f0d66d 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm @@ -24,7 +24,26 @@ replicants, and gives some methods for querying information about their status. This class defines the following attributes. -=head2 replicant_type +=head2 maximum_lag ($num) + +This is a number which defines the maximum allowed lag returned by the +L method. The default is 0. In +general, this should return a larger number when the replicant is lagging +behind it's master, however the implementation of this is database specific, so +don't count on this number having a fixed meaning. For example, MySQL will +return a number of seconds that the replicating database is lagging. + +=cut + +has 'maximum_lag' => ( + is=>'ro', + isa=>'Num', + required=>1, + lazy=>1, + default=>0, +); + +=head2 replicant_type ($classname) Base class used to instantiate replicants that are in the pool. Unless you need to subclass L you should @@ -107,8 +126,6 @@ L attribute. =cut -use Data::Dump qw/dump/; - sub connect_replicants { my $self = shift @_; my $schema = shift @_; @@ -179,6 +196,31 @@ sub all_replicants { return values %{$self->replicants}; } +=head2 validate_replicants + +This does a check to see if 1) each replicate is connected (or reconnectable), +2) that is ->is_replicating, and 3) that it is not exceeding the lag amount +defined by L. Replicants that fail any of these tests are set to +inactive, and thus removed from the replication pool. + +This tests L, since a replicant that has been previous marked +as inactive can be reactived should it start to pass the validation tests again. + +See L for more about checking if a replicating +connection is not following a master or is lagging. + +Calling this method will generate queries on the replicant databases so it is +not recommended that you run them very often. + +=cut + +sub validate_replicants { + my $self = shift @_; + foreach my $replicant($self->all_replicants) { + + } +} + =head1 AUTHOR John Napiorkowski