File Coverage

blib/lib/Search/Elasticsearch/CxnPool/Static.pm
Criterion Covered Total %
statement 24 24 100.0
branch 8 8 100.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 37 37 100.0


line stmt bran cond sub pod time code
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             $Search::Elasticsearch::CxnPool::Static::VERSION = '7.717';
20 37     37   14739 use Moo;
  37         84  
  37         221  
21             with 'Search::Elasticsearch::Role::CxnPool::Static',
22             'Search::Elasticsearch::Role::Is_Sync';
23 37     37   10358 use Search::Elasticsearch::Util qw(throw);
  37         102  
  37         277  
24 37     37   9795 use namespace::clean;
  37         77  
  37         263  
25              
26             #===================================
27             sub next_cxn {
28             #===================================
29 54     54 1 88 my ($self) = @_;
30              
31 54         114 my $cxns = $self->cxns;
32 54         68 my $total = @$cxns;
33              
34 54         76 my $now = time();
35 54         83 my @skipped;
36              
37 54         114 while ( $total-- ) {
38 63         187 my $cxn = $cxns->[ $self->next_cxn_num ];
39 63 100       182 return $cxn if $cxn->is_live;
40              
41 49 100       119 if ( $cxn->next_ping < $now ) {
42 40 100       94 return $cxn if $cxn->pings_ok;
43             }
44             else {
45 9         20 push @skipped, $cxn;
46             }
47             }
48              
49 12         21 for my $cxn (@skipped) {
50 7 100       17 return $cxn if $cxn->pings_ok;
51             }
52              
53 7         28 $_->force_ping for @$cxns;
54              
55 7         24 throw( "NoNodes", "No nodes are available: [" . $self->cxns_str . ']' );
56             }
57              
58             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 7.717
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 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 and
95             L.
96              
97             =head1 CONFIGURATION
98              
99             =head2 C
100              
101             The list of nodes to use to serve requests. Can accept a single node,
102             multiple nodes, and defaults to C if no C are
103             specified. See L for details of the node
104             specification.
105              
106             =head2 See also
107              
108             =over
109              
110             =item *
111              
112             L
113              
114             =item *
115              
116             L
117              
118             =item *
119              
120             L
121              
122             =item *
123              
124             L
125              
126             =back
127              
128             =head2 Inherited configuration
129              
130             From L
131              
132             =over
133              
134             =item * L
135              
136             =back
137              
138             =head1 METHODS
139              
140             =head2 C
141              
142             $cxn = $cxn_pool->next_cxn
143              
144             Returns the next available live node (in round robin fashion), or
145             throws a C error if no nodes respond to ping requests.
146              
147             =head2 Inherited methods
148              
149             From L
150              
151             =over
152              
153             =item * L
154              
155             =back
156              
157             From L
158              
159             =over
160              
161             =item * L
162              
163             =item * L
164              
165             =item * L
166              
167             =item * L
168              
169             =item * L
170              
171             =item * L
172              
173             =item * L
174              
175             =item * L
176              
177             =item * L
178              
179             =item * L
180              
181             =item * L
182              
183             =item * L
184              
185             =item * L
186              
187             =item * L
188              
189             =item * L
190              
191             =item * L
192              
193             =back
194              
195             =head1 AUTHOR
196              
197             Enrico Zimuel
198              
199             =head1 COPYRIGHT AND LICENSE
200              
201             This software is Copyright (c) 2022 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__