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::Sniff; |
19
|
|
|
|
|
|
|
$Search::Elasticsearch::CxnPool::Sniff::VERSION = '7.717'; |
20
|
11
|
|
|
11
|
|
4274
|
use Moo; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
52
|
|
21
|
|
|
|
|
|
|
with 'Search::Elasticsearch::Role::CxnPool::Sniff', |
22
|
|
|
|
|
|
|
'Search::Elasticsearch::Role::Is_Sync'; |
23
|
|
|
|
|
|
|
|
24
|
11
|
|
|
11
|
|
2878
|
use Search::Elasticsearch::Util qw(throw); |
|
11
|
|
|
|
|
17
|
|
|
11
|
|
|
|
|
61
|
|
25
|
11
|
|
|
11
|
|
2404
|
use namespace::clean; |
|
11
|
|
|
|
|
20
|
|
|
11
|
|
|
|
|
51
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#=================================== |
28
|
|
|
|
|
|
|
sub next_cxn { |
29
|
|
|
|
|
|
|
#=================================== |
30
|
50
|
|
|
50
|
1
|
97
|
my ($self) = @_; |
31
|
|
|
|
|
|
|
|
32
|
50
|
100
|
|
|
|
341
|
$self->sniff if $self->next_sniff <= time(); |
33
|
|
|
|
|
|
|
|
34
|
50
|
|
|
|
|
149
|
my $cxns = $self->cxns; |
35
|
50
|
|
|
|
|
74
|
my $total = @$cxns; |
36
|
|
|
|
|
|
|
|
37
|
50
|
|
|
|
|
111
|
while ( 0 < $total-- ) { |
38
|
49
|
|
|
|
|
121
|
my $cxn = $cxns->[ $self->next_cxn_num ]; |
39
|
49
|
100
|
|
|
|
133
|
return $cxn if $cxn->is_live; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
5
|
|
|
|
|
27
|
throw( "NoNodes", |
43
|
|
|
|
|
|
|
"No nodes are available: [" . $self->cxns_seeds_str . ']' ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
#=================================== |
47
|
|
|
|
|
|
|
sub sniff { |
48
|
|
|
|
|
|
|
#=================================== |
49
|
29
|
|
|
29
|
1
|
57
|
my $self = shift; |
50
|
|
|
|
|
|
|
|
51
|
29
|
|
|
|
|
69
|
my $cxns = $self->cxns; |
52
|
29
|
|
|
|
|
51
|
my $total = @$cxns; |
53
|
29
|
|
|
|
|
41
|
my @skipped; |
54
|
|
|
|
|
|
|
|
55
|
29
|
|
|
|
|
119
|
while ( 0 < $total-- ) { |
56
|
19
|
|
|
|
|
115
|
my $cxn = $cxns->[ $self->next_cxn_num ]; |
57
|
19
|
100
|
|
|
|
64
|
if ( $cxn->is_dead ) { |
58
|
5
|
|
|
|
|
10
|
push @skipped, $cxn; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
14
|
100
|
|
|
|
30
|
$self->sniff_cxn($cxn) and return; |
62
|
1
|
|
|
|
|
3
|
$cxn->mark_dead; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
16
|
|
|
|
|
35
|
for my $cxn (@skipped) { |
67
|
4
|
100
|
|
|
|
8
|
$self->sniff_cxn($cxn) and return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
15
|
|
|
|
|
332
|
$self->logger->info("No live nodes available. Trying seed nodes."); |
71
|
15
|
|
|
|
|
16635
|
for my $seed ( @{ $self->seed_nodes } ) { |
|
15
|
|
|
|
|
69
|
|
72
|
20
|
|
|
|
|
104
|
my $cxn = $self->cxn_factory->new_cxn($seed); |
73
|
20
|
100
|
|
|
|
3411
|
$self->sniff_cxn($cxn) and return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#=================================== |
79
|
|
|
|
|
|
|
sub sniff_cxn { |
80
|
|
|
|
|
|
|
#=================================== |
81
|
38
|
|
|
38
|
0
|
80
|
my ( $self, $cxn ) = @_; |
82
|
38
|
|
|
|
|
106
|
return $self->parse_sniff( $cxn->sniff ); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# ABSTRACT: A CxnPool for connecting to a local cluster with a dynamic node list |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |