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