[Dbix-class] Replicated bug / Overriding Storage for
lag_behind_master
Bill Moseley
moseley at hank.org
Tue Nov 2 04:49:46 GMT 2010
First, in DBIx::Class::Storage::DBI::Replicated 'pool' is defined like this:
has 'pool' =3D> (
*is=3D>'ro'*,
isa=3D>'DBIx::Class::Storage::DBI::Replicated::Pool',
lazy_build=3D>1,
handles=3D>[qw/
connect_replicants
replicants
has_replicants
/],
);
But in the connect_info method there's this code which tries to set the
read-only attribute:
$self->pool($self->_build_pool)
if $self->pool;
"Cannot assign a value to a read-only accessor at
/usr/local/share/perl/5.10.0/DBIx/Class/Storage/DBI/Replicated.pm line 421
I assume that's not on purpose. To fix I've overridden the pool attribute
in my on replicated class (by specifying "storage_type" in my
configuration).
Now, only mysql is configured to handle lag_behind_master, and I'm using
Postgresql. Is it easiest to override DBIx::Class::Storage::DBI by
specifying the "replicant_type" as below?
In my Catalyst config I'm passing in the balancer_args and pool_args (which
is what triggered the error above).
Model::DB:
balancer_args:
master_read_weight: 0
auto_validate_every: 5
pool_args:
maximum_lag: 5
*replicant_type: MyApp::DB::Storage*
connect_info:
dsn: dbi:Pg:dbname=3Dmaster
user:
password:
replicants:
- dsn: dbi:Pg:dbname=3Dslave1
user:
password:
- dsn: dbi:Pg:dbname=3Dslave2
user:
password:
storage_type: MyApp::DB::Replicated
traits:
- Replicated
Then I have:
package MyApp::DB::Storage;
use strict;
use warnings;
use parent 'DBIx::Class::Storage::DBI';
sub is_replicating { return 1 }
sub lag_behind_master {
my $self =3D shift;
return $self->lag_seconds; # report current lag seconds.
}
1;
That make sense?
I assume I'll put lag_seconds in memcached so that I don't have a large
number of processes always hitting the slaves to query the lag time.
-- =
Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20101101/7dc=
cdf9a/attachment.htm
More information about the DBIx-Class
mailing list