[Bast-commits] r4367 - in
DBIx-Class/0.08/branches/replication_dedux:
lib/DBIx/Class/Storage/DBI lib/DBIx/Class/Storage/DBI/Replicated t
jnapiorkowski at dev.catalyst.perl.org
jnapiorkowski at dev.catalyst.perl.org
Fri May 9 00:34:56 BST 2008
Author: jnapiorkowski
Date: 2008-05-09 00:34:55 +0100 (Fri, 09 May 2008)
New Revision: 4367
Modified:
DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm
DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Replicant.pm
DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/mysql.pm
DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t
Log:
converted replicant to a role so that we can apply it after ensure_connected properly reblesses the storage into the correct driver specific storage
Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm 2008-05-08 21:43:16 UTC (rev 4366)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm 2008-05-08 23:34:55 UTC (rev 4367)
@@ -36,7 +36,7 @@
is=>'ro',
isa=>'ClassName',
required=>1,
- default=>'DBIx::Class::Storage::DBI::Replicated::Replicant',
+ default=>'DBIx::Class::Storage::DBI',
handles=>{
'create_replicant' => 'new',
},
@@ -84,7 +84,7 @@
has 'replicants' => (
is=>'rw',
metaclass => 'Collection::Hash',
- isa=>'HashRef[DBIx::Class::Storage::DBI::Replicated::Replicant]',
+ isa=>'HashRef[DBIx::Class::Storage::DBI]',
default=>sub {{}},
provides => {
'set' => 'set_replicant',
@@ -107,15 +107,21 @@
=cut
+use Data::Dump qw/dump/;
+
sub connect_replicants {
my $self = shift @_;
my $schema = shift @_;
my @newly_created = ();
foreach my $connect_info (@_) {
+
my $replicant = $self->create_replicant($schema);
- $replicant->connect_info($connect_info);
+ $replicant->connect_info($connect_info);
$replicant->ensure_connected;
+
+ DBIx::Class::Storage::DBI::Replicated::Replicant->meta->apply($replicant);
+
my ($key) = ($connect_info->[0]=~m/^dbi\:.+\:(.+)$/);
$self->set_replicant( $key => $replicant);
push @newly_created, $replicant;
Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Replicant.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Replicant.pm 2008-05-08 21:43:16 UTC (rev 4366)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Replicant.pm 2008-05-08 23:34:55 UTC (rev 4367)
@@ -1,16 +1,14 @@
package DBIx::Class::Storage::DBI::Replicated::Replicant;
-use Moose;
-extends 'DBIx::Class::Storage::DBI', 'Moose::Object';
+use Moose::Role;
=head1 NAME
-DBIx::Class::Storage::DBI::Replicated::Replicant; A replicated DBI Storage
+DBIx::Class::Storage::DBI::Replicated::Replicant; A replicated DBI Storage Role
=head1 SYNOPSIS
-This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>. You
-shouldn't need to create instances of this class.
+This class is used internally by L<DBIx::Class::Storage::DBI::Replicated>.
=head1 DESCRIPTION
@@ -65,30 +63,7 @@
$self->$method("DSN: $dsn SQL: $sql", @bind);
};
-=head2 is_replicating
-A boolean that reports if a particular L<DBIx::Class::Storage::DBI> is set to
-replicate from a master database. Default is false, which is the result
-returned by databases that don't support replication.
-
-=cut
-
-sub is_replicating {
- my $self = shift @_;
-}
-
-=head2 lag_behind_master
-
-Returns a number that represents a certain amount of lag behind a master db
-when a given storage is replicating. The number is database dependent, but
-starts at zero, which is the default, and increases with the amount of lag.
-
-=cut
-
-sub lag_behind_master {
- my $self = shift @_;
-}
-
=head1 AUTHOR
John Napiorkowski <john.napiorkowski at takkle.com>
Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/mysql.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/mysql.pm 2008-05-08 21:43:16 UTC (rev 4366)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/mysql.pm 2008-05-08 23:34:55 UTC (rev 4367)
@@ -40,6 +40,7 @@
sub lag_behind_master {
my $self = shift @_;
+ return $self->dbh->selectrow_hashref('show slave status');
}
1;
Modified: DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t 2008-05-08 21:43:16 UTC (rev 4366)
+++ DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t 2008-05-08 23:34:55 UTC (rev 4367)
@@ -5,10 +5,10 @@
use DBICTest;
BEGIN {
- eval "use Moose";
+ eval "use Moose; use Test::Moose";
plan $@
? ( skip_all => 'needs Moose for testing' )
- : ( tests => 40 );
+ : ( tests => 41 );
}
use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool';
@@ -213,18 +213,18 @@
is $replicated->schema->storage->num_replicants => 2
=> 'has two replicants';
-isa_ok $replicated_storages[0]
+does_ok $replicated_storages[0]
=> 'DBIx::Class::Storage::DBI::Replicated::Replicant';
-isa_ok $replicated_storages[1]
+does_ok $replicated_storages[1]
=> 'DBIx::Class::Storage::DBI::Replicated::Replicant';
my @replicant_names = keys %{$replicated->schema->storage->replicants};
-
-isa_ok $replicated->schema->storage->replicants->{$replicant_names[0]}
+
+does_ok $replicated->schema->storage->replicants->{$replicant_names[0]}
=> 'DBIx::Class::Storage::DBI::Replicated::Replicant';
-isa_ok $replicated->schema->storage->replicants->{$replicant_names[1]}
+does_ok $replicated->schema->storage->replicants->{$replicant_names[1]}
=> 'DBIx::Class::Storage::DBI::Replicated::Replicant';
## Add some info to the database
@@ -355,7 +355,19 @@
$replicated->schema->storage->replicants->{$replicant_names[1]}->active(0);
ok $replicated->schema->resultset('Artist')->find(2)
- => 'Fallback to master';
+ => 'Fallback to master';
+
+$replicated->schema->storage->replicants->{$replicant_names[0]}->active(1);
+$replicated->schema->storage->replicants->{$replicant_names[1]}->active(1);
+
+ok $replicated->schema->resultset('Artist')->find(2)
+ => 'Returned to replicates';
+
+## Getting slave status tests
+
+use Data::Dump qw/dump/;
+my $lag1 = $replicated->schema->storage->replicants->{$replicant_names[0]}->lag_behind_master;
+warn dump $lag1;
## Delete the old database files
$replicated->cleanup;
More information about the Bast-commits
mailing list