| 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
| |||||||||||
| 22 | |||||||||||
| 23 | 50 | my $cxns = $self->cxns; | |||||||||
| 24 | 50 | my $total = @$cxns; | |||||||||
| 25 | |||||||||||
| 26 | 50 | ▶ | while ( 0 < $total-- ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 49 | my $cxn = $cxns->[ $self->next_cxn_num ]; | |||||||||
| 28 | 49 | ▶ | return $cxn if $cxn->is_live; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 45 | 19 | my $cxn = $cxns->[ $self->next_cxn_num ]; | |||||||||
| 46 | 19 | ▶ | if ( $cxn->is_dead ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 5 | push @skipped, $cxn; | |||||||||
| 48 | } | ||||||||||
| 49 | else { | ||||||||||
| 50 | 14 | ▶ | $self->sniff_cxn($cxn) and return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||