DBIx::C...ed::Pool(3)
π DBIx::C...ed::Pool(3) π
okay bestie, this is the DBIx::C...ed::Pool(3) page from the User Contributed Perl Documentation, and itβs giving βinternal plumbing that keeps the read-only girlies in lineβ energy. no cap β¨
β¨ NAME β¨
DBIx::Class::Storage::DBI::Replicated::Pool β manage a pool of replicants. periodt π
π¦ SYNOPSIS π¦
This class is used internally by DBIx::Class::Storage::DBI::Replicated. You shouldnβt need to create instances of this class. like, fr fr, itβs not here for your main-character DIY moment π«Ά
πΈ 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. itβs basically the group chat admin for your replicas π
π ATTRIBUTES π
This class defines the following attributes.
π maximum_lag ($num) π
This is a number which defines the maximum allowed lag returned by the "lag_behind_master" 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. lowkey important, highkey not universal π
β 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. no cap, thatβs the whole vibe π°οΈ
π§ 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. bestie, donβt touch it unless you actually know why youβre touching it π
π replicants π
A hashref of replicant, with the key being the dsn and the value returning the actual replicant storage. For example, if the $dsn element is something like:
"dbi:SQLite:dbname=dbfile"
You could access the specific replicant via:
$schema->storage->replicants->{'dbname=dbfile'}
This attributes also supports the following helper methods:
set_replicant($key=>$storage)β pushes a replicant onto the HashRef under$keyget_replicant($key)β retrieves the named replicanthas_replicantsβ returns true if the Pool defines replicants.num_replicantsβ the number of replicants in the pooldelete_replicant ($key)β removes the replicant under$keyfrom the pool
π master π
Reference to the master Storage. the head honcho, the main character, the one in charge π
π₯ METHODS π₯
This class defines the following methods.
π connect_replicants ($schema, Array[$connect_info]) π
Given an array of $dsn or connect_info structures suitable for connecting to a database, create an DBIx::Class::Storage::DBI::Replicated::Replicant object and store it in the "replicants" attribute. slay, now the pool has friends β¨
π©· connect_replicant ($schema, $connect_info) π©·
Given a schema object and a hashref of $connect_info, connect the replicant and return it. simple, cute, does the job π«Ά
π _safely_ensure_connected ($replicant) π
The standard ensure_connected method will 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. iconic resilience, honestly ππ
π¦ _safely ($replicant, $name, $code) π¦
Execute $code for operation $name catching any exceptions and printing an error message to the "<$replicant-"debugobj>>.
Returns 1 on success and undef on failure. yes, that angle-bracket situation is exactly the docβs business, iykyk π
π connected_replicants π
Returns true if there are connected replicants. Actually is overloaded to return the number of replicants. So you can do stuff like:
if( my $num_connected = $storage->has_connected_replicants ) {
print "I have $num_connected connected replicants";
} else {
print "Sorry, no replicants.";
}
This method will actually test that each replicant in the "replicants" hashref is actually connected, try not to hit this 10 times a second.
bestie, that last part is a warning. do not spam it. your database will not think itβs cute π
πΈ 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, DBIC should automatically reconnect them for us when we hit them with a query. main character energy: assumed active until proven otherwise π
π 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. itβs giving βhereβs everyone, donβt read into the seating chartβ π«Ά
β‘ validate_replicants β‘
This does a check to see if:
- each replicate is connected (or reconnectable)
- that is
->is_replicating - that it is not exceeding the lag amount defined by
"maximum_lag".
Replicants that fail any of these tests are set to inactive, and thus removed from the replication pool. bye bestie, vibe check failed π
This tests "all_replicants", since a replicant that has been previous marked as inactive can be reactivated should it start to pass the validation tests again. we love a comeback arc π
See DBIx::Class::Storage::DBI for more about checking if a replicating connection is not following a master or is lagging.
Calling this method will generate queries on the replicant databases so it is not recommended that you run them very often. like, do not make this your little fidget spinner, okay? π
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. bring your faves, the door is open π«Ά
β FURTHER QUESTIONS? β
Check the list of additional DBIC resources. thatβs the whole assignment, bestie πβ¨
π COPYRIGHT AND LICENSE π
This module is free software copyright by the DBIx::Class (DBIC) authors. You can redistribute it and/or modify it under the same terms as the DBIx::Class library. legal cuteness, periodt π
okay thatβs the whole page, mwah π this was DBIx::C...ed::Pool(3) from the User Contributed Perl Documentation, brought to you by perl v5.42.0 and dated 2025-01-22. go forth and pool responsibly, icon π«ΆπΈ
π¦ where this page comes from
- opensuse-leap 16.0: perl-DBIx-Class 0.082844-bp160.1.10 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms