Elasticsearch/CxnPool/Static.pm

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