[Bast-commits] r7013 - in
DBIx-Class/0.08/branches/new_replication_transaction_fixup:
lib/DBIx/Class/Storage/DBI lib/DBIx/Class/Storage/DBI/Replicated t
jnapiorkowski at dev.catalyst.perl.org
jnapiorkowski at dev.catalyst.perl.org
Thu Jul 9 18:06:44 GMT 2009
Author: jnapiorkowski
Date: 2009-07-09 18:06:44 +0000 (Thu, 09 Jul 2009)
New Revision: 7013
Modified:
DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated.pm
DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm
DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm
DBIx-Class/0.08/branches/new_replication_transaction_fixup/t/93storage_replication.t
Log:
changed the way transactions are detected for replication to work with the standard way to do this, minor doc updates, fix to the force pool so you can force a particular slave, changes to the way the debugging is created
Modified: DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm
===================================================================
--- DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm 2009-07-09 15:00:22 UTC (rev 7012)
+++ DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated/Balancer.pm 2009-07-09 18:06:44 UTC (rev 7013)
@@ -169,10 +169,12 @@
around 'select' => sub {
my ($select, $self, @args) = @_;
-
+
if (my $forced_pool = $args[-1]->{force_pool}) {
delete $args[-1]->{force_pool};
return $self->_get_forced_pool($forced_pool)->select(@args);
+ } elsif($self->master->{transaction_depth}) {
+ return $self->master->select(@args);
} else {
$self->increment_storage;
return $self->$select(@args);
@@ -189,10 +191,12 @@
around 'select_single' => sub {
my ($select_single, $self, @args) = @_;
-
+
if (my $forced_pool = $args[-1]->{force_pool}) {
delete $args[-1]->{force_pool};
return $self->_get_forced_pool($forced_pool)->select_single(@args);
+ } elsif($self->master->{transaction_depth}) {
+ return $self->master->select_single(@args);
} else {
$self->increment_storage;
return $self->$select_single(@args);
@@ -224,7 +228,7 @@
return $forced_pool;
} elsif($forced_pool eq 'master') {
return $self->master;
- } elsif(my $replicant = $self->pool->replicants($forced_pool)) {
+ } elsif(my $replicant = $self->pool->replicants->{$forced_pool}) {
return $replicant;
} else {
$self->master->throw_exception("$forced_pool is not a named replicant.");
@@ -233,7 +237,7 @@
=head1 AUTHOR
-John Napiorkowski <john.napiorkowski at takkle.com>
+John Napiorkowski <jjnapiork at cpan.org>
=head1 LICENSE
Modified: DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm
===================================================================
--- DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm 2009-07-09 15:00:22 UTC (rev 7012)
+++ DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm 2009-07-09 18:06:44 UTC (rev 7013)
@@ -31,7 +31,8 @@
around '_query_start' => sub {
my ($method, $self, $sql, @bind) = @_;
my $dsn = $self->_dbi_connect_info->[0];
- $self->$method("DSN: $dsn SQL: $sql", @bind);
+ my($op, $rest) = ($sql=~m/^(\w+) (.+)$/);
+ $self->$method("$op [DSN=$dsn] $rest", @bind);
};
=head1 ALSO SEE
Modified: DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated.pm
===================================================================
--- DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated.pm 2009-07-09 15:00:22 UTC (rev 7012)
+++ DBIx-Class/0.08/branches/new_replication_transaction_fixup/lib/DBIx/Class/Storage/DBI/Replicated.pm 2009-07-09 18:06:44 UTC (rev 7013)
@@ -7,11 +7,11 @@
## use, so we explicitly test for these.
my %replication_required = (
- Moose => '0.77',
- MooseX::AttributeHelpers => '0.12',
- MooseX::Types => '0.10',
- namespace::clean => '0.11',
- Hash::Merge => '0.11'
+ 'Moose' => '0.77',
+ 'MooseX::AttributeHelpers' => '0.12',
+ 'MooseX::Types' => '0.10',
+ 'namespace::clean' => '0.11',
+ 'Hash::Merge' => '0.11'
);
my @didnt_load;
@@ -612,24 +612,11 @@
sub set_balanced_storage {
my $self = shift @_;
my $schema = $self->schema;
- my $write_handler = $self->schema->storage->balancer;
+ my $balanced_handler = $self->schema->storage->balancer;
- $schema->storage->read_handler($write_handler);
+ $schema->storage->read_handler($balanced_handler);
}
-=head2 around: txn_do ($coderef)
-
-Overload to the txn_do method, which is delegated to whatever the
-L<write_handler> is set to. We overload this in order to wrap in inside a
-L</execute_reliably> method.
-
-=cut
-
-around 'txn_do' => sub {
- my($txn_do, $self, $coderef, @args) = @_;
- $self->execute_reliably(sub {$self->$txn_do($coderef, @args)});
-};
-
=head2 connected
Check that the master and at least one of the replicants is connected.
Modified: DBIx-Class/0.08/branches/new_replication_transaction_fixup/t/93storage_replication.t
===================================================================
--- DBIx-Class/0.08/branches/new_replication_transaction_fixup/t/93storage_replication.t 2009-07-09 15:00:22 UTC (rev 7012)
+++ DBIx-Class/0.08/branches/new_replication_transaction_fixup/t/93storage_replication.t 2009-07-09 18:06:44 UTC (rev 7013)
@@ -12,7 +12,7 @@
eval "use DBIx::Class::Storage::DBI::Replicated; use Test::Moose";
plan $@
? ( skip_all => "Deps not installed: $@" )
- : ( tests => 90 );
+ : ( tests => 95 );
}
use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool';
@@ -257,6 +257,8 @@
=> 'configured balancer_type';
}
+$replicated->schema->storage->debugcb(sub {my ($ob, $info) = @_; warn "\n\n$ob, $info\n\n"});
+
ok $replicated->schema->storage->meta
=> 'has a meta object';
@@ -296,6 +298,8 @@
my @replicant_names = keys %{ $replicated->schema->storage->replicants };
+ok @replicant_names, "found replicant names @replicant_names";
+
## Silence warning about not supporting the is_replicating method if using the
## sqlite dbs.
$replicated->schema->storage->debugobj->silence(1)
@@ -607,10 +611,10 @@
]);
ok my $result = $replicated->schema->resultset('Artist')->find($id)
- => 'Found expected artist';
+ => "Found expected artist for $id";
ok my $more = $replicated->schema->resultset('Artist')->find(1)
- => 'Found expected artist again';
+ => 'Found expected artist again for 1';
return ($result, $more);
@@ -630,11 +634,14 @@
## Test that asking for single return works
{
- ok my $return = $replicated->schema->txn_do($transaction, 777)
+ ok my @return = $replicated->schema->txn_do($transaction, 777)
=> 'did transaction';
- is $return->id, 777
+ is $return[0]->id, 777
=> 'first returned value is correct';
+
+ is $return[1]->id, 1
+ => 'second returned value is correct';
}
## Test transaction returning a single value
@@ -711,6 +718,19 @@
=> 'got an artist result via force_pool storage';
}
+## Test the force_pool resultset attribute part two.
+
+{
+ ok my $artist_rs = $replicated->schema->resultset('Artist')
+ => 'got artist resultset';
+
+ ## Turn on Forced Pool Storage
+ ok my $reliable_artist_rs = $artist_rs->search(undef, {force_pool=>$replicant_names[0]})
+ => 'Created a resultset using force_pool storage';
+
+ ok my $artist = $reliable_artist_rs->find(2)
+ => 'got an artist result via force_pool storage';
+}
## Delete the old database files
$replicated->cleanup;
More information about the Bast-commits
mailing list