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