.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "DBIx::Class::Storage::DBI::Replicated::Pool 3pm" .TH DBIx::Class::Storage::DBI::Replicated::Pool 3pm "2018-04-19" "perl v5.26.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" DBIx::Class::Storage::DBI::Replicated::Pool \- Manage a pool of replicants .SH "SYNOPSIS" .IX Header "SYNOPSIS" This class is used internally by DBIx::Class::Storage::DBI::Replicated. You shouldn't need to create instances of this class. .SH "DESCRIPTION" .IX Header "DESCRIPTION" In a replicated storage type, there is at least one replicant to handle the read-only traffic. The Pool class manages this replicant, or list of replicants, and gives some methods for querying information about their status. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" This class defines the following attributes. .SS "maximum_lag ($num)" .IX Subsection "maximum_lag ($num)" This is a number which defines the maximum allowed lag returned by the \&\*(L"lag_behind_master\*(R" in DBIx::Class::Storage::DBI method. The default is 0. In general, this should return a larger number when the replicant is lagging behind its master, however the implementation of this is database specific, so don't count on this number having a fixed meaning. For example, MySQL will return a number of seconds that the replicating database is lagging. .SS "last_validated" .IX Subsection "last_validated" This is an integer representing a time since the last time the replicants were validated. It's nothing fancy, just an integer provided via the perl time built-in. .SS "replicant_type ($classname)" .IX Subsection "replicant_type ($classname)" Base class used to instantiate replicants that are in the pool. Unless you need to subclass DBIx::Class::Storage::DBI::Replicated::Replicant you should just leave this alone. .SS "replicants" .IX Subsection "replicants" A hashref of replicant, with the key being the dsn and the value returning the actual replicant storage. For example, if the \f(CW$dsn\fR element is something like: .PP .Vb 1 \& "dbi:SQLite:dbname=dbfile" .Ve .PP You could access the specific replicant via: .PP .Vb 1 \& $schema\->storage\->replicants\->{\*(Aqdbname=dbfile\*(Aq} .Ve .PP This attributes also supports the following helper methods: .IP "set_replicant($key=>$storage)" 4 .IX Item "set_replicant($key=>$storage)" Pushes a replicant onto the HashRef under \f(CW$key\fR .IP "get_replicant($key)" 4 .IX Item "get_replicant($key)" Retrieves the named replicant .IP "has_replicants" 4 .IX Item "has_replicants" Returns true if the Pool defines replicants. .IP "num_replicants" 4 .IX Item "num_replicants" The number of replicants in the pool .IP "delete_replicant ($key)" 4 .IX Item "delete_replicant ($key)" Removes the replicant under \f(CW$key\fR from the pool .SS "master" .IX Subsection "master" Reference to the master Storage. .SH "METHODS" .IX Header "METHODS" This class defines the following methods. .SS "connect_replicants ($schema, Array[$connect_info])" .IX Subsection "connect_replicants ($schema, Array[$connect_info])" Given an array of \f(CW$dsn\fR or connect_info structures suitable for connected to a database, create an DBIx::Class::Storage::DBI::Replicated::Replicant object and store it in the \*(L"replicants\*(R" attribute. .ie n .SS "connect_replicant ($schema, $connect_info)" .el .SS "connect_replicant ($schema, \f(CW$connect_info\fP)" .IX Subsection "connect_replicant ($schema, $connect_info)" Given a schema object and a hashref of \f(CW$connect_info\fR, connect the replicant and return it. .SS "_safely_ensure_connected ($replicant)" .IX Subsection "_safely_ensure_connected ($replicant)" The standard ensure_connected method with throw an exception should it fail to connect. For the master database this is desirable, but since replicants are allowed to fail, this behavior is not desirable. This method wraps the call to ensure_connected in an eval in order to catch any generated errors. That way a slave can go completely offline (e.g. the box itself can die) without bringing down your entire pool of databases. .ie n .SS "_safely ($replicant, $name, $code)" .el .SS "_safely ($replicant, \f(CW$name\fP, \f(CW$code\fP)" .IX Subsection "_safely ($replicant, $name, $code)" Execute \f(CW$code\fR for operation \f(CW$name\fR catching any exceptions and printing an error message to the \f(CW\*(C`<$replicant\-\*(C'\fRdebugobj>>. .PP Returns 1 on success and undef on failure. .SS "connected_replicants" .IX Subsection "connected_replicants" Returns true if there are connected replicants. Actually is overloaded to return the number of replicants. So you can do stuff like: .PP .Vb 5 \& if( my $num_connected = $storage\->has_connected_replicants ) { \& print "I have $num_connected connected replicants"; \& } else { \& print "Sorry, no replicants."; \& } .Ve .PP This method will actually test that each replicant in the \*(L"replicants\*(R" hashref is actually connected, try not to hit this 10 times a second. .SS "active_replicants" .IX Subsection "active_replicants" This is an array of replicants that are considered to be active in the pool. This does not check to see if they are connected, but if they are not, \s-1DBIC\s0 should automatically reconnect them for us when we hit them with a query. .SS "all_replicants" .IX Subsection "all_replicants" Just a simple array of all the replicant storages. No particular order to the array is given, nor should any meaning be derived. .SS "validate_replicants" .IX Subsection "validate_replicants" This does a check to see if 1) each replicate is connected (or reconnectable), 2) that is \->is_replicating, and 3) that it is not exceeding the lag amount defined by \*(L"maximum_lag\*(R". Replicants that fail any of these tests are set to inactive, and thus removed from the replication pool. .PP This tests \*(L"all_replicants\*(R", since a replicant that has been previous marked as inactive can be reactivated should it start to pass the validation tests again. .PP See DBIx::Class::Storage::DBI for more about checking if a replicating connection is not following a master or is lagging. .PP Calling this method will generate queries on the replicant databases so it is not recommended that you run them very often. .PP This method requires that your underlying storage engine supports some sort of native replication mechanism. Currently only MySQL native replication is supported. Your patches to make other replication types work are welcomed. .SH "FURTHER QUESTIONS?" .IX Header "FURTHER QUESTIONS?" Check the list of additional \s-1DBIC\s0 resources. .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This module is free software copyright by the DBIx::Class (\s-1DBIC\s0) authors. You can redistribute it and/or modify it under the same terms as the DBIx::Class library.