1DBIx::Class::Storage::DUBsIe:r:RCeopnltirciDabBtuIetxde::d::CPPloeaorslls(:3D:)oSctuomreangtea:t:iDoBnI::Replicated::Pool(3)
2
3
4
6 DBIx::Class::Storage::DBI::Replicated::Pool - Manage a pool of
7 replicants
8
10 This class is used internally by DBIx::Class::Storage::DBI::Replicated.
11 You shouldn't need to create instances of this class.
12
14 In a replicated storage type, there is at least one replicant to handle
15 the read-only traffic. The Pool class manages this replicant, or list
16 of replicants, and gives some methods for querying information about
17 their status.
18
20 This class defines the following attributes.
21
22 maximum_lag ($num)
23 This is a number which defines the maximum allowed lag returned by the
24 "lag_behind_master" in DBIx::Class::Storage::DBI method. The default
25 is 0. In general, this should return a larger number when the
26 replicant is lagging behind its master, however the implementation of
27 this is database specific, so don't count on this number having a fixed
28 meaning. For example, MySQL will return a number of seconds that the
29 replicating database is lagging.
30
31 last_validated
32 This is an integer representing a time since the last time the
33 replicants were validated. It's nothing fancy, just an integer provided
34 via the perl time built-in.
35
36 replicant_type ($classname)
37 Base class used to instantiate replicants that are in the pool. Unless
38 you need to subclass DBIx::Class::Storage::DBI::Replicated::Replicant
39 you should just leave this alone.
40
41 replicants
42 A hashref of replicant, with the key being the dsn and the value
43 returning the actual replicant storage. For example, if the $dsn
44 element is something like:
45
46 "dbi:SQLite:dbname=dbfile"
47
48 You could access the specific replicant via:
49
50 $schema->storage->replicants->{'dbname=dbfile'}
51
52 This attributes also supports the following helper methods:
53
54 set_replicant($key=>$storage)
55 Pushes a replicant onto the HashRef under $key
56
57 get_replicant($key)
58 Retrieves the named replicant
59
60 has_replicants
61 Returns true if the Pool defines replicants.
62
63 num_replicants
64 The number of replicants in the pool
65
66 delete_replicant ($key)
67 Removes the replicant under $key from the pool
68
69 master
70 Reference to the master Storage.
71
73 This class defines the following methods.
74
75 connect_replicants ($schema, Array[$connect_info])
76 Given an array of $dsn or connect_info structures suitable for
77 connected to a database, create an
78 DBIx::Class::Storage::DBI::Replicated::Replicant object and store it in
79 the "replicants" attribute.
80
81 connect_replicant ($schema, $connect_info)
82 Given a schema object and a hashref of $connect_info, connect the
83 replicant and return it.
84
85 _safely_ensure_connected ($replicant)
86 The standard ensure_connected method with throw an exception should it
87 fail to connect. For the master database this is desirable, but since
88 replicants are allowed to fail, this behavior is not desirable. This
89 method wraps the call to ensure_connected in an eval in order to catch
90 any generated errors. That way a slave can go completely offline (e.g.
91 the box itself can die) without bringing down your entire pool of
92 databases.
93
94 _safely ($replicant, $name, $code)
95 Execute $code for operation $name catching any exceptions and printing
96 an error message to the "<$replicant-"debugobj>>.
97
98 Returns 1 on success and undef on failure.
99
100 connected_replicants
101 Returns true if there are connected replicants. Actually is overloaded
102 to return the number of replicants. So you can do stuff like:
103
104 if( my $num_connected = $storage->has_connected_replicants ) {
105 print "I have $num_connected connected replicants";
106 } else {
107 print "Sorry, no replicants.";
108 }
109
110 This method will actually test that each replicant in the "replicants"
111 hashref is actually connected, try not to hit this 10 times a second.
112
113 active_replicants
114 This is an array of replicants that are considered to be active in the
115 pool. This does not check to see if they are connected, but if they
116 are not, DBIC should automatically reconnect them for us when we hit
117 them with a query.
118
119 all_replicants
120 Just a simple array of all the replicant storages. No particular order
121 to the array is given, nor should any meaning be derived.
122
123 validate_replicants
124 This does a check to see if 1) each replicate is connected (or
125 reconnectable), 2) that is ->is_replicating, and 3) that it is not
126 exceeding the lag amount defined by "maximum_lag". Replicants that
127 fail any of these tests are set to inactive, and thus removed from the
128 replication pool.
129
130 This tests "all_replicants", since a replicant that has been previous
131 marked as inactive can be reactivated should it start to pass the
132 validation tests again.
133
134 See DBIx::Class::Storage::DBI for more about checking if a replicating
135 connection is not following a master or is lagging.
136
137 Calling this method will generate queries on the replicant databases so
138 it is not recommended that you run them very often.
139
140 This method requires that your underlying storage engine supports some
141 sort of native replication mechanism. Currently only MySQL native
142 replication is supported. Your patches to make other replication types
143 work are welcomed.
144
146 Check the list of additional DBIC resources.
147
149 This module is free software copyright by the DBIx::Class (DBIC)
150 authors. You can redistribute it and/or modify it under the same terms
151 as the DBIx::Class library.
152
153
154
155perl v5.30.1 DB2I0x2:0:-C0l1a-s2s9::Storage::DBI::Replicated::Pool(3)