Elasticsearch/CxnPool/Sniff.pm

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