| 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
| |||||||||||
| 33 | |||||||||||
| 34 | 50 | my $cxns = $self->cxns; | |||||||||
| 35 | 50 | my $total = @$cxns; | |||||||||
| 36 | |||||||||||
| 37 | 50 | ▶ | while ( 0 < $total-- ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 49 | my $cxn = $cxns->[ $self->next_cxn_num ]; | |||||||||
| 39 | 49 | ▶ | return $cxn if $cxn->is_live; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 56 | 19 | my $cxn = $cxns->[ $self->next_cxn_num ]; | |||||||||
| 57 | 19 | ▶ | if ( $cxn->is_dead ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 5 | push @skipped, $cxn; | |||||||||
| 59 | } | ||||||||||
| 60 | else { | ||||||||||
| 61 | 14 | ▶ | $self->sniff_cxn($cxn) and return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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__ | ||||||||||