Elasticsearch/CxnPool/Static.pm

filter: Statementstmt 100% 27 / 27 Branchbran 100% 10 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 100% 42 / 42 CC 8 SCAR 18.1
CC
8
Cov
100%
next_cxn
8.0
BEGIN
1.0
BEGIN
1.0
CRAP 6.1
« Elasticsearch/Error.pm ↑ Summary Elasticsearch.pm »
1 # Licensed to Elasticsearch B.V. under one or more contributor
2 # license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright
4 # ownership. Elasticsearch B.V. licenses this file to you under
5 # the Apache License, Version 2.0 (the "License"); you may
6 # not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17  
18 package Search::Elasticsearch::CxnPool::Static;
19 37 $Search::Elasticsearch::CxnPool::Static::VERSION = '8.12';
20 37 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 37 with 'Search::Elasticsearch::Role::CxnPool::Static',
22 'Search::Elasticsearch::Role::Is_Sync';
23 37 ▶use Search::Elasticsearch::Util qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 37 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 #===================================
27 54 ▶sub next_cxn {
Subroutine next_cxn: called CC=8 SCAR=20.8
Pod documented
28 #===================================
29 54 my ($self) = @_;
30  
31 54 my $cxns = $self->cxns;
32 54 my $total = @$cxns;
33  
34 54 my $now = time();
35 54 my @skipped;
36  
37 54 ▶ while ( $total-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($total--) 63 12 75
38 63 my $cxn = $cxns->[ $self->next_cxn_num ];
39 63 ▶ return $cxn if $cxn->is_live;
Branch: 1 branch
BranchTrueFalseTotal
if $cxn->is_live 14 49 63
40  
41 49 ▶ if ( $cxn->next_ping < $now ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cxn->next_ping < $now) { } 40 9 49
42 40 ▶ return $cxn if $cxn->pings_ok;
Branch: 1 branch
BranchTrueFalseTotal
if $cxn->pings_ok 28 12 40
43 }
44 else {
45 9 push @skipped, $cxn;
46 }
47 }
48  
49 12 for my $cxn (@skipped) {
50 7 ▶ return $cxn if $cxn->pings_ok;
Branch: 1 branch
BranchTrueFalseTotal
if $cxn->pings_ok 5 2 7
51 }
52  
53 7 $_->force_ping for @$cxns;
54  
55 7 throw( "NoNodes", "No nodes are available: [" . $self->cxns_str . ']' );
56 }
57  
58 37 1;
59  
60 =pod
61  
62 =encoding UTF-8
63  
64 =head1 NAME
65  
66 Search::Elasticsearch::CxnPool::Static - A CxnPool for connecting to a remote cluster with a static list of nodes.
67  
68 =head1 VERSION
69  
70 version 8.12
71  
72 =head1 SYNOPSIS
73  
74 $e = Search::Elasticsearch->new(
75 cxn_pool => 'Static' # default
76 nodes => [
77 'search1:9200',
78 'search2:9200'
79 ],
80 );
81  
82 =head1 DESCRIPTION
83  
84 The L<Static|Search::Elasticsearch::CxnPool::Static> connection pool, which is the
85 default, should be used when you don't have direct access to the Elasticsearch
86 cluster, eg when you are accessing the cluster through a proxy. It
87 round-robins through the nodes that you specified, and pings each node
88 before it is used for the first time, to ensure that it is responding.
89  
90 If any node fails, then all nodes are pinged before the next request to
91 ensure that they are still alive and responding. Failed nodes will be
92 pinged regularly to check if they have recovered.
93  
94 This class does L<Search::Elasticsearch::Role::CxnPool::Static> and
95 L<Search::Elasticsearch::Role::Is_Sync>.
96  
97 =head1 CONFIGURATION
98  
99 =head2 C<nodes>
100  
101 The list of nodes to use to serve requests. Can accept a single node,
102 multiple nodes, and defaults to C<localhost:9200> if no C<nodes> are
103 specified. See L<Search::Elasticsearch::Role::Cxn/node> for details of the node
104 specification.
105  
106 =head2 See also
107  
108 =over
109  
110 =item *
111  
112 L<Search::Elasticsearch::Role::Cxn/request_timeout>
113  
114 =item *
115  
116 L<Search::Elasticsearch::Role::Cxn/ping_timeout>
117  
118 =item *
119  
120 L<Search::Elasticsearch::Role::Cxn/dead_timeout>
121  
122 =item *
123  
124 L<Search::Elasticsearch::Role::Cxn/max_dead_timeout>
125  
126 =back
127  
128 =head2 Inherited configuration
129  
130 From L<Search::Elasticsearch::Role::CxnPool>
131  
132 =over
133  
134 =item * L<randomize_cxns|Search::Elasticsearch::Role::CxnPool/"randomize_cxns">
135  
136 =back
137  
138 =head1 METHODS
139  
140 =head2 C<next_cxn()>
141  
142 $cxn = $cxn_pool->next_cxn
143  
144 Returns the next available live node (in round robin fashion), or
145 throws a C<NoNodes> error if no nodes respond to ping requests.
146  
147 =head2 Inherited methods
148  
149 From L<Search::Elasticsearch::Role::CxnPool::Static>
150  
151 =over
152  
153 =item * L<schedule_check()|Search::Elasticsearch::Role::CxnPool::Static/"schedule_check()">
154  
155 =back
156  
157 From L<Search::Elasticsearch::Role::CxnPool>
158  
159 =over
160  
161 =item * L<cxn_factory()|Search::Elasticsearch::Role::CxnPool/"cxn_factory()">
162  
163 =item * L<logger()|Search::Elasticsearch::Role::CxnPool/"logger()">
164  
165 =item * L<serializer()|Search::Elasticsearch::Role::CxnPool/"serializer()">
166  
167 =item * L<current_cxn_num()|Search::Elasticsearch::Role::CxnPool/"current_cxn_num()">
168  
169 =item * L<cxns()|Search::Elasticsearch::Role::CxnPool/"cxns()">
170  
171 =item * L<seed_nodes()|Search::Elasticsearch::Role::CxnPool/"seed_nodes()">
172  
173 =item * L<next_cxn_num()|Search::Elasticsearch::Role::CxnPool/"next_cxn_num()">
174  
175 =item * L<set_cxns()|Search::Elasticsearch::Role::CxnPool/"set_cxns()">
176  
177 =item * L<request_ok()|Search::Elasticsearch::Role::CxnPool/"request_ok()">
178  
179 =item * L<request_failed()|Search::Elasticsearch::Role::CxnPool/"request_failed()">
180  
181 =item * L<should_retry()|Search::Elasticsearch::Role::CxnPool/"should_retry()">
182  
183 =item * L<should_mark_dead()|Search::Elasticsearch::Role::CxnPool/"should_mark_dead()">
184  
185 =item * L<cxns_str()|Search::Elasticsearch::Role::CxnPool/"cxns_str()">
186  
187 =item * L<cxns_seeds_str()|Search::Elasticsearch::Role::CxnPool/"cxns_seeds_str()">
188  
189 =item * L<retries()|Search::Elasticsearch::Role::CxnPool/"retries()">
190  
191 =item * L<reset_retries()|Search::Elasticsearch::Role::CxnPool/"reset_retries()">
192  
193 =back
194  
195 =head1 AUTHOR
196  
197 Enrico Zimuel <enrico.zimuel@elastic.co>
198  
199 =head1 COPYRIGHT AND LICENSE
200  
201 This software is Copyright (c) 2024 by Elasticsearch BV.
202  
203 This is free software, licensed under:
204  
205 The Apache License, Version 2.0, January 2004
206  
207 =cut
208  
209 __END__
« Elasticsearch/Error.pm ↑ Summary Elasticsearch.pm »