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