Elasticsearch/CxnPool/Sniff.pm

filter: Statementstmt 100% 39 / 39 Branchbran 100% 16 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 66.6% 2 / 3 totaltotal 98.4% 63 / 64 CC 11 SCAR 16.6
CC
11
Cov
100%
sniff
8.0
next_cxn
4.0
BEGIN
1.0
CRAP 5.2
« Elasticsearch.pm ↑ Summary Elasticsearch/Role/CxnPool/Static/NoPing.pm »
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 11 $Search::Elasticsearch::CxnPool::Sniff::VERSION = '8.12';
20 11 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 11 with 'Search::Elasticsearch::Role::CxnPool::Sniff',
22 'Search::Elasticsearch::Role::Is_Sync';
23  
24 11 ▶use Search::Elasticsearch::Util qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 11 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 #===================================
28 50 ▶sub next_cxn {
Subroutine next_cxn: called CC=4 SCAR=13.9
Pod documented
29 #===================================
30 50 my ($self) = @_;
31  
32 50 ▶ $self->sniff if $self->next_sniff <= time();
Branch: 1 branch
BranchTrueFalseTotal
if $self->next_sniff <= time 29 21 50
33  
34 50 my $cxns = $self->cxns;
35 50 my $total = @$cxns;
36  
37 50 ▶ while ( 0 < $total-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 < $total--) 49 5 54
38 49 my $cxn = $cxns->[ $self->next_cxn_num ];
39 49 ▶ return $cxn if $cxn->is_live;
Branch: 1 branch
BranchTrueFalseTotal
if $cxn->is_live 45 4 49
40 }
41  
42 5 throw( "NoNodes",
43 "No nodes are available: [" . $self->cxns_seeds_str . ']' );
44 }
45  
46 #===================================
47 29 ▶sub sniff {
Subroutine sniff: called CC=8 SCAR=20.8
Pod documented
48 #===================================
49 29 my $self = shift;
50  
51 29 my $cxns = $self->cxns;
52 29 my $total = @$cxns;
53 29 my @skipped;
54  
55 29 ▶ while ( 0 < $total-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 < $total--) 19 16 35
56 19 my $cxn = $cxns->[ $self->next_cxn_num ];
57 19 ▶ if ( $cxn->is_dead ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cxn->is_dead) { } 5 14 19
58 5 push @skipped, $cxn;
59 }
60 else {
61 14 ▶ $self->sniff_cxn($cxn) and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->sniff_cxn($cxn) and return 13 1 14
62 1 $cxn->mark_dead;
63 }
64 }
65  
66 16 for my $cxn (@skipped) {
67 4 ▶ $self->sniff_cxn($cxn) and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->sniff_cxn($cxn) and return 1 3 4
68 }
69  
70 15 $self->logger->info("No live nodes available. Trying seed nodes.");
71 15 for my $seed ( @{ $self->seed_nodes } ) {
72 20 my $cxn = $self->cxn_factory->new_cxn($seed);
73 20 ▶ $self->sniff_cxn($cxn) and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->sniff_cxn($cxn) and return 10 10 20
74 }
75  
76 }
77  
78 #===================================
79 38 ▶sub sniff_cxn {
Subroutine sniff_cxn: called CC=1 SCAR=0.0
Pod undocumented
80 #===================================
81 38 my ( $self, $cxn ) = @_;
82 38 return $self->parse_sniff( $cxn->sniff );
83 }
84  
85 11 1;
86  
87 # ABSTRACT: A CxnPool for connecting to a local cluster with a dynamic node list
88  
89 __END__
« Elasticsearch.pm ↑ Summary Elasticsearch/Role/CxnPool/Static/NoPing.pm »