From: John Napiorkowski Date: Fri, 19 Dec 2008 19:52:44 +0000 (+0000) Subject: more noise debugging messages if debug is on, minor doc tweaks, changes so that the... X-Git-Tag: v0.08240~215 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=13b9e8285fc913aa88469afa8d28fd3cd33e04cc;p=dbsrgits%2FDBIx-Class.git more noise debugging messages if debug is on, minor doc tweaks, changes so that the fake sqlite tests will work and laid the groundwork for replication without dbatabase native replication support. --- diff --git a/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm b/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm index 5021ed9..8af899c 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm @@ -126,19 +126,20 @@ or just just forgot to create them :) around 'next_storage' => sub { my ($next_storage, $self, @args) = @_; my $now = time; - + ## Do we need to validate the replicants? if( $self->has_auto_validate_every && ($self->auto_validate_every + $self->pool->last_validated) <= $now - ) { + ) { $self->pool->validate_replicants; } - + ## Get a replicant, or the master if none if(my $next = $self->$next_storage(@args)) { return $next; } else { + $self->master->debugobj->print("No Replicants validate, falling back to master reads. "); return $self->master; } }; diff --git a/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm b/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm index a3db265..833ffad 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm @@ -189,7 +189,14 @@ sub _safely_ensure_connected { my ($self, $replicant, @args) = @_; my $return; eval { $return = $replicant->ensure_connected(@args); - }; + }; if ($@) { + $replicant + ->debugobj + ->print( + sprintf( "Exception trying to ->ensure_connected for replicant %s, error is %s", + $self->_dbi_connect_info->[0], $@) + ); + } return $return; } @@ -259,23 +266,43 @@ 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. +This method requires that your underlying storage engine supports some sort of +native replication mechanism. Currently only MySQL native replication is +supported. Your patches to make other replication types work are welcomed. + =cut sub validate_replicants { my $self = shift @_; foreach my $replicant($self->all_replicants) { - if( - $self->_safely_ensure_connected($replicant) && - $replicant->is_replicating && - $replicant->lag_behind_master <= $self->maximum_lag - ) { - $replicant->active(1) + if($self->_safely_ensure_connected($replicant)) { + my $is_replicating = $replicant->is_replicating; + unless(defined $is_replicating) { + $replicant->debugobj->print("Storage Driver ".ref $self." Does not support the 'is_replicating' method. Assuming you are manually managing."); + next; + } else { + if($is_replicating) { + my $lag_behind_master = $replicant->lag_behind_master; + unless(defined $lag_behind_master) { + $replicant->debugobj->print("Storage Driver ".ref $self." Does not support the 'lag_behind_master' method. Assuming you are manually managing."); + next; + } else { + if($lag_behind_master <= $self->maximum_lag) { + $replicant->active(1); + } else { + $replicant->active(0); + } + } + } else { + $replicant->active(0); + } + } } else { $replicant->active(0); } } ## Mark that we completed this validation. - $self->_last_validated(time); + $self->_last_validated(time); } =head1 AUTHOR diff --git a/t/93storage_replication.t b/t/93storage_replication.t index 161013b..b72405b 100644 --- a/t/93storage_replication.t +++ b/t/93storage_replication.t @@ -312,7 +312,7 @@ is $artist3->name, "Dead On Arrival" => 'Found expected name for first result'; is $replicated->schema->storage->pool->connected_replicants => 1 - => "One replicant reconnected to handle the job"; + => "At Least One replicant reconnected to handle the job"; ## What happens when we try to select something that doesn't exist? @@ -578,6 +578,9 @@ ok $replicated->schema->resultset('Artist')->find(1) ## Delete the old database files $replicated->cleanup; +use Data::Dump qw/dump/; +#warn dump $replicated->schema->storage->read_handler; +