First, in DBIx::Class::Storage::DBI::Replicated 'pool' is defined like this:

has 'pool' => (
  *is=>'ro'*,
  isa=>'DBIx::Class::Storage::DBI::Replicated::Pool',
  lazy_build=>1,
  handles=>[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=master
        user:
        password:

    replicants:
      - dsn: dbi:Pg:dbname=slave1
         user:
        password:
      - dsn: dbi:Pg:dbname=slave2
        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 = 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
[email protected]
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to