Subject: | PATCH: improved docs and lazy-loading test |
Hello,
Attached a couple patches for DBD::Multi.
First, I wanted to find out if DBD::Multi lazy-loads the database
connections. It does. I'm submitting tests for that, and doc improvements.
I also created a "suggested uses" section.
Your peer review for accuracy is appreciated.
Mark
Subject: | dbd-multi-docs.patch |
--- lib/DBD/Multi.pm.orig Tue Jan 16 15:01:53 2007
+++ lib/DBD/Multi.pm Tue Jan 16 15:11:06 2007
@@ -416,8 +416,7 @@
considered EXPIREMENTAL. This module is primary intended for read-only
operations (where some other application is being used to handle replication).
This software does not prevent write operations from being executed. This is
-left up to the user. (One suggestion is to make sure the user your a connecting
-to the db as has privileges sufficiently restricted to prevent updates).
+left up to the user. See L<SUGGESTED USES> below for ideas.
The interface is nearly the same as other DBI drivers with one notable
exception.
@@ -442,6 +441,9 @@
is lost. If a DBI object is used, the DBD::Multi will give up permanently
once that connection is lost.
+These connections are lazy loaded, meaning they aren't made until they are
+actually used.
+
=head2 Configuring Failures
By default a data source will not be tried again after it has failed
@@ -453,8 +455,24 @@
time we remember a data source as being failed, set the C<failed_expire>
parameter in seconds.
+=head1 SUGGESTED USES
+
+Here are some ideas on how to use this module effectively and safely.
+
+One suggestion is to make sure the user your a connecting to the db as has
+privileges sufficiently restricted to prevent updates.
+
+You might also design the application to use two database handles. The first
+handle would be the standard read/write handle. The second would be for
+read-only use, and would be used with C<DBD::Multi>. Read-only database calls
+would be updated to explicitly use the read-only handle. It is not necessary to
+find every single call that can be load balanced, since they can safely be sent
+through the read/write handle as well.
+
=head1 SEE ALSO
+L<CGI::Application::Plugin::DBH> - A plugin for the L<CGI::Application> framework
+which makes it easy to support two database handles, and also supports lazy-loading.
L<DBD::Multiplex>,
L<DBI>,
L<perl>.
Subject: | lazy-load.t |
# vim: ft=perl
use Test::More 'no_plan';
# Test that the handles are lazy-loaded.
use strict;
$^W = 1;
use DBI;
my $c = DBI->connect('DBI:Multi:', undef, undef, {
dsns => [
1 => ['dbi:Boom', '',''],
],
});
isa_ok $c, 'DBI::db', "invalid connect strict survives DBD::Multi connect()";
eval { $c->prepare("CREATE TABLE multi(id int)") };
ok($@, "invalid connect string blows up when handle is actually attempted to be used");